Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Check-out files from the "current cache directory" |
| 3 | * |
| 4 | * Copyright (C) 2005 Linus Torvalds |
| 5 | * |
| 6 | * Careful: order of argument flags does matter. For example, |
| 7 | * |
Heikki Orsila | 05207a2 | 2008-09-09 13:28:30 +0300 | [diff] [blame] | 8 | * git checkout-index -a -f file.c |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 9 | * |
| 10 | * Will first check out all files listed in the cache (but not |
| 11 | * overwrite any old ones), and then force-checkout "file.c" a |
| 12 | * second time (ie that one _will_ overwrite any old contents |
| 13 | * with the same filename). |
| 14 | * |
Heikki Orsila | 05207a2 | 2008-09-09 13:28:30 +0300 | [diff] [blame] | 15 | * Also, just doing "git checkout-index" does nothing. You probably |
| 16 | * meant "git checkout-index -a". And if you want to force it, you |
| 17 | * want "git checkout-index -f -a". |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 18 | * |
| 19 | * Intuitiveness is not the goal here. Repeatability is. The |
| 20 | * reason for the "no arguments means no work" thing is that |
| 21 | * from scripts you are supposed to be able to do things like |
| 22 | * |
Heikki Orsila | 05207a2 | 2008-09-09 13:28:30 +0300 | [diff] [blame] | 23 | * find . -name '*.h' -print0 | xargs -0 git checkout-index -f -- |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 24 | * |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 25 | * or: |
| 26 | * |
Heikki Orsila | 05207a2 | 2008-09-09 13:28:30 +0300 | [diff] [blame] | 27 | * find . -name '*.h' -print0 | git checkout-index -f -z --stdin |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 28 | * |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 29 | * which will force all existing *.h files to be replaced with |
| 30 | * their cached copies. If an empty command line implied "all", |
| 31 | * then this would force-refresh everything in the cache, which |
| 32 | * was not the point. |
| 33 | * |
| 34 | * Oh, and the "--" is just a good idea when you know the rest |
| 35 | * will be filenames. Just so that you wouldn't have a filename |
| 36 | * of "-a" causing problems (not possible in the above example, |
| 37 | * but get used to it in scripting!). |
| 38 | */ |
Peter Hagervall | baffc0e | 2007-07-15 01:14:45 +0200 | [diff] [blame] | 39 | #include "builtin.h" |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 40 | #include "cache.h" |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 41 | #include "quote.h" |
Junio C Hamano | bad68ec | 2006-04-24 21:18:58 -0700 | [diff] [blame] | 42 | #include "cache-tree.h" |
Miklos Vajna | a6c7db1 | 2008-10-18 03:17:23 +0200 | [diff] [blame] | 43 | #include "parse-options.h" |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 44 | |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 45 | #define CHECKOUT_ALL 4 |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 46 | static int line_termination = '\n'; |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 47 | static int checkout_stage; /* default to checkout stage0 */ |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 48 | static int to_tempfile; |
Jonas Fonseca | 095c424 | 2006-08-26 16:09:17 +0200 | [diff] [blame] | 49 | static char topath[4][PATH_MAX + 1]; |
Junio C Hamano | c3e9a65 | 2005-11-26 00:22:48 -0800 | [diff] [blame] | 50 | |
Shawn Pearce | 344c52a | 2006-07-08 14:34:02 -0400 | [diff] [blame] | 51 | static struct checkout state; |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 52 | |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 53 | static void write_tempfile_record(const char *name, int prefix_length) |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 54 | { |
| 55 | int i; |
| 56 | |
| 57 | if (CHECKOUT_ALL == checkout_stage) { |
| 58 | for (i = 1; i < 4; i++) { |
| 59 | if (i > 1) |
| 60 | putchar(' '); |
| 61 | if (topath[i][0]) |
| 62 | fputs(topath[i], stdout); |
| 63 | else |
| 64 | putchar('.'); |
| 65 | } |
| 66 | } else |
| 67 | fputs(topath[checkout_stage], stdout); |
| 68 | |
| 69 | putchar('\t'); |
Pierre Habouzit | 663af34 | 2007-09-20 00:42:15 +0200 | [diff] [blame] | 70 | write_name_quoted(name + prefix_length, stdout, line_termination); |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 71 | |
| 72 | for (i = 0; i < 4; i++) { |
| 73 | topath[i][0] = 0; |
| 74 | } |
| 75 | } |
| 76 | |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 77 | static int checkout_file(const char *name, int prefix_length) |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 78 | { |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 79 | int namelen = strlen(name); |
| 80 | int pos = cache_name_pos(name, namelen); |
| 81 | int has_same_name = 0; |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 82 | int did_checkout = 0; |
| 83 | int errs = 0; |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 84 | |
| 85 | if (pos < 0) |
| 86 | pos = -pos - 1; |
| 87 | |
| 88 | while (pos < active_nr) { |
| 89 | struct cache_entry *ce = active_cache[pos]; |
Junio C Hamano | f4f9ada | 2005-12-13 21:39:56 -0800 | [diff] [blame] | 90 | if (ce_namelen(ce) != namelen || |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 91 | memcmp(ce->name, name, namelen)) |
| 92 | break; |
| 93 | has_same_name = 1; |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 94 | pos++; |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 95 | if (ce_stage(ce) != checkout_stage |
| 96 | && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce))) |
| 97 | continue; |
| 98 | did_checkout = 1; |
| 99 | if (checkout_entry(ce, &state, |
| 100 | to_tempfile ? topath[ce_stage(ce)] : NULL) < 0) |
| 101 | errs++; |
| 102 | } |
| 103 | |
| 104 | if (did_checkout) { |
| 105 | if (to_tempfile) |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 106 | write_tempfile_record(name, prefix_length); |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 107 | return errs > 0 ? -1 : 0; |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 108 | } |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 109 | |
| 110 | if (!state.quiet) { |
Heikki Orsila | 05207a2 | 2008-09-09 13:28:30 +0300 | [diff] [blame] | 111 | fprintf(stderr, "git checkout-index: %s ", name); |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 112 | if (!has_same_name) |
| 113 | fprintf(stderr, "is not in the cache"); |
| 114 | else if (checkout_stage) |
| 115 | fprintf(stderr, "does not exist at stage %d", |
| 116 | checkout_stage); |
| 117 | else |
| 118 | fprintf(stderr, "is unmerged"); |
| 119 | fputc('\n', stderr); |
| 120 | } |
| 121 | return -1; |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 122 | } |
| 123 | |
David Rientjes | f7f0fbf | 2006-08-14 13:20:12 -0700 | [diff] [blame] | 124 | static void checkout_all(const char *prefix, int prefix_length) |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 125 | { |
Junio C Hamano | 4b12dae | 2005-10-03 12:44:48 -0700 | [diff] [blame] | 126 | int i, errs = 0; |
Rene Scharfe | 5142db6 | 2006-04-02 13:13:01 +0200 | [diff] [blame] | 127 | struct cache_entry* last_ce = NULL; |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 128 | |
| 129 | for (i = 0; i < active_nr ; i++) { |
| 130 | struct cache_entry *ce = active_cache[i]; |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 131 | if (ce_stage(ce) != checkout_stage |
| 132 | && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce))) |
Linus Torvalds | d9f98ee | 2005-04-17 18:39:14 -0700 | [diff] [blame] | 133 | continue; |
Junio C Hamano | c3e9a65 | 2005-11-26 00:22:48 -0800 | [diff] [blame] | 134 | if (prefix && *prefix && |
Junio C Hamano | 3bd348a | 2005-12-07 00:29:51 -0800 | [diff] [blame] | 135 | (ce_namelen(ce) <= prefix_length || |
| 136 | memcmp(prefix, ce->name, prefix_length))) |
Junio C Hamano | c3e9a65 | 2005-11-26 00:22:48 -0800 | [diff] [blame] | 137 | continue; |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 138 | if (last_ce && to_tempfile) { |
| 139 | if (ce_namelen(last_ce) != ce_namelen(ce) |
| 140 | || memcmp(last_ce->name, ce->name, ce_namelen(ce))) |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 141 | write_tempfile_record(last_ce->name, prefix_length); |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 142 | } |
| 143 | if (checkout_entry(ce, &state, |
| 144 | to_tempfile ? topath[ce_stage(ce)] : NULL) < 0) |
Junio C Hamano | 4b12dae | 2005-10-03 12:44:48 -0700 | [diff] [blame] | 145 | errs++; |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 146 | last_ce = ce; |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 147 | } |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 148 | if (last_ce && to_tempfile) |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 149 | write_tempfile_record(last_ce->name, prefix_length); |
Junio C Hamano | 4b12dae | 2005-10-03 12:44:48 -0700 | [diff] [blame] | 150 | if (errs) |
| 151 | /* we have already done our error reporting. |
| 152 | * exit with the same code as die(). |
| 153 | */ |
| 154 | exit(128); |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Miklos Vajna | a6c7db1 | 2008-10-18 03:17:23 +0200 | [diff] [blame] | 157 | static const char * const builtin_checkout_index_usage[] = { |
| 158 | "git checkout-index [options] [--] <file>...", |
| 159 | NULL |
| 160 | }; |
Junio C Hamano | d46ad9c | 2005-07-13 20:25:07 -0700 | [diff] [blame] | 161 | |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 162 | static struct lock_file lock_file; |
James Bottomley | 31f584c | 2005-08-13 10:29:32 -0500 | [diff] [blame] | 163 | |
Miklos Vajna | a6c7db1 | 2008-10-18 03:17:23 +0200 | [diff] [blame] | 164 | static int option_parse_u(const struct option *opt, |
| 165 | const char *arg, int unset) |
| 166 | { |
| 167 | int *newfd = opt->value; |
| 168 | |
| 169 | state.refresh_cache = 1; |
| 170 | if (*newfd < 0) |
| 171 | *newfd = hold_locked_index(&lock_file, 1); |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static int option_parse_z(const struct option *opt, |
| 176 | const char *arg, int unset) |
| 177 | { |
| 178 | if (unset) |
| 179 | line_termination = '\n'; |
| 180 | else |
| 181 | line_termination = 0; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static int option_parse_prefix(const struct option *opt, |
| 186 | const char *arg, int unset) |
| 187 | { |
| 188 | state.base_dir = arg; |
| 189 | state.base_dir_len = strlen(arg); |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int option_parse_stage(const struct option *opt, |
| 194 | const char *arg, int unset) |
| 195 | { |
| 196 | if (!strcmp(arg, "all")) { |
| 197 | to_tempfile = 1; |
| 198 | checkout_stage = CHECKOUT_ALL; |
| 199 | } else { |
| 200 | int ch = arg[0]; |
| 201 | if ('1' <= ch && ch <= '3') |
| 202 | checkout_stage = arg[0] - '0'; |
| 203 | else |
| 204 | die("stage should be between 1 and 3 or all"); |
| 205 | } |
| 206 | return 0; |
| 207 | } |
| 208 | |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 209 | int cmd_checkout_index(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 210 | { |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 211 | int i; |
Junio C Hamano | 415e96c | 2005-05-15 14:23:12 -0700 | [diff] [blame] | 212 | int newfd = -1; |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 213 | int all = 0; |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 214 | int read_from_stdin = 0; |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 215 | int prefix_length; |
Miklos Vajna | a6c7db1 | 2008-10-18 03:17:23 +0200 | [diff] [blame] | 216 | int force = 0, quiet = 0, not_new = 0; |
| 217 | struct option builtin_checkout_index_options[] = { |
| 218 | OPT_BOOLEAN('a', "all", &all, |
| 219 | "checks out all files in the index"), |
| 220 | OPT_BOOLEAN('f', "force", &force, |
| 221 | "forces overwrite of existing files"), |
| 222 | OPT__QUIET(&quiet), |
| 223 | OPT_BOOLEAN('n', "no-create", ¬_new, |
| 224 | "don't checkout new files"), |
| 225 | { OPTION_CALLBACK, 'u', "index", &newfd, NULL, |
| 226 | "update stat information in the index file", |
| 227 | PARSE_OPT_NOARG, option_parse_u }, |
| 228 | { OPTION_CALLBACK, 'z', NULL, NULL, NULL, |
| 229 | "paths are separated with NUL character", |
| 230 | PARSE_OPT_NOARG, option_parse_z }, |
| 231 | OPT_BOOLEAN(0, "stdin", &read_from_stdin, |
| 232 | "read list of paths from the standard input"), |
| 233 | OPT_BOOLEAN(0, "temp", &to_tempfile, |
| 234 | "write the content to temporary files"), |
| 235 | OPT_CALLBACK(0, "prefix", NULL, "string", |
| 236 | "when creating files, prepend <string>", |
| 237 | option_parse_prefix), |
| 238 | OPT_CALLBACK(0, "stage", NULL, NULL, |
| 239 | "copy out the files from named stage", |
| 240 | option_parse_stage), |
| 241 | OPT_END() |
| 242 | }; |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 243 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 244 | git_config(git_default_config, NULL); |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 245 | state.base_dir = ""; |
Junio C Hamano | c3e9a65 | 2005-11-26 00:22:48 -0800 | [diff] [blame] | 246 | prefix_length = prefix ? strlen(prefix) : 0; |
| 247 | |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 248 | if (read_cache() < 0) { |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 249 | die("invalid cache"); |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Miklos Vajna | a6c7db1 | 2008-10-18 03:17:23 +0200 | [diff] [blame] | 252 | argc = parse_options(argc, argv, builtin_checkout_index_options, |
| 253 | builtin_checkout_index_usage, 0); |
| 254 | state.force = force; |
| 255 | state.quiet = quiet; |
| 256 | state.not_new = not_new; |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 257 | |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 258 | if (state.base_dir_len || to_tempfile) { |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 259 | /* when --prefix is specified we do not |
| 260 | * want to update cache. |
| 261 | */ |
| 262 | if (state.refresh_cache) { |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 263 | rollback_lock_file(&lock_file); |
Brandon Casey | 4ed7cd3 | 2008-01-16 13:12:46 -0600 | [diff] [blame] | 264 | newfd = -1; |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 265 | } |
| 266 | state.refresh_cache = 0; |
| 267 | } |
| 268 | |
| 269 | /* Check out named files first */ |
Miklos Vajna | a6c7db1 | 2008-10-18 03:17:23 +0200 | [diff] [blame] | 270 | for (i = 0; i < argc; i++) { |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 271 | const char *arg = argv[i]; |
Junio C Hamano | dc46da2 | 2006-05-05 22:38:06 -0700 | [diff] [blame] | 272 | const char *p; |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 273 | |
| 274 | if (all) |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 275 | die("git checkout-index: don't mix '--all' and explicit filenames"); |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 276 | if (read_from_stdin) |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 277 | die("git checkout-index: don't mix '--stdin' and explicit filenames"); |
Junio C Hamano | dc46da2 | 2006-05-05 22:38:06 -0700 | [diff] [blame] | 278 | p = prefix_path(prefix, prefix_length, arg); |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 279 | checkout_file(p, prefix_length); |
Johannes Schindelin | be65e7d | 2006-05-07 00:02:53 +0200 | [diff] [blame] | 280 | if (p < arg || p > arg + strlen(arg)) |
Junio C Hamano | dc46da2 | 2006-05-05 22:38:06 -0700 | [diff] [blame] | 281 | free((char*)p); |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 282 | } |
Junio C Hamano | 415e96c | 2005-05-15 14:23:12 -0700 | [diff] [blame] | 283 | |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 284 | if (read_from_stdin) { |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 285 | struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; |
Pierre Habouzit | 7fb1011 | 2007-09-20 00:42:14 +0200 | [diff] [blame] | 286 | |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 287 | if (all) |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 288 | die("git checkout-index: don't mix '--all' and '--stdin'"); |
Pierre Habouzit | 7fb1011 | 2007-09-20 00:42:14 +0200 | [diff] [blame] | 289 | |
Pierre Habouzit | 7fb1011 | 2007-09-20 00:42:14 +0200 | [diff] [blame] | 290 | while (strbuf_getline(&buf, stdin, line_termination) != EOF) { |
Junio C Hamano | dc46da2 | 2006-05-05 22:38:06 -0700 | [diff] [blame] | 291 | const char *p; |
Pierre Habouzit | 7fb1011 | 2007-09-20 00:42:14 +0200 | [diff] [blame] | 292 | if (line_termination && buf.buf[0] == '"') { |
| 293 | strbuf_reset(&nbuf); |
| 294 | if (unquote_c_style(&nbuf, buf.buf, NULL)) |
| 295 | die("line is badly quoted"); |
| 296 | strbuf_swap(&buf, &nbuf); |
| 297 | } |
| 298 | p = prefix_path(prefix, prefix_length, buf.buf); |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 299 | checkout_file(p, prefix_length); |
Pierre Habouzit | 7fb1011 | 2007-09-20 00:42:14 +0200 | [diff] [blame] | 300 | if (p < buf.buf || p > buf.buf + buf.len) |
Junio C Hamano | dc46da2 | 2006-05-05 22:38:06 -0700 | [diff] [blame] | 301 | free((char *)p); |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 302 | } |
Pierre Habouzit | 7fb1011 | 2007-09-20 00:42:14 +0200 | [diff] [blame] | 303 | strbuf_release(&nbuf); |
Pierre Habouzit | e6c019d | 2007-09-17 11:19:04 +0200 | [diff] [blame] | 304 | strbuf_release(&buf); |
Shawn Pearce | 9debe63 | 2006-02-28 21:43:33 -0500 | [diff] [blame] | 305 | } |
| 306 | |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 307 | if (all) |
Junio C Hamano | e414156 | 2006-08-04 01:23:19 -0700 | [diff] [blame] | 308 | checkout_all(prefix, prefix_length); |
Linus Torvalds | a65a686 | 2005-10-17 17:32:12 -0700 | [diff] [blame] | 309 | |
Junio C Hamano | 415e96c | 2005-05-15 14:23:12 -0700 | [diff] [blame] | 310 | if (0 <= newfd && |
| 311 | (write_cache(newfd, active_cache, active_nr) || |
Brandon Casey | 4ed7cd3 | 2008-01-16 13:12:46 -0600 | [diff] [blame] | 312 | commit_locked_index(&lock_file))) |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 313 | die("Unable to write new index file"); |
Linus Torvalds | 33db5f4 | 2005-04-09 09:53:05 -0700 | [diff] [blame] | 314 | return 0; |
| 315 | } |