blob: 11b7f6a5169e0a9a957155c03c7a56667efe980c [file] [log] [blame]
Linus Torvalds8bc9a0c2005-04-07 15:16:10 -07001/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
Linus Torvaldse83c5162005-04-07 15:13:13 -07006#include "cache.h"
Junio C Hamanoee1bec32005-09-26 18:13:08 -07007#include "strbuf.h"
Junio C Hamano973d6a22005-10-16 00:39:07 -07008#include "quote.h"
Linus Torvaldse83c5162005-04-07 15:13:13 -07009
Linus Torvalds121481a2005-04-10 11:32:54 -070010/*
11 * Default to not allowing changes to the list of files. The
12 * tool doesn't actually care, but this makes it harder to add
13 * files to the revision control by mistake by doing something
Junio C Hamano215a7ad2005-09-07 17:26:23 -070014 * like "git-update-index *" and suddenly having all the object
Linus Torvalds121481a2005-04-10 11:32:54 -070015 * files be revision controlled.
16 */
Junio C Hamanocaf4f582005-10-14 21:56:46 -070017static int allow_add;
18static int allow_remove;
19static int allow_replace;
20static int allow_unmerged; /* --refresh needing merge is not error */
21static int not_new; /* --refresh not having working tree files is not error */
22static int quiet; /* --refresh needing update is not error */
23static int info_only;
Petr Baudis9b63f502005-05-31 18:52:43 +020024static int force_remove;
Junio C Hamanocaf4f582005-10-14 21:56:46 -070025static int verbose;
James Bottomleyc6e007b2005-04-24 15:14:16 -070026
27/* Three functions to allow overloaded pointer return; see linux/err.h */
28static inline void *ERR_PTR(long error)
29{
30 return (void *) error;
31}
32
33static inline long PTR_ERR(const void *ptr)
34{
35 return (long) ptr;
36}
37
38static inline long IS_ERR(const void *ptr)
39{
40 return (unsigned long)ptr > (unsigned long)-1000L;
41}
Linus Torvalds121481a2005-04-10 11:32:54 -070042
Junio C Hamanocaf4f582005-10-14 21:56:46 -070043static void report(const char *fmt, ...)
44{
45 va_list vp;
46
47 if (!verbose)
48 return;
49
50 va_start(vp, fmt);
51 vprintf(fmt, vp);
52 putchar('\n');
53 va_end(vp);
54}
55
Junio C Hamano6b5ee132005-09-21 00:00:47 -070056static int add_file_to_cache(const char *path)
Linus Torvaldse83c5162005-04-07 15:13:13 -070057{
Junio C Hamano4c5abf42005-05-08 00:05:18 -070058 int size, namelen, option, status;
Linus Torvaldse83c5162005-04-07 15:13:13 -070059 struct cache_entry *ce;
60 struct stat st;
Linus Torvaldse83c5162005-04-07 15:13:13 -070061
Junio C Hamano4c5abf42005-05-08 00:05:18 -070062 status = lstat(path, &st);
63 if (status < 0 || S_ISDIR(st.st_mode)) {
64 /* When we used to have "path" and now we want to add
65 * "path/file", we need a way to remove "path" before
66 * being able to add "path/file". However,
Junio C Hamano215a7ad2005-09-07 17:26:23 -070067 * "git-update-index --remove path" would not work.
Junio C Hamano4c5abf42005-05-08 00:05:18 -070068 * --force-remove can be used but this is more user
69 * friendly, especially since we can do the opposite
70 * case just fine without --force-remove.
71 */
72 if (status == 0 || (errno == ENOENT || errno == ENOTDIR)) {
Petr Baudis34143b22005-09-18 21:09:22 +020073 if (allow_remove) {
74 if (remove_file_from_cache(path))
75 return error("%s: cannot remove from the index",
76 path);
77 else
78 return 0;
79 } else if (status < 0) {
80 return error("%s: does not exist and --remove not passed",
81 path);
82 }
Linus Torvalds121481a2005-04-10 11:32:54 -070083 }
Amos Waterland89bc8c72005-09-01 09:13:50 -050084 if (0 == status)
Petr Baudis34143b22005-09-18 21:09:22 +020085 return error("%s: is a directory - add files inside instead",
86 path);
Amos Waterland89bc8c72005-09-01 09:13:50 -050087 else
88 return error("lstat(\"%s\"): %s", path,
89 strerror(errno));
Linus Torvaldse83c5162005-04-07 15:13:13 -070090 }
Junio C Hamano3e09cdf2005-10-11 18:45:33 -070091
Linus Torvaldse83c5162005-04-07 15:13:13 -070092 namelen = strlen(path);
93 size = cache_entry_size(namelen);
Christopher Li812666c2005-04-26 12:00:58 -070094 ce = xmalloc(size);
Linus Torvaldse83c5162005-04-07 15:13:13 -070095 memset(ce, 0, size);
96 memcpy(ce->name, path, namelen);
Linus Torvalds711cf3a2005-04-11 09:39:21 -070097 fill_stat_cache_info(ce, &st);
Junio C Hamano3e09cdf2005-10-11 18:45:33 -070098
Linus Torvaldse4479472005-04-16 22:26:31 -070099 ce->ce_mode = create_ce_mode(st.st_mode);
Junio C Hamano3e09cdf2005-10-11 18:45:33 -0700100 if (!trust_executable_bit) {
101 /* If there is an existing entry, pick the mode bits
102 * from it.
103 */
104 int pos = cache_name_pos(path, namelen);
105 if (0 <= pos)
106 ce->ce_mode = active_cache[pos]->ce_mode;
107 }
Linus Torvaldsf5cabd12005-04-15 21:45:38 -0700108 ce->ce_flags = htons(namelen);
Junio C Hamanoec1fcc12005-10-07 03:42:00 -0700109
110 if (index_path(ce->sha1, path, &st, !info_only))
111 return -1;
Junio C Hamano192268c2005-05-07 21:55:21 -0700112 option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
113 option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
Petr Baudis34143b22005-09-18 21:09:22 +0200114 if (add_cache_entry(ce, option))
115 return error("%s: cannot add to the index - missing --add option?",
116 path);
117 return 0;
Linus Torvalds121481a2005-04-10 11:32:54 -0700118}
119
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700120/*
121 * "refresh" does not calculate a new sha1 file or bring the
122 * cache up-to-date for mode/content changes. But what it
123 * _does_ do is to "re-match" the stat information of a file
124 * with the cache, so that you can refresh the cache for a
125 * file that hasn't been changed but where the stat entry is
126 * out of date.
127 *
Alexey Nezhdanov667bb592005-05-19 15:17:16 +0400128 * For example, you'd want to do this after doing a "git-read-tree",
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700129 * to link up the stat cache details with the proper files.
130 */
131static struct cache_entry *refresh_entry(struct cache_entry *ce)
132{
133 struct stat st;
134 struct cache_entry *updated;
135 int changed, size;
136
Kay Sievers8ae0a8c2005-05-05 14:38:25 +0200137 if (lstat(ce->name, &st) < 0)
James Bottomleyc6e007b2005-04-24 15:14:16 -0700138 return ERR_PTR(-errno);
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700139
Brad Roberts5d728c82005-05-14 19:04:25 -0700140 changed = ce_match_stat(ce, &st);
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700141 if (!changed)
Linus Torvalds5d1a5c02005-10-01 13:24:27 -0700142 return NULL;
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700143
Junio C Hamanob0391892005-09-19 15:11:15 -0700144 if (ce_modified(ce, &st))
James Bottomleyc6e007b2005-04-24 15:14:16 -0700145 return ERR_PTR(-EINVAL);
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700146
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700147 size = ce_size(ce);
Christopher Li812666c2005-04-26 12:00:58 -0700148 updated = xmalloc(size);
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700149 memcpy(updated, ce, size);
150 fill_stat_cache_info(updated, &st);
151 return updated;
Linus Torvalds121481a2005-04-10 11:32:54 -0700152}
153
Junio C Hamano90535212005-05-01 21:07:40 -0700154static int refresh_cache(void)
Linus Torvalds121481a2005-04-10 11:32:54 -0700155{
156 int i;
Junio C Hamano90535212005-05-01 21:07:40 -0700157 int has_errors = 0;
Linus Torvalds121481a2005-04-10 11:32:54 -0700158
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700159 for (i = 0; i < active_nr; i++) {
Junio C Hamano1bc992a2005-04-18 10:42:48 -0700160 struct cache_entry *ce, *new;
161 ce = active_cache[i];
162 if (ce_stage(ce)) {
Junio C Hamano1bc992a2005-04-18 10:42:48 -0700163 while ((i < active_nr) &&
164 ! strcmp(active_cache[i]->name, ce->name))
165 i++;
166 i--;
Linus Torvalds5d1a5c02005-10-01 13:24:27 -0700167 if (allow_unmerged)
168 continue;
169 printf("%s: needs merge\n", ce->name);
170 has_errors = 1;
Junio C Hamano1bc992a2005-04-18 10:42:48 -0700171 continue;
172 }
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700173
Junio C Hamano1bc992a2005-04-18 10:42:48 -0700174 new = refresh_entry(ce);
Linus Torvalds5d1a5c02005-10-01 13:24:27 -0700175 if (!new)
176 continue;
James Bottomleyc6e007b2005-04-24 15:14:16 -0700177 if (IS_ERR(new)) {
Linus Torvalds0ed37152005-06-20 21:18:54 -0700178 if (not_new && PTR_ERR(new) == -ENOENT)
179 continue;
180 if (quiet)
181 continue;
182 printf("%s: needs update\n", ce->name);
183 has_errors = 1;
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700184 continue;
185 }
Linus Torvaldsee267522005-05-06 16:48:43 -0700186 active_cache_changed = 1;
Petr Baudis62d046a2005-04-17 23:34:51 +0200187 /* You can NOT just free active_cache[i] here, since it
188 * might not be necessarily malloc()ed but can also come
189 * from mmap(). */
Linus Torvalds711cf3a2005-04-11 09:39:21 -0700190 active_cache[i] = new;
191 }
Junio C Hamano90535212005-05-01 21:07:40 -0700192 return has_errors;
Linus Torvaldse83c5162005-04-07 15:13:13 -0700193}
194
Linus Torvaldse83c5162005-04-07 15:13:13 -0700195/*
196 * We fundamentally don't like some paths: we don't want
Linus Torvalds320d3a12005-05-24 14:40:28 -0700197 * dot or dot-dot anywhere, and for obvious reasons don't
198 * want to recurse into ".git" either.
Linus Torvaldse83c5162005-04-07 15:13:13 -0700199 *
200 * Also, we don't want double slashes or slashes at the
Ingo Molnaraebb2672005-04-12 11:36:26 -0700201 * end that can make pathnames ambiguous.
Linus Torvaldse83c5162005-04-07 15:13:13 -0700202 */
Linus Torvalds320d3a12005-05-24 14:40:28 -0700203static int verify_dotfile(const char *rest)
204{
205 /*
206 * The first character was '.', but that
207 * has already been discarded, we now test
208 * the rest.
209 */
210 switch (*rest) {
211 /* "." is not allowed */
212 case '\0': case '/':
213 return 0;
214
215 /*
216 * ".git" followed by NUL or slash is bad. This
217 * shares the path end test with the ".." case.
218 */
219 case 'g':
220 if (rest[1] != 'i')
221 break;
222 if (rest[2] != 't')
223 break;
224 rest += 2;
225 /* fallthrough */
226 case '.':
227 if (rest[1] == '\0' || rest[1] == '/')
228 return 0;
229 }
230 return 1;
231}
232
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700233static int verify_path(const char *path)
Linus Torvaldse83c5162005-04-07 15:13:13 -0700234{
235 char c;
236
237 goto inside;
238 for (;;) {
239 if (!c)
240 return 1;
241 if (c == '/') {
242inside:
243 c = *path++;
Linus Torvalds320d3a12005-05-24 14:40:28 -0700244 switch (c) {
245 default:
Linus Torvaldse83c5162005-04-07 15:13:13 -0700246 continue;
Linus Torvalds320d3a12005-05-24 14:40:28 -0700247 case '/': case '\0':
248 break;
249 case '.':
250 if (verify_dotfile(path))
251 continue;
252 }
Linus Torvaldse83c5162005-04-07 15:13:13 -0700253 return 0;
254 }
255 c = *path++;
256 }
257}
258
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700259static int add_cacheinfo(const char *arg1, const char *arg2, const char *arg3)
Linus Torvalds9945d982005-04-15 11:08:33 -0700260{
Junio C Hamano192268c2005-05-07 21:55:21 -0700261 int size, len, option;
Linus Torvalds9945d982005-04-15 11:08:33 -0700262 unsigned int mode;
263 unsigned char sha1[20];
264 struct cache_entry *ce;
265
266 if (sscanf(arg1, "%o", &mode) != 1)
267 return -1;
Linus Torvalds9945d982005-04-15 11:08:33 -0700268 if (get_sha1_hex(arg2, sha1))
269 return -1;
Linus Torvalds9945d982005-04-15 11:08:33 -0700270 if (!verify_path(arg3))
271 return -1;
Linus Torvalds9945d982005-04-15 11:08:33 -0700272
273 len = strlen(arg3);
274 size = cache_entry_size(len);
Christopher Li812666c2005-04-26 12:00:58 -0700275 ce = xmalloc(size);
Linus Torvalds9945d982005-04-15 11:08:33 -0700276 memset(ce, 0, size);
277
278 memcpy(ce->sha1, sha1, 20);
279 memcpy(ce->name, arg3, len);
Linus Torvaldsf5cabd12005-04-15 21:45:38 -0700280 ce->ce_flags = htons(len);
Linus Torvaldse4479472005-04-16 22:26:31 -0700281 ce->ce_mode = create_ce_mode(mode);
Junio C Hamano192268c2005-05-07 21:55:21 -0700282 option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
283 option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
Junio C Hamanocaf4f582005-10-14 21:56:46 -0700284 if (add_cache_entry(ce, option))
285 return error("%s: cannot add to the index - missing --add option?",
286 arg3);
287 report("add '%s'", arg3);
288 return 0;
Linus Torvalds9945d982005-04-15 11:08:33 -0700289}
290
Junio C Hamano3e09cdf2005-10-11 18:45:33 -0700291static int chmod_path(int flip, const char *path)
292{
293 int pos;
294 struct cache_entry *ce;
295 unsigned int mode;
Linus Torvaldsf2a19342005-04-26 11:55:42 -0700296
Junio C Hamano3e09cdf2005-10-11 18:45:33 -0700297 pos = cache_name_pos(path, strlen(path));
298 if (pos < 0)
299 return -1;
300 ce = active_cache[pos];
301 mode = ntohl(ce->ce_mode);
302 if (!S_ISREG(mode))
303 return -1;
304 switch (flip) {
305 case '+':
306 ce->ce_mode |= htonl(0111); break;
307 case '-':
308 ce->ce_mode &= htonl(~0111); break;
309 default:
310 return -1;
311 }
312 active_cache_changed = 1;
313 return 0;
314}
315
316static struct cache_file cache_file;
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700317
318static void update_one(const char *path, const char *prefix, int prefix_length)
319{
320 const char *p = prefix_path(prefix, prefix_length, path);
321 if (!verify_path(p)) {
322 fprintf(stderr, "Ignoring path %s\n", path);
323 return;
324 }
325 if (force_remove) {
326 if (remove_file_from_cache(p))
327 die("git-update-index: unable to remove %s", path);
Junio C Hamanocaf4f582005-10-14 21:56:46 -0700328 report("remove '%s'", path);
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700329 return;
330 }
331 if (add_file_to_cache(p))
332 die("Unable to process file %s", path);
Junio C Hamanocaf4f582005-10-14 21:56:46 -0700333 report("add '%s'", path);
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700334}
335
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700336static void read_index_info(int line_termination)
337{
338 struct strbuf buf;
339 strbuf_init(&buf);
340 while (1) {
Junio C Hamano9c20a472005-11-21 21:46:57 -0800341 char *ptr, *tab;
Junio C Hamano973d6a22005-10-16 00:39:07 -0700342 char *path_name;
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700343 unsigned char sha1[20];
344 unsigned int mode;
345
346 read_line(&buf, stdin, line_termination);
347 if (buf.eof)
348 break;
349
350 mode = strtoul(buf.buf, &ptr, 8);
Junio C Hamano9c20a472005-11-21 21:46:57 -0800351 if (ptr == buf.buf || *ptr != ' ')
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700352 goto bad_line;
353
Junio C Hamano9c20a472005-11-21 21:46:57 -0800354 tab = strchr(ptr, '\t');
355 if (!tab || tab - ptr < 41)
356 goto bad_line;
357 if (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ')
358 goto bad_line;
359 ptr = tab + 1;
Junio C Hamano973d6a22005-10-16 00:39:07 -0700360
361 if (line_termination && ptr[0] == '"')
362 path_name = unquote_c_style(ptr, NULL);
363 else
364 path_name = ptr;
365
366 if (!verify_path(path_name)) {
367 fprintf(stderr, "Ignoring path %s\n", path_name);
368 if (path_name != ptr)
369 free(path_name);
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700370 continue;
371 }
372
373 if (!mode) {
374 /* mode == 0 means there is no such path -- remove */
Junio C Hamano973d6a22005-10-16 00:39:07 -0700375 if (remove_file_from_cache(path_name))
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700376 die("git-update-index: unable to remove %s",
377 ptr);
378 }
379 else {
380 /* mode ' ' sha1 '\t' name
381 * ptr[-1] points at tab,
382 * ptr[-41] is at the beginning of sha1
383 */
384 ptr[-42] = ptr[-1] = 0;
Junio C Hamano973d6a22005-10-16 00:39:07 -0700385 if (add_cacheinfo(buf.buf, ptr-41, path_name))
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700386 die("git-update-index: unable to update %s",
Junio C Hamano973d6a22005-10-16 00:39:07 -0700387 path_name);
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700388 }
Junio C Hamano973d6a22005-10-16 00:39:07 -0700389 if (path_name != ptr)
390 free(path_name);
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700391 continue;
392
393 bad_line:
394 die("malformed index info %s", buf.buf);
395 }
396}
397
Petr Baudisf6ab5bb2005-10-25 17:26:25 +0200398static const char update_index_usage[] =
Chris Shoemaker14470c02005-10-29 17:46:41 -0400399"git-update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--cacheinfo] [--chmod=(+|-)x] [--info-only] [--force-remove] [--stdin] [--index-info] [--ignore-missing] [-z] [--verbose] [--] <file>...";
Petr Baudisf6ab5bb2005-10-25 17:26:25 +0200400
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700401int main(int argc, const char **argv)
Linus Torvaldse83c5162005-04-07 15:13:13 -0700402{
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700403 int i, newfd, entries, has_errors = 0, line_termination = '\n';
Linus Torvalds121481a2005-04-10 11:32:54 -0700404 int allow_options = 1;
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700405 int read_from_stdin = 0;
Linus Torvaldscfb0af12005-08-17 13:32:22 -0700406 const char *prefix = setup_git_directory();
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700407 int prefix_length = prefix ? strlen(prefix) : 0;
Linus Torvaldse83c5162005-04-07 15:13:13 -0700408
Junio C Hamano3e09cdf2005-10-11 18:45:33 -0700409 git_config(git_default_config);
410
Junio C Hamano415e96c2005-05-15 14:23:12 -0700411 newfd = hold_index_file_for_update(&cache_file, get_index_file());
Linus Torvalds9614b8d2005-04-11 15:39:26 -0700412 if (newfd < 0)
Petr Baudis2de381f2005-04-13 02:28:48 -0700413 die("unable to create new cachefile");
Linus Torvalds9614b8d2005-04-11 15:39:26 -0700414
Linus Torvalds9614b8d2005-04-11 15:39:26 -0700415 entries = read_cache();
416 if (entries < 0)
Petr Baudis2de381f2005-04-13 02:28:48 -0700417 die("cache corrupted");
Linus Torvalds9614b8d2005-04-11 15:39:26 -0700418
Linus Torvaldse83c5162005-04-07 15:13:13 -0700419 for (i = 1 ; i < argc; i++) {
Junio C Hamano6b5ee132005-09-21 00:00:47 -0700420 const char *path = argv[i];
Linus Torvalds121481a2005-04-10 11:32:54 -0700421
422 if (allow_options && *path == '-') {
423 if (!strcmp(path, "--")) {
424 allow_options = 0;
425 continue;
426 }
Linus Torvalds0ed37152005-06-20 21:18:54 -0700427 if (!strcmp(path, "-q")) {
428 quiet = 1;
429 continue;
430 }
Linus Torvalds121481a2005-04-10 11:32:54 -0700431 if (!strcmp(path, "--add")) {
432 allow_add = 1;
433 continue;
434 }
Junio C Hamano192268c2005-05-07 21:55:21 -0700435 if (!strcmp(path, "--replace")) {
436 allow_replace = 1;
437 continue;
438 }
Linus Torvalds121481a2005-04-10 11:32:54 -0700439 if (!strcmp(path, "--remove")) {
440 allow_remove = 1;
441 continue;
442 }
Linus Torvalds5d1a5c02005-10-01 13:24:27 -0700443 if (!strcmp(path, "--unmerged")) {
444 allow_unmerged = 1;
445 continue;
446 }
Linus Torvalds121481a2005-04-10 11:32:54 -0700447 if (!strcmp(path, "--refresh")) {
Junio C Hamano90535212005-05-01 21:07:40 -0700448 has_errors |= refresh_cache();
Linus Torvalds121481a2005-04-10 11:32:54 -0700449 continue;
450 }
Linus Torvalds9945d982005-04-15 11:08:33 -0700451 if (!strcmp(path, "--cacheinfo")) {
Junio C Hamanob3f94c42005-05-08 15:31:33 -0700452 if (i+3 >= argc)
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700453 die("git-update-index: --cacheinfo <mode> <sha1> <path>");
Junio C Hamanob3f94c42005-05-08 15:31:33 -0700454 if (add_cacheinfo(argv[i+1], argv[i+2], argv[i+3]))
Junio C Hamano215a7ad2005-09-07 17:26:23 -0700455 die("git-update-index: --cacheinfo cannot add %s", argv[i+3]);
Linus Torvalds9945d982005-04-15 11:08:33 -0700456 i += 3;
457 continue;
458 }
Junio C Hamano3e09cdf2005-10-11 18:45:33 -0700459 if (!strcmp(path, "--chmod=-x") ||
460 !strcmp(path, "--chmod=+x")) {
461 if (argc <= i+1)
462 die("git-update-index: %s <path>", path);
463 if (chmod_path(path[8], argv[++i]))
464 die("git-update-index: %s cannot chmod %s", path, argv[i]);
465 continue;
466 }
Bryan Larsendf6e1512005-07-08 16:52:12 -0700467 if (!strcmp(path, "--info-only")) {
468 info_only = 1;
469 continue;
470 }
Junio C Hamano0ff5bf72005-05-01 23:50:51 -0700471 if (!strcmp(path, "--force-remove")) {
Petr Baudis9b63f502005-05-31 18:52:43 +0200472 force_remove = 1;
Junio C Hamano0ff5bf72005-05-01 23:50:51 -0700473 continue;
474 }
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700475 if (!strcmp(path, "-z")) {
476 line_termination = 0;
477 continue;
478 }
479 if (!strcmp(path, "--stdin")) {
480 if (i != argc - 1)
481 die("--stdin must be at the end");
482 read_from_stdin = 1;
483 break;
484 }
Junio C Hamanod4dbf36d2005-10-07 03:42:00 -0700485 if (!strcmp(path, "--index-info")) {
486 allow_add = allow_replace = allow_remove = 1;
487 read_index_info(line_termination);
488 continue;
489 }
James Bottomleyc6e007b2005-04-24 15:14:16 -0700490 if (!strcmp(path, "--ignore-missing")) {
491 not_new = 1;
492 continue;
493 }
Junio C Hamanocaf4f582005-10-14 21:56:46 -0700494 if (!strcmp(path, "--verbose")) {
495 verbose = 1;
496 continue;
497 }
Petr Baudisf6ab5bb2005-10-25 17:26:25 +0200498 if (!strcmp(path, "-h") || !strcmp(path, "--help"))
499 usage(update_index_usage);
Petr Baudis2de381f2005-04-13 02:28:48 -0700500 die("unknown option %s", path);
Linus Torvalds121481a2005-04-10 11:32:54 -0700501 }
Junio C Hamanoee1bec32005-09-26 18:13:08 -0700502 update_one(path, prefix, prefix_length);
503 }
504 if (read_from_stdin) {
505 struct strbuf buf;
506 strbuf_init(&buf);
507 while (1) {
508 read_line(&buf, stdin, line_termination);
509 if (buf.eof)
510 break;
511 update_one(buf.buf, prefix, prefix_length);
Linus Torvaldse83c5162005-04-07 15:13:13 -0700512 }
Linus Torvaldse83c5162005-04-07 15:13:13 -0700513 }
Linus Torvalds5cd5ace2005-10-01 13:39:47 -0700514 if (active_cache_changed) {
515 if (write_cache(newfd, active_cache, active_nr) ||
516 commit_index_file(&cache_file))
517 die("Unable to write new cachefile");
518 }
Linus Torvalds9614b8d2005-04-11 15:39:26 -0700519
Junio C Hamanoc4b83e62005-05-05 15:29:06 -0700520 return has_errors ? 1 : 0;
Linus Torvaldse83c5162005-04-07 15:13:13 -0700521}