]>
Commit | Line | Data |
---|---|---|
8bc9a0c7 LT |
1 | /* |
2 | * GIT - The information manager from hell | |
3 | * | |
4 | * Copyright (C) Linus Torvalds, 2005 | |
5 | */ | |
e83c5163 | 6 | #include "cache.h" |
ee1bec3d | 7 | #include "strbuf.h" |
973d6a20 | 8 | #include "quote.h" |
a6e5642f | 9 | #include "cache-tree.h" |
2bd452d3 | 10 | #include "tree-walk.h" |
fefe81c9 | 11 | #include "builtin.h" |
e83c5163 | 12 | |
121481ab LT |
13 | /* |
14 | * Default to not allowing changes to the list of files. The | |
15 | * tool doesn't actually care, but this makes it harder to add | |
16 | * files to the revision control by mistake by doing something | |
215a7ad1 | 17 | * like "git-update-index *" and suddenly having all the object |
121481ab LT |
18 | * files be revision controlled. |
19 | */ | |
caf4f582 JH |
20 | static int allow_add; |
21 | static int allow_remove; | |
22 | static int allow_replace; | |
caf4f582 | 23 | static int info_only; |
9b63f501 | 24 | static int force_remove; |
caf4f582 | 25 | static int verbose; |
96f1e58f | 26 | static int mark_valid_only; |
5f73076c JH |
27 | #define MARK_VALID 1 |
28 | #define UNMARK_VALID 2 | |
29 | ||
caf4f582 JH |
30 | static void report(const char *fmt, ...) |
31 | { | |
32 | va_list vp; | |
33 | ||
34 | if (!verbose) | |
35 | return; | |
36 | ||
37 | va_start(vp, fmt); | |
38 | vprintf(fmt, vp); | |
39 | putchar('\n'); | |
40 | va_end(vp); | |
41 | } | |
42 | ||
5f73076c JH |
43 | static int mark_valid(const char *path) |
44 | { | |
45 | int namelen = strlen(path); | |
46 | int pos = cache_name_pos(path, namelen); | |
47 | if (0 <= pos) { | |
48 | switch (mark_valid_only) { | |
49 | case MARK_VALID: | |
50 | active_cache[pos]->ce_flags |= htons(CE_VALID); | |
51 | break; | |
52 | case UNMARK_VALID: | |
53 | active_cache[pos]->ce_flags &= ~htons(CE_VALID); | |
54 | break; | |
55 | } | |
a6e5642f | 56 | cache_tree_invalidate_path(active_cache_tree, path); |
5f73076c JH |
57 | active_cache_changed = 1; |
58 | return 0; | |
59 | } | |
60 | return -1; | |
61 | } | |
62 | ||
6b5ee137 | 63 | static int add_file_to_cache(const char *path) |
e83c5163 | 64 | { |
4c5abf42 | 65 | int size, namelen, option, status; |
e83c5163 LT |
66 | struct cache_entry *ce; |
67 | struct stat st; | |
e83c5163 | 68 | |
4c5abf42 | 69 | status = lstat(path, &st); |
a6e5642f JH |
70 | |
71 | /* We probably want to do this in remove_file_from_cache() and | |
72 | * add_cache_entry() instead... | |
73 | */ | |
74 | cache_tree_invalidate_path(active_cache_tree, path); | |
75 | ||
4c5abf42 JH |
76 | if (status < 0 || S_ISDIR(st.st_mode)) { |
77 | /* When we used to have "path" and now we want to add | |
78 | * "path/file", we need a way to remove "path" before | |
79 | * being able to add "path/file". However, | |
215a7ad1 | 80 | * "git-update-index --remove path" would not work. |
4c5abf42 JH |
81 | * --force-remove can be used but this is more user |
82 | * friendly, especially since we can do the opposite | |
83 | * case just fine without --force-remove. | |
84 | */ | |
85 | if (status == 0 || (errno == ENOENT || errno == ENOTDIR)) { | |
34143b26 PB |
86 | if (allow_remove) { |
87 | if (remove_file_from_cache(path)) | |
88 | return error("%s: cannot remove from the index", | |
89 | path); | |
90 | else | |
91 | return 0; | |
92 | } else if (status < 0) { | |
93 | return error("%s: does not exist and --remove not passed", | |
94 | path); | |
95 | } | |
121481ab | 96 | } |
89bc8c78 | 97 | if (0 == status) |
34143b26 PB |
98 | return error("%s: is a directory - add files inside instead", |
99 | path); | |
89bc8c78 AW |
100 | else |
101 | return error("lstat(\"%s\"): %s", path, | |
102 | strerror(errno)); | |
e83c5163 | 103 | } |
3e09cdfd | 104 | |
e83c5163 LT |
105 | namelen = strlen(path); |
106 | size = cache_entry_size(namelen); | |
90321c10 | 107 | ce = xcalloc(1, size); |
e83c5163 | 108 | memcpy(ce->name, path, namelen); |
5f73076c | 109 | ce->ce_flags = htons(namelen); |
711cf3a0 | 110 | fill_stat_cache_info(ce, &st); |
3e09cdfd | 111 | |
185c975f JH |
112 | if (trust_executable_bit) |
113 | ce->ce_mode = create_ce_mode(st.st_mode); | |
114 | else { | |
3e09cdfd | 115 | /* If there is an existing entry, pick the mode bits |
2bbaaed9 | 116 | * from it, otherwise assume unexecutable. |
3e09cdfd | 117 | */ |
185c975f | 118 | struct cache_entry *ent; |
3e09cdfd | 119 | int pos = cache_name_pos(path, namelen); |
185c975f JH |
120 | |
121 | ent = (0 <= pos) ? active_cache[pos] : NULL; | |
122 | ce->ce_mode = ce_mode_from_stat(ent, st.st_mode); | |
3e09cdfd | 123 | } |
ec1fcc16 JH |
124 | |
125 | if (index_path(ce->sha1, path, &st, !info_only)) | |
126 | return -1; | |
192268c1 JH |
127 | option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; |
128 | option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; | |
34143b26 PB |
129 | if (add_cache_entry(ce, option)) |
130 | return error("%s: cannot add to the index - missing --add option?", | |
131 | path); | |
132 | return 0; | |
121481ab LT |
133 | } |
134 | ||
d23748a6 JH |
135 | static int add_cacheinfo(unsigned int mode, const unsigned char *sha1, |
136 | const char *path, int stage) | |
9945d980 | 137 | { |
192268c1 | 138 | int size, len, option; |
9945d980 LT |
139 | struct cache_entry *ce; |
140 | ||
d23748a6 | 141 | if (!verify_path(path)) |
9945d980 | 142 | return -1; |
9945d980 | 143 | |
d23748a6 | 144 | len = strlen(path); |
9945d980 | 145 | size = cache_entry_size(len); |
90321c10 | 146 | ce = xcalloc(1, size); |
9945d980 | 147 | |
e702496e | 148 | hashcpy(ce->sha1, sha1); |
d23748a6 JH |
149 | memcpy(ce->name, path, len); |
150 | ce->ce_flags = create_ce_flags(len, stage); | |
e4479470 | 151 | ce->ce_mode = create_ce_mode(mode); |
5f73076c JH |
152 | if (assume_unchanged) |
153 | ce->ce_flags |= htons(CE_VALID); | |
192268c1 JH |
154 | option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; |
155 | option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; | |
caf4f582 JH |
156 | if (add_cache_entry(ce, option)) |
157 | return error("%s: cannot add to the index - missing --add option?", | |
d23748a6 JH |
158 | path); |
159 | report("add '%s'", path); | |
a6e5642f | 160 | cache_tree_invalidate_path(active_cache_tree, path); |
caf4f582 | 161 | return 0; |
9945d980 LT |
162 | } |
163 | ||
227bdb18 | 164 | static void chmod_path(int flip, const char *path) |
3e09cdfd JH |
165 | { |
166 | int pos; | |
167 | struct cache_entry *ce; | |
168 | unsigned int mode; | |
f2a19340 | 169 | |
3e09cdfd JH |
170 | pos = cache_name_pos(path, strlen(path)); |
171 | if (pos < 0) | |
227bdb18 | 172 | goto fail; |
3e09cdfd JH |
173 | ce = active_cache[pos]; |
174 | mode = ntohl(ce->ce_mode); | |
175 | if (!S_ISREG(mode)) | |
227bdb18 | 176 | goto fail; |
3e09cdfd JH |
177 | switch (flip) { |
178 | case '+': | |
179 | ce->ce_mode |= htonl(0111); break; | |
180 | case '-': | |
181 | ce->ce_mode &= htonl(~0111); break; | |
182 | default: | |
227bdb18 | 183 | goto fail; |
3e09cdfd | 184 | } |
a6e5642f | 185 | cache_tree_invalidate_path(active_cache_tree, path); |
3e09cdfd | 186 | active_cache_changed = 1; |
227bdb18 AR |
187 | report("chmod %cx '%s'", flip, path); |
188 | return; | |
189 | fail: | |
190 | die("git-update-index: cannot chmod %cx '%s'", flip, path); | |
3e09cdfd JH |
191 | } |
192 | ||
ee1bec3d JH |
193 | static void update_one(const char *path, const char *prefix, int prefix_length) |
194 | { | |
195 | const char *p = prefix_path(prefix, prefix_length, path); | |
196 | if (!verify_path(p)) { | |
197 | fprintf(stderr, "Ignoring path %s\n", path); | |
fb69a760 | 198 | goto free_return; |
ee1bec3d | 199 | } |
5f73076c JH |
200 | if (mark_valid_only) { |
201 | if (mark_valid(p)) | |
202 | die("Unable to mark file %s", path); | |
fb69a760 | 203 | goto free_return; |
5f73076c | 204 | } |
a6e5642f | 205 | cache_tree_invalidate_path(active_cache_tree, path); |
5f73076c | 206 | |
ee1bec3d JH |
207 | if (force_remove) { |
208 | if (remove_file_from_cache(p)) | |
209 | die("git-update-index: unable to remove %s", path); | |
caf4f582 | 210 | report("remove '%s'", path); |
fb69a760 | 211 | goto free_return; |
ee1bec3d JH |
212 | } |
213 | if (add_file_to_cache(p)) | |
214 | die("Unable to process file %s", path); | |
caf4f582 | 215 | report("add '%s'", path); |
fb69a760 | 216 | free_return: |
0cc9e70c | 217 | if (p < path || p > path + strlen(path)) |
fb69a760 | 218 | free((char*)p); |
ee1bec3d JH |
219 | } |
220 | ||
d4dbf36d JH |
221 | static void read_index_info(int line_termination) |
222 | { | |
223 | struct strbuf buf; | |
224 | strbuf_init(&buf); | |
225 | while (1) { | |
9c20a470 | 226 | char *ptr, *tab; |
973d6a20 | 227 | char *path_name; |
d4dbf36d JH |
228 | unsigned char sha1[20]; |
229 | unsigned int mode; | |
d23748a6 JH |
230 | int stage; |
231 | ||
232 | /* This reads lines formatted in one of three formats: | |
233 | * | |
234 | * (1) mode SP sha1 TAB path | |
235 | * The first format is what "git-apply --index-info" | |
236 | * reports, and used to reconstruct a partial tree | |
237 | * that is used for phony merge base tree when falling | |
238 | * back on 3-way merge. | |
239 | * | |
240 | * (2) mode SP type SP sha1 TAB path | |
241 | * The second format is to stuff git-ls-tree output | |
242 | * into the index file. | |
fefe81c9 | 243 | * |
d23748a6 JH |
244 | * (3) mode SP sha1 SP stage TAB path |
245 | * This format is to put higher order stages into the | |
246 | * index file and matches git-ls-files --stage output. | |
247 | */ | |
d4dbf36d JH |
248 | read_line(&buf, stdin, line_termination); |
249 | if (buf.eof) | |
250 | break; | |
251 | ||
252 | mode = strtoul(buf.buf, &ptr, 8); | |
9c20a470 | 253 | if (ptr == buf.buf || *ptr != ' ') |
d4dbf36d JH |
254 | goto bad_line; |
255 | ||
9c20a470 JH |
256 | tab = strchr(ptr, '\t'); |
257 | if (!tab || tab - ptr < 41) | |
258 | goto bad_line; | |
d23748a6 | 259 | |
2d497115 | 260 | if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') { |
d23748a6 JH |
261 | stage = tab[-1] - '0'; |
262 | ptr = tab + 1; /* point at the head of path */ | |
263 | tab = tab - 2; /* point at tail of sha1 */ | |
264 | } | |
265 | else { | |
266 | stage = 0; | |
267 | ptr = tab + 1; /* point at the head of path */ | |
268 | } | |
269 | ||
9c20a470 JH |
270 | if (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ') |
271 | goto bad_line; | |
973d6a20 JH |
272 | |
273 | if (line_termination && ptr[0] == '"') | |
274 | path_name = unquote_c_style(ptr, NULL); | |
275 | else | |
276 | path_name = ptr; | |
277 | ||
278 | if (!verify_path(path_name)) { | |
279 | fprintf(stderr, "Ignoring path %s\n", path_name); | |
280 | if (path_name != ptr) | |
281 | free(path_name); | |
d4dbf36d JH |
282 | continue; |
283 | } | |
a6e5642f | 284 | cache_tree_invalidate_path(active_cache_tree, path_name); |
d4dbf36d JH |
285 | |
286 | if (!mode) { | |
287 | /* mode == 0 means there is no such path -- remove */ | |
973d6a20 | 288 | if (remove_file_from_cache(path_name)) |
d4dbf36d JH |
289 | die("git-update-index: unable to remove %s", |
290 | ptr); | |
291 | } | |
292 | else { | |
293 | /* mode ' ' sha1 '\t' name | |
294 | * ptr[-1] points at tab, | |
295 | * ptr[-41] is at the beginning of sha1 | |
296 | */ | |
297 | ptr[-42] = ptr[-1] = 0; | |
d23748a6 | 298 | if (add_cacheinfo(mode, sha1, path_name, stage)) |
d4dbf36d | 299 | die("git-update-index: unable to update %s", |
973d6a20 | 300 | path_name); |
d4dbf36d | 301 | } |
973d6a20 JH |
302 | if (path_name != ptr) |
303 | free(path_name); | |
d4dbf36d JH |
304 | continue; |
305 | ||
306 | bad_line: | |
307 | die("malformed index info %s", buf.buf); | |
308 | } | |
309 | } | |
310 | ||
f6ab5bb2 | 311 | static const char update_index_usage[] = |
7099c9c7 | 312 | "git-update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--really-refresh] [--cacheinfo] [--chmod=(+|-)x] [--assume-unchanged] [--info-only] [--force-remove] [--stdin] [--index-info] [--unresolve] [--again | -g] [--ignore-missing] [-z] [--verbose] [--] <file>..."; |
f6ab5bb2 | 313 | |
2bd452d3 JH |
314 | static unsigned char head_sha1[20]; |
315 | static unsigned char merge_head_sha1[20]; | |
316 | ||
317 | static struct cache_entry *read_one_ent(const char *which, | |
318 | unsigned char *ent, const char *path, | |
319 | int namelen, int stage) | |
320 | { | |
321 | unsigned mode; | |
322 | unsigned char sha1[20]; | |
323 | int size; | |
324 | struct cache_entry *ce; | |
325 | ||
326 | if (get_tree_entry(ent, path, sha1, &mode)) { | |
83e77a25 JH |
327 | if (which) |
328 | error("%s: not in %s branch.", path, which); | |
2bd452d3 JH |
329 | return NULL; |
330 | } | |
331 | if (mode == S_IFDIR) { | |
83e77a25 JH |
332 | if (which) |
333 | error("%s: not a blob in %s branch.", path, which); | |
2bd452d3 JH |
334 | return NULL; |
335 | } | |
336 | size = cache_entry_size(namelen); | |
337 | ce = xcalloc(1, size); | |
338 | ||
e702496e | 339 | hashcpy(ce->sha1, sha1); |
2bd452d3 JH |
340 | memcpy(ce->name, path, namelen); |
341 | ce->ce_flags = create_ce_flags(namelen, stage); | |
342 | ce->ce_mode = create_ce_mode(mode); | |
343 | return ce; | |
344 | } | |
345 | ||
346 | static int unresolve_one(const char *path) | |
347 | { | |
348 | int namelen = strlen(path); | |
349 | int pos; | |
350 | int ret = 0; | |
351 | struct cache_entry *ce_2 = NULL, *ce_3 = NULL; | |
352 | ||
353 | /* See if there is such entry in the index. */ | |
354 | pos = cache_name_pos(path, namelen); | |
355 | if (pos < 0) { | |
356 | /* If there isn't, either it is unmerged, or | |
357 | * resolved as "removed" by mistake. We do not | |
358 | * want to do anything in the former case. | |
359 | */ | |
360 | pos = -pos-1; | |
361 | if (pos < active_nr) { | |
362 | struct cache_entry *ce = active_cache[pos]; | |
363 | if (ce_namelen(ce) == namelen && | |
364 | !memcmp(ce->name, path, namelen)) { | |
365 | fprintf(stderr, | |
366 | "%s: skipping still unmerged path.\n", | |
367 | path); | |
368 | goto free_return; | |
369 | } | |
370 | } | |
371 | } | |
372 | ||
373 | /* Grab blobs from given path from HEAD and MERGE_HEAD, | |
374 | * stuff HEAD version in stage #2, | |
375 | * stuff MERGE_HEAD version in stage #3. | |
376 | */ | |
377 | ce_2 = read_one_ent("our", head_sha1, path, namelen, 2); | |
378 | ce_3 = read_one_ent("their", merge_head_sha1, path, namelen, 3); | |
379 | ||
380 | if (!ce_2 || !ce_3) { | |
381 | ret = -1; | |
382 | goto free_return; | |
383 | } | |
a89fccd2 | 384 | if (!hashcmp(ce_2->sha1, ce_3->sha1) && |
2bd452d3 JH |
385 | ce_2->ce_mode == ce_3->ce_mode) { |
386 | fprintf(stderr, "%s: identical in both, skipping.\n", | |
387 | path); | |
388 | goto free_return; | |
389 | } | |
390 | ||
497c3213 | 391 | cache_tree_invalidate_path(active_cache_tree, path); |
2bd452d3 JH |
392 | remove_file_from_cache(path); |
393 | if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { | |
394 | error("%s: cannot add our version to the index.", path); | |
395 | ret = -1; | |
396 | goto free_return; | |
397 | } | |
398 | if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD)) | |
399 | return 0; | |
400 | error("%s: cannot add their version to the index.", path); | |
401 | ret = -1; | |
402 | free_return: | |
403 | free(ce_2); | |
404 | free(ce_3); | |
405 | return ret; | |
406 | } | |
407 | ||
408 | static void read_head_pointers(void) | |
409 | { | |
913c983e | 410 | if (read_ref("HEAD", head_sha1)) |
2bd452d3 | 411 | die("No HEAD -- no initial commit yet?\n"); |
913c983e | 412 | if (read_ref("MERGE_HEAD", merge_head_sha1)) { |
2bd452d3 JH |
413 | fprintf(stderr, "Not in the middle of a merge.\n"); |
414 | exit(0); | |
415 | } | |
416 | } | |
417 | ||
09895c1f JH |
418 | static int do_unresolve(int ac, const char **av, |
419 | const char *prefix, int prefix_length) | |
2bd452d3 JH |
420 | { |
421 | int i; | |
422 | int err = 0; | |
423 | ||
424 | /* Read HEAD and MERGE_HEAD; if MERGE_HEAD does not exist, we | |
425 | * are not doing a merge, so exit with success status. | |
426 | */ | |
427 | read_head_pointers(); | |
428 | ||
429 | for (i = 1; i < ac; i++) { | |
430 | const char *arg = av[i]; | |
09895c1f JH |
431 | const char *p = prefix_path(prefix, prefix_length, arg); |
432 | err |= unresolve_one(p); | |
0cc9e70c | 433 | if (p < arg || p > arg + strlen(arg)) |
09895c1f | 434 | free((char*)p); |
2bd452d3 JH |
435 | } |
436 | return err; | |
437 | } | |
438 | ||
83e77a25 JH |
439 | static int do_reupdate(int ac, const char **av, |
440 | const char *prefix, int prefix_length) | |
441 | { | |
442 | /* Read HEAD and run update-index on paths that are | |
443 | * merged and already different between index and HEAD. | |
444 | */ | |
445 | int pos; | |
446 | int has_head = 1; | |
0cc9e70c | 447 | const char **pathspec = get_pathspec(prefix, av + 1); |
83e77a25 | 448 | |
913c983e | 449 | if (read_ref("HEAD", head_sha1)) |
83e77a25 JH |
450 | /* If there is no HEAD, that means it is an initial |
451 | * commit. Update everything in the index. | |
452 | */ | |
453 | has_head = 0; | |
454 | redo: | |
455 | for (pos = 0; pos < active_nr; pos++) { | |
456 | struct cache_entry *ce = active_cache[pos]; | |
457 | struct cache_entry *old = NULL; | |
458 | int save_nr; | |
22293b9c JH |
459 | |
460 | if (ce_stage(ce) || !ce_path_match(ce, pathspec)) | |
83e77a25 JH |
461 | continue; |
462 | if (has_head) | |
463 | old = read_one_ent(NULL, head_sha1, | |
464 | ce->name, ce_namelen(ce), 0); | |
465 | if (old && ce->ce_mode == old->ce_mode && | |
a89fccd2 | 466 | !hashcmp(ce->sha1, old->sha1)) { |
83e77a25 JH |
467 | free(old); |
468 | continue; /* unchanged */ | |
469 | } | |
470 | /* Be careful. The working tree may not have the | |
471 | * path anymore, in which case, under 'allow_remove', | |
472 | * or worse yet 'allow_replace', active_nr may decrease. | |
473 | */ | |
474 | save_nr = active_nr; | |
475 | update_one(ce->name + prefix_length, prefix, prefix_length); | |
476 | if (save_nr != active_nr) | |
477 | goto redo; | |
478 | } | |
479 | return 0; | |
480 | } | |
481 | ||
a633fca0 | 482 | int cmd_update_index(int argc, const char **argv, const char *prefix) |
e83c5163 | 483 | { |
ee1bec3d | 484 | int i, newfd, entries, has_errors = 0, line_termination = '\n'; |
121481ab | 485 | int allow_options = 1; |
ee1bec3d | 486 | int read_from_stdin = 0; |
ee1bec3d | 487 | int prefix_length = prefix ? strlen(prefix) : 0; |
227bdb18 | 488 | char set_executable_bit = 0; |
405e5b2f | 489 | unsigned int refresh_flags = 0; |
fefe81c9 | 490 | struct lock_file *lock_file; |
bb233d69 | 491 | |
3e09cdfd JH |
492 | git_config(git_default_config); |
493 | ||
fefe81c9 | 494 | /* We can't free this memory, it becomes part of a linked list parsed atexit() */ |
928e47e3 | 495 | lock_file = xcalloc(1, sizeof(struct lock_file)); |
fefe81c9 | 496 | |
40aaae88 | 497 | newfd = hold_lock_file_for_update(lock_file, get_index_file(), 1); |
9614b8dc | 498 | |
e83c5163 | 499 | entries = read_cache(); |
9614b8dc | 500 | if (entries < 0) |
2de381f9 | 501 | die("cache corrupted"); |
e83c5163 | 502 | |
e83c5163 | 503 | for (i = 1 ; i < argc; i++) { |
6b5ee137 | 504 | const char *path = argv[i]; |
9ebe6cf9 | 505 | const char *p; |
121481ab LT |
506 | |
507 | if (allow_options && *path == '-') { | |
508 | if (!strcmp(path, "--")) { | |
509 | allow_options = 0; | |
510 | continue; | |
511 | } | |
0ed3715f | 512 | if (!strcmp(path, "-q")) { |
405e5b2f | 513 | refresh_flags |= REFRESH_QUIET; |
0ed3715f LT |
514 | continue; |
515 | } | |
121481ab LT |
516 | if (!strcmp(path, "--add")) { |
517 | allow_add = 1; | |
518 | continue; | |
519 | } | |
192268c1 JH |
520 | if (!strcmp(path, "--replace")) { |
521 | allow_replace = 1; | |
522 | continue; | |
523 | } | |
121481ab LT |
524 | if (!strcmp(path, "--remove")) { |
525 | allow_remove = 1; | |
526 | continue; | |
527 | } | |
5d1a5c02 | 528 | if (!strcmp(path, "--unmerged")) { |
405e5b2f | 529 | refresh_flags |= REFRESH_UNMERGED; |
5d1a5c02 LT |
530 | continue; |
531 | } | |
121481ab | 532 | if (!strcmp(path, "--refresh")) { |
405e5b2f | 533 | has_errors |= refresh_cache(refresh_flags); |
5f73076c JH |
534 | continue; |
535 | } | |
536 | if (!strcmp(path, "--really-refresh")) { | |
405e5b2f | 537 | has_errors |= refresh_cache(REFRESH_REALLY | refresh_flags); |
121481ab LT |
538 | continue; |
539 | } | |
9945d980 | 540 | if (!strcmp(path, "--cacheinfo")) { |
d23748a6 JH |
541 | unsigned char sha1[20]; |
542 | unsigned int mode; | |
543 | ||
b3f94c4b | 544 | if (i+3 >= argc) |
215a7ad1 | 545 | die("git-update-index: --cacheinfo <mode> <sha1> <path>"); |
d23748a6 JH |
546 | |
547 | if ((sscanf(argv[i+1], "%o", &mode) != 1) || | |
548 | get_sha1_hex(argv[i+2], sha1) || | |
549 | add_cacheinfo(mode, sha1, argv[i+3], 0)) | |
550 | die("git-update-index: --cacheinfo" | |
551 | " cannot add %s", argv[i+3]); | |
9945d980 LT |
552 | i += 3; |
553 | continue; | |
554 | } | |
3e09cdfd JH |
555 | if (!strcmp(path, "--chmod=-x") || |
556 | !strcmp(path, "--chmod=+x")) { | |
557 | if (argc <= i+1) | |
558 | die("git-update-index: %s <path>", path); | |
227bdb18 | 559 | set_executable_bit = path[8]; |
3e09cdfd JH |
560 | continue; |
561 | } | |
5f73076c JH |
562 | if (!strcmp(path, "--assume-unchanged")) { |
563 | mark_valid_only = MARK_VALID; | |
564 | continue; | |
565 | } | |
566 | if (!strcmp(path, "--no-assume-unchanged")) { | |
567 | mark_valid_only = UNMARK_VALID; | |
568 | continue; | |
569 | } | |
df6e1516 BL |
570 | if (!strcmp(path, "--info-only")) { |
571 | info_only = 1; | |
572 | continue; | |
573 | } | |
0ff5bf7c | 574 | if (!strcmp(path, "--force-remove")) { |
9b63f501 | 575 | force_remove = 1; |
0ff5bf7c JH |
576 | continue; |
577 | } | |
ee1bec3d JH |
578 | if (!strcmp(path, "-z")) { |
579 | line_termination = 0; | |
580 | continue; | |
581 | } | |
582 | if (!strcmp(path, "--stdin")) { | |
583 | if (i != argc - 1) | |
584 | die("--stdin must be at the end"); | |
585 | read_from_stdin = 1; | |
586 | break; | |
587 | } | |
d4dbf36d | 588 | if (!strcmp(path, "--index-info")) { |
a41c175d SP |
589 | if (i != argc - 1) |
590 | die("--index-info must be at the end"); | |
d4dbf36d JH |
591 | allow_add = allow_replace = allow_remove = 1; |
592 | read_index_info(line_termination); | |
a41c175d | 593 | break; |
d4dbf36d | 594 | } |
2bd452d3 | 595 | if (!strcmp(path, "--unresolve")) { |
09895c1f JH |
596 | has_errors = do_unresolve(argc - i, argv + i, |
597 | prefix, prefix_length); | |
2bd452d3 JH |
598 | if (has_errors) |
599 | active_cache_changed = 0; | |
600 | goto finish; | |
601 | } | |
7099c9c7 | 602 | if (!strcmp(path, "--again") || !strcmp(path, "-g")) { |
83e77a25 JH |
603 | has_errors = do_reupdate(argc - i, argv + i, |
604 | prefix, prefix_length); | |
605 | if (has_errors) | |
606 | active_cache_changed = 0; | |
607 | goto finish; | |
608 | } | |
c6e007b0 | 609 | if (!strcmp(path, "--ignore-missing")) { |
405e5b2f | 610 | refresh_flags |= REFRESH_IGNORE_MISSING; |
c6e007b0 JB |
611 | continue; |
612 | } | |
caf4f582 JH |
613 | if (!strcmp(path, "--verbose")) { |
614 | verbose = 1; | |
615 | continue; | |
616 | } | |
f6ab5bb2 PB |
617 | if (!strcmp(path, "-h") || !strcmp(path, "--help")) |
618 | usage(update_index_usage); | |
2de381f9 | 619 | die("unknown option %s", path); |
121481ab | 620 | } |
9ebe6cf9 AR |
621 | p = prefix_path(prefix, prefix_length, path); |
622 | update_one(p, NULL, 0); | |
227bdb18 | 623 | if (set_executable_bit) |
9ebe6cf9 AR |
624 | chmod_path(set_executable_bit, p); |
625 | if (p < path || p > path + strlen(path)) | |
626 | free((char*)p); | |
ee1bec3d JH |
627 | } |
628 | if (read_from_stdin) { | |
629 | struct strbuf buf; | |
630 | strbuf_init(&buf); | |
631 | while (1) { | |
a94d9948 | 632 | char *path_name; |
fb69a760 | 633 | const char *p; |
ee1bec3d JH |
634 | read_line(&buf, stdin, line_termination); |
635 | if (buf.eof) | |
636 | break; | |
a94d9948 JH |
637 | if (line_termination && buf.buf[0] == '"') |
638 | path_name = unquote_c_style(buf.buf, NULL); | |
639 | else | |
640 | path_name = buf.buf; | |
fb69a760 JH |
641 | p = prefix_path(prefix, prefix_length, path_name); |
642 | update_one(p, NULL, 0); | |
643 | if (set_executable_bit) | |
227bdb18 | 644 | chmod_path(set_executable_bit, p); |
0cc9e70c | 645 | if (p < path_name || p > path_name + strlen(path_name)) |
fb69a760 | 646 | free((char*) p); |
a94d9948 JH |
647 | if (path_name != buf.buf) |
648 | free(path_name); | |
9b63f501 | 649 | } |
e83c5163 | 650 | } |
2bd452d3 JH |
651 | |
652 | finish: | |
5cd5ace7 LT |
653 | if (active_cache_changed) { |
654 | if (write_cache(newfd, active_cache, active_nr) || | |
6244b249 | 655 | close(newfd) || commit_lock_file(lock_file)) |
021b6e45 | 656 | die("Unable to write new index file"); |
5cd5ace7 | 657 | } |
9614b8dc | 658 | |
fefe81c9 LS |
659 | rollback_lock_file(lock_file); |
660 | ||
c4b83e61 | 661 | return has_errors ? 1 : 0; |
e83c5163 | 662 | } |