Code

Merge branch 'ph/strbuf' into kh/commit
[git.git] / builtin-update-index.c
1 /*
2  * GIT - The information manager from hell
3  *
4  * Copyright (C) Linus Torvalds, 2005
5  */
6 #include "cache.h"
7 #include "quote.h"
8 #include "cache-tree.h"
9 #include "tree-walk.h"
10 #include "builtin.h"
11 #include "refs.h"
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
17  * like "git-update-index *" and suddenly having all the object
18  * files be revision controlled.
19  */
20 static int allow_add;
21 static int allow_remove;
22 static int allow_replace;
23 static int info_only;
24 static int force_remove;
25 static int verbose;
26 static int mark_valid_only;
27 #define MARK_VALID 1
28 #define UNMARK_VALID 2
30 static void report(const char *fmt, ...)
31 {
32         va_list vp;
34         if (!verbose)
35                 return;
37         va_start(vp, fmt);
38         vprintf(fmt, vp);
39         putchar('\n');
40         va_end(vp);
41 }
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                 }
56                 cache_tree_invalidate_path(active_cache_tree, path);
57                 active_cache_changed = 1;
58                 return 0;
59         }
60         return -1;
61 }
63 static int remove_one_path(const char *path)
64 {
65         if (!allow_remove)
66                 return error("%s: does not exist and --remove not passed", path);
67         if (remove_file_from_cache(path))
68                 return error("%s: cannot remove from the index", path);
69         return 0;
70 }
72 /*
73  * Handle a path that couldn't be lstat'ed. It's either:
74  *  - missing file (ENOENT or ENOTDIR). That's ok if we're
75  *    supposed to be removing it and the removal actually
76  *    succeeds.
77  *  - permission error. That's never ok.
78  */
79 static int process_lstat_error(const char *path, int err)
80 {
81         if (err == ENOENT || err == ENOTDIR)
82                 return remove_one_path(path);
83         return error("lstat(\"%s\"): %s", path, strerror(errno));
84 }
86 static int add_one_path(struct cache_entry *old, const char *path, int len, struct stat *st)
87 {
88         int option, size;
89         struct cache_entry *ce;
91         /* Was the old index entry already up-to-date? */
92         if (old && !ce_stage(old) && !ce_match_stat(old, st, 0))
93                 return 0;
95         size = cache_entry_size(len);
96         ce = xcalloc(1, size);
97         memcpy(ce->name, path, len);
98         ce->ce_flags = htons(len);
99         fill_stat_cache_info(ce, st);
100         ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
102         if (index_path(ce->sha1, path, st, !info_only))
103                 return -1;
104         option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
105         option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
106         if (add_cache_entry(ce, option))
107                 return error("%s: cannot add to the index - missing --add option?", path);
108         return 0;
111 /*
112  * Handle a path that was a directory. Four cases:
113  *
114  *  - it's already a gitlink in the index, and we keep it that
115  *    way, and update it if we can (if we cannot find the HEAD,
116  *    we're going to keep it unchanged in the index!)
117  *
118  *  - it's a *file* in the index, in which case it should be
119  *    removed as a file if removal is allowed, since it doesn't
120  *    exist as such any more. If removal isn't allowed, it's
121  *    an error.
122  *
123  *    (NOTE! This is old and arguably fairly strange behaviour.
124  *    We might want to make this an error unconditionally, and
125  *    use "--force-remove" if you actually want to force removal).
126  *
127  *  - it used to exist as a subdirectory (ie multiple files with
128  *    this particular prefix) in the index, in which case it's wrong
129  *    to try to update it as a directory.
130  *
131  *  - it doesn't exist at all in the index, but it is a valid
132  *    git directory, and it should be *added* as a gitlink.
133  */
134 static int process_directory(const char *path, int len, struct stat *st)
136         unsigned char sha1[20];
137         int pos = cache_name_pos(path, len);
139         /* Exact match: file or existing gitlink */
140         if (pos >= 0) {
141                 struct cache_entry *ce = active_cache[pos];
142                 if (S_ISGITLINK(ntohl(ce->ce_mode))) {
144                         /* Do nothing to the index if there is no HEAD! */
145                         if (resolve_gitlink_ref(path, "HEAD", sha1) < 0)
146                                 return 0;
148                         return add_one_path(ce, path, len, st);
149                 }
150                 /* Should this be an unconditional error? */
151                 return remove_one_path(path);
152         }
154         /* Inexact match: is there perhaps a subdirectory match? */
155         pos = -pos-1;
156         while (pos < active_nr) {
157                 struct cache_entry *ce = active_cache[pos++];
159                 if (strncmp(ce->name, path, len))
160                         break;
161                 if (ce->name[len] > '/')
162                         break;
163                 if (ce->name[len] < '/')
164                         continue;
166                 /* Subdirectory match - error out */
167                 return error("%s: is a directory - add individual files instead", path);
168         }
170         /* No match - should we add it as a gitlink? */
171         if (!resolve_gitlink_ref(path, "HEAD", sha1))
172                 return add_one_path(NULL, path, len, st);
174         /* Error out. */
175         return error("%s: is a directory - add files inside instead", path);
178 /*
179  * Process a regular file
180  */
181 static int process_file(const char *path, int len, struct stat *st)
183         int pos = cache_name_pos(path, len);
184         struct cache_entry *ce = pos < 0 ? NULL : active_cache[pos];
186         if (ce && S_ISGITLINK(ntohl(ce->ce_mode)))
187                 return error("%s is already a gitlink, not replacing", path);
189         return add_one_path(ce, path, len, st);
192 static int process_path(const char *path)
194         int len;
195         struct stat st;
197         /*
198          * First things first: get the stat information, to decide
199          * what to do about the pathname!
200          */
201         if (lstat(path, &st) < 0)
202                 return process_lstat_error(path, errno);
204         len = strlen(path);
205         if (S_ISDIR(st.st_mode))
206                 return process_directory(path, len, &st);
208         return process_file(path, len, &st);
211 static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
212                          const char *path, int stage)
214         int size, len, option;
215         struct cache_entry *ce;
217         if (!verify_path(path))
218                 return -1;
220         len = strlen(path);
221         size = cache_entry_size(len);
222         ce = xcalloc(1, size);
224         hashcpy(ce->sha1, sha1);
225         memcpy(ce->name, path, len);
226         ce->ce_flags = create_ce_flags(len, stage);
227         ce->ce_mode = create_ce_mode(mode);
228         if (assume_unchanged)
229                 ce->ce_flags |= htons(CE_VALID);
230         option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
231         option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
232         if (add_cache_entry(ce, option))
233                 return error("%s: cannot add to the index - missing --add option?",
234                              path);
235         report("add '%s'", path);
236         return 0;
239 static void chmod_path(int flip, const char *path)
241         int pos;
242         struct cache_entry *ce;
243         unsigned int mode;
245         pos = cache_name_pos(path, strlen(path));
246         if (pos < 0)
247                 goto fail;
248         ce = active_cache[pos];
249         mode = ntohl(ce->ce_mode);
250         if (!S_ISREG(mode))
251                 goto fail;
252         switch (flip) {
253         case '+':
254                 ce->ce_mode |= htonl(0111); break;
255         case '-':
256                 ce->ce_mode &= htonl(~0111); break;
257         default:
258                 goto fail;
259         }
260         cache_tree_invalidate_path(active_cache_tree, path);
261         active_cache_changed = 1;
262         report("chmod %cx '%s'", flip, path);
263         return;
264  fail:
265         die("git-update-index: cannot chmod %cx '%s'", flip, path);
268 static void update_one(const char *path, const char *prefix, int prefix_length)
270         const char *p = prefix_path(prefix, prefix_length, path);
271         if (!verify_path(p)) {
272                 fprintf(stderr, "Ignoring path %s\n", path);
273                 goto free_return;
274         }
275         if (mark_valid_only) {
276                 if (mark_valid(p))
277                         die("Unable to mark file %s", path);
278                 goto free_return;
279         }
281         if (force_remove) {
282                 if (remove_file_from_cache(p))
283                         die("git-update-index: unable to remove %s", path);
284                 report("remove '%s'", path);
285                 goto free_return;
286         }
287         if (process_path(p))
288                 die("Unable to process path %s", path);
289         report("add '%s'", path);
290  free_return:
291         if (p < path || p > path + strlen(path))
292                 free((char*)p);
295 static void read_index_info(int line_termination)
297         struct strbuf buf;
298         struct strbuf uq;
300         strbuf_init(&buf, 0);
301         strbuf_init(&uq, 0);
302         while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
303                 char *ptr, *tab;
304                 char *path_name;
305                 unsigned char sha1[20];
306                 unsigned int mode;
307                 unsigned long ul;
308                 int stage;
310                 /* This reads lines formatted in one of three formats:
311                  *
312                  * (1) mode         SP sha1          TAB path
313                  * The first format is what "git-apply --index-info"
314                  * reports, and used to reconstruct a partial tree
315                  * that is used for phony merge base tree when falling
316                  * back on 3-way merge.
317                  *
318                  * (2) mode SP type SP sha1          TAB path
319                  * The second format is to stuff git-ls-tree output
320                  * into the index file.
321                  *
322                  * (3) mode         SP sha1 SP stage TAB path
323                  * This format is to put higher order stages into the
324                  * index file and matches git-ls-files --stage output.
325                  */
326                 errno = 0;
327                 ul = strtoul(buf.buf, &ptr, 8);
328                 if (ptr == buf.buf || *ptr != ' '
329                     || errno || (unsigned int) ul != ul)
330                         goto bad_line;
331                 mode = ul;
333                 tab = strchr(ptr, '\t');
334                 if (!tab || tab - ptr < 41)
335                         goto bad_line;
337                 if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') {
338                         stage = tab[-1] - '0';
339                         ptr = tab + 1; /* point at the head of path */
340                         tab = tab - 2; /* point at tail of sha1 */
341                 }
342                 else {
343                         stage = 0;
344                         ptr = tab + 1; /* point at the head of path */
345                 }
347                 if (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ')
348                         goto bad_line;
350                 path_name = ptr;
351                 if (line_termination && path_name[0] == '"') {
352                         strbuf_reset(&uq);
353                         if (unquote_c_style(&uq, path_name, NULL)) {
354                                 die("git-update-index: bad quoting of path name");
355                         }
356                         path_name = uq.buf;
357                 }
359                 if (!verify_path(path_name)) {
360                         fprintf(stderr, "Ignoring path %s\n", path_name);
361                         continue;
362                 }
364                 if (!mode) {
365                         /* mode == 0 means there is no such path -- remove */
366                         if (remove_file_from_cache(path_name))
367                                 die("git-update-index: unable to remove %s",
368                                     ptr);
369                 }
370                 else {
371                         /* mode ' ' sha1 '\t' name
372                          * ptr[-1] points at tab,
373                          * ptr[-41] is at the beginning of sha1
374                          */
375                         ptr[-42] = ptr[-1] = 0;
376                         if (add_cacheinfo(mode, sha1, path_name, stage))
377                                 die("git-update-index: unable to update %s",
378                                     path_name);
379                 }
380                 if (path_name != ptr)
381                         free(path_name);
382                 continue;
384         bad_line:
385                 die("malformed index info %s", buf.buf);
386         }
387         strbuf_release(&buf);
388         strbuf_release(&uq);
391 static const char update_index_usage[] =
392 "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>...";
394 static unsigned char head_sha1[20];
395 static unsigned char merge_head_sha1[20];
397 static struct cache_entry *read_one_ent(const char *which,
398                                         unsigned char *ent, const char *path,
399                                         int namelen, int stage)
401         unsigned mode;
402         unsigned char sha1[20];
403         int size;
404         struct cache_entry *ce;
406         if (get_tree_entry(ent, path, sha1, &mode)) {
407                 if (which)
408                         error("%s: not in %s branch.", path, which);
409                 return NULL;
410         }
411         if (mode == S_IFDIR) {
412                 if (which)
413                         error("%s: not a blob in %s branch.", path, which);
414                 return NULL;
415         }
416         size = cache_entry_size(namelen);
417         ce = xcalloc(1, size);
419         hashcpy(ce->sha1, sha1);
420         memcpy(ce->name, path, namelen);
421         ce->ce_flags = create_ce_flags(namelen, stage);
422         ce->ce_mode = create_ce_mode(mode);
423         return ce;
426 static int unresolve_one(const char *path)
428         int namelen = strlen(path);
429         int pos;
430         int ret = 0;
431         struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
433         /* See if there is such entry in the index. */
434         pos = cache_name_pos(path, namelen);
435         if (pos < 0) {
436                 /* If there isn't, either it is unmerged, or
437                  * resolved as "removed" by mistake.  We do not
438                  * want to do anything in the former case.
439                  */
440                 pos = -pos-1;
441                 if (pos < active_nr) {
442                         struct cache_entry *ce = active_cache[pos];
443                         if (ce_namelen(ce) == namelen &&
444                             !memcmp(ce->name, path, namelen)) {
445                                 fprintf(stderr,
446                                         "%s: skipping still unmerged path.\n",
447                                         path);
448                                 goto free_return;
449                         }
450                 }
451         }
453         /* Grab blobs from given path from HEAD and MERGE_HEAD,
454          * stuff HEAD version in stage #2,
455          * stuff MERGE_HEAD version in stage #3.
456          */
457         ce_2 = read_one_ent("our", head_sha1, path, namelen, 2);
458         ce_3 = read_one_ent("their", merge_head_sha1, path, namelen, 3);
460         if (!ce_2 || !ce_3) {
461                 ret = -1;
462                 goto free_return;
463         }
464         if (!hashcmp(ce_2->sha1, ce_3->sha1) &&
465             ce_2->ce_mode == ce_3->ce_mode) {
466                 fprintf(stderr, "%s: identical in both, skipping.\n",
467                         path);
468                 goto free_return;
469         }
471         remove_file_from_cache(path);
472         if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {
473                 error("%s: cannot add our version to the index.", path);
474                 ret = -1;
475                 goto free_return;
476         }
477         if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))
478                 return 0;
479         error("%s: cannot add their version to the index.", path);
480         ret = -1;
481  free_return:
482         free(ce_2);
483         free(ce_3);
484         return ret;
487 static void read_head_pointers(void)
489         if (read_ref("HEAD", head_sha1))
490                 die("No HEAD -- no initial commit yet?\n");
491         if (read_ref("MERGE_HEAD", merge_head_sha1)) {
492                 fprintf(stderr, "Not in the middle of a merge.\n");
493                 exit(0);
494         }
497 static int do_unresolve(int ac, const char **av,
498                         const char *prefix, int prefix_length)
500         int i;
501         int err = 0;
503         /* Read HEAD and MERGE_HEAD; if MERGE_HEAD does not exist, we
504          * are not doing a merge, so exit with success status.
505          */
506         read_head_pointers();
508         for (i = 1; i < ac; i++) {
509                 const char *arg = av[i];
510                 const char *p = prefix_path(prefix, prefix_length, arg);
511                 err |= unresolve_one(p);
512                 if (p < arg || p > arg + strlen(arg))
513                         free((char*)p);
514         }
515         return err;
518 static int do_reupdate(int ac, const char **av,
519                        const char *prefix, int prefix_length)
521         /* Read HEAD and run update-index on paths that are
522          * merged and already different between index and HEAD.
523          */
524         int pos;
525         int has_head = 1;
526         const char **pathspec = get_pathspec(prefix, av + 1);
528         if (read_ref("HEAD", head_sha1))
529                 /* If there is no HEAD, that means it is an initial
530                  * commit.  Update everything in the index.
531                  */
532                 has_head = 0;
533  redo:
534         for (pos = 0; pos < active_nr; pos++) {
535                 struct cache_entry *ce = active_cache[pos];
536                 struct cache_entry *old = NULL;
537                 int save_nr;
539                 if (ce_stage(ce) || !ce_path_match(ce, pathspec))
540                         continue;
541                 if (has_head)
542                         old = read_one_ent(NULL, head_sha1,
543                                            ce->name, ce_namelen(ce), 0);
544                 if (old && ce->ce_mode == old->ce_mode &&
545                     !hashcmp(ce->sha1, old->sha1)) {
546                         free(old);
547                         continue; /* unchanged */
548                 }
549                 /* Be careful.  The working tree may not have the
550                  * path anymore, in which case, under 'allow_remove',
551                  * or worse yet 'allow_replace', active_nr may decrease.
552                  */
553                 save_nr = active_nr;
554                 update_one(ce->name + prefix_length, prefix, prefix_length);
555                 if (save_nr != active_nr)
556                         goto redo;
557         }
558         return 0;
561 int cmd_update_index(int argc, const char **argv, const char *prefix)
563         int i, newfd, entries, has_errors = 0, line_termination = '\n';
564         int allow_options = 1;
565         int read_from_stdin = 0;
566         int prefix_length = prefix ? strlen(prefix) : 0;
567         char set_executable_bit = 0;
568         unsigned int refresh_flags = 0;
569         int lock_error = 0;
570         struct lock_file *lock_file;
572         git_config(git_default_config);
574         /* We can't free this memory, it becomes part of a linked list parsed atexit() */
575         lock_file = xcalloc(1, sizeof(struct lock_file));
577         newfd = hold_locked_index(lock_file, 0);
578         if (newfd < 0)
579                 lock_error = errno;
581         entries = read_cache();
582         if (entries < 0)
583                 die("cache corrupted");
585         for (i = 1 ; i < argc; i++) {
586                 const char *path = argv[i];
587                 const char *p;
589                 if (allow_options && *path == '-') {
590                         if (!strcmp(path, "--")) {
591                                 allow_options = 0;
592                                 continue;
593                         }
594                         if (!strcmp(path, "-q")) {
595                                 refresh_flags |= REFRESH_QUIET;
596                                 continue;
597                         }
598                         if (!strcmp(path, "--add")) {
599                                 allow_add = 1;
600                                 continue;
601                         }
602                         if (!strcmp(path, "--replace")) {
603                                 allow_replace = 1;
604                                 continue;
605                         }
606                         if (!strcmp(path, "--remove")) {
607                                 allow_remove = 1;
608                                 continue;
609                         }
610                         if (!strcmp(path, "--unmerged")) {
611                                 refresh_flags |= REFRESH_UNMERGED;
612                                 continue;
613                         }
614                         if (!strcmp(path, "--refresh")) {
615                                 has_errors |= refresh_cache(refresh_flags);
616                                 continue;
617                         }
618                         if (!strcmp(path, "--really-refresh")) {
619                                 has_errors |= refresh_cache(REFRESH_REALLY | refresh_flags);
620                                 continue;
621                         }
622                         if (!strcmp(path, "--cacheinfo")) {
623                                 unsigned char sha1[20];
624                                 unsigned int mode;
626                                 if (i+3 >= argc)
627                                         die("git-update-index: --cacheinfo <mode> <sha1> <path>");
629                                 if (strtoul_ui(argv[i+1], 8, &mode) ||
630                                     get_sha1_hex(argv[i+2], sha1) ||
631                                     add_cacheinfo(mode, sha1, argv[i+3], 0))
632                                         die("git-update-index: --cacheinfo"
633                                             " cannot add %s", argv[i+3]);
634                                 i += 3;
635                                 continue;
636                         }
637                         if (!strcmp(path, "--chmod=-x") ||
638                             !strcmp(path, "--chmod=+x")) {
639                                 if (argc <= i+1)
640                                         die("git-update-index: %s <path>", path);
641                                 set_executable_bit = path[8];
642                                 continue;
643                         }
644                         if (!strcmp(path, "--assume-unchanged")) {
645                                 mark_valid_only = MARK_VALID;
646                                 continue;
647                         }
648                         if (!strcmp(path, "--no-assume-unchanged")) {
649                                 mark_valid_only = UNMARK_VALID;
650                                 continue;
651                         }
652                         if (!strcmp(path, "--info-only")) {
653                                 info_only = 1;
654                                 continue;
655                         }
656                         if (!strcmp(path, "--force-remove")) {
657                                 force_remove = 1;
658                                 continue;
659                         }
660                         if (!strcmp(path, "-z")) {
661                                 line_termination = 0;
662                                 continue;
663                         }
664                         if (!strcmp(path, "--stdin")) {
665                                 if (i != argc - 1)
666                                         die("--stdin must be at the end");
667                                 read_from_stdin = 1;
668                                 break;
669                         }
670                         if (!strcmp(path, "--index-info")) {
671                                 if (i != argc - 1)
672                                         die("--index-info must be at the end");
673                                 allow_add = allow_replace = allow_remove = 1;
674                                 read_index_info(line_termination);
675                                 break;
676                         }
677                         if (!strcmp(path, "--unresolve")) {
678                                 has_errors = do_unresolve(argc - i, argv + i,
679                                                           prefix, prefix_length);
680                                 if (has_errors)
681                                         active_cache_changed = 0;
682                                 goto finish;
683                         }
684                         if (!strcmp(path, "--again") || !strcmp(path, "-g")) {
685                                 has_errors = do_reupdate(argc - i, argv + i,
686                                                          prefix, prefix_length);
687                                 if (has_errors)
688                                         active_cache_changed = 0;
689                                 goto finish;
690                         }
691                         if (!strcmp(path, "--ignore-missing")) {
692                                 refresh_flags |= REFRESH_IGNORE_MISSING;
693                                 continue;
694                         }
695                         if (!strcmp(path, "--verbose")) {
696                                 verbose = 1;
697                                 continue;
698                         }
699                         if (!strcmp(path, "-h") || !strcmp(path, "--help"))
700                                 usage(update_index_usage);
701                         die("unknown option %s", path);
702                 }
703                 p = prefix_path(prefix, prefix_length, path);
704                 update_one(p, NULL, 0);
705                 if (set_executable_bit)
706                         chmod_path(set_executable_bit, p);
707                 if (p < path || p > path + strlen(path))
708                         free((char*)p);
709         }
710         if (read_from_stdin) {
711                 struct strbuf buf, nbuf;
713                 strbuf_init(&buf, 0);
714                 strbuf_init(&nbuf, 0);
715                 while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
716                         const char *p;
717                         if (line_termination && buf.buf[0] == '"') {
718                                 strbuf_reset(&nbuf);
719                                 if (unquote_c_style(&nbuf, buf.buf, NULL))
720                                         die("line is badly quoted");
721                                 strbuf_swap(&buf, &nbuf);
722                         }
723                         p = prefix_path(prefix, prefix_length, buf.buf);
724                         update_one(p, NULL, 0);
725                         if (set_executable_bit)
726                                 chmod_path(set_executable_bit, p);
727                         if (p < buf.buf || p > buf.buf + buf.len)
728                                 free((char *)p);
729                 }
730                 strbuf_release(&nbuf);
731                 strbuf_release(&buf);
732         }
734  finish:
735         if (active_cache_changed) {
736                 if (newfd < 0) {
737                         if (refresh_flags & REFRESH_QUIET)
738                                 exit(128);
739                         die("unable to create '%s.lock': %s",
740                             get_index_file(), strerror(lock_error));
741                 }
742                 if (write_cache(newfd, active_cache, active_nr) ||
743                     close(newfd) || commit_locked_index(lock_file))
744                         die("Unable to write new index file");
745         }
747         rollback_lock_file(lock_file);
749         return has_errors ? 1 : 0;