Merge branch 'fc/fast-import-broken-marks-file'
authorJunio C Hamano <gitster@pobox.com>
Tue, 31 May 2016 19:40:53 +0000 (12:40 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 May 2016 19:40:53 +0000 (12:40 -0700)
"git fast-import --export-marks" would overwrite the existing marks
file even when it makes a dump from its custom die routine.
Prevent it from doing so when we have an import-marks file but
haven't finished reading it.

* fc/fast-import-broken-marks-file:
fast-import: do not truncate exported marks file

1  2 
fast-import.c
diff --combined fast-import.c
index 83558dcfe3ab442a415accd82ec7503f95f4746e,a975c348d8b3f9e9f638897dde8c3e7dc5803e1c..c504ef752db124e21156be5b92360dbe432e568f
@@@ -329,6 -329,7 +329,7 @@@ static const char *export_marks_file
  static const char *import_marks_file;
  static int import_marks_file_from_stream;
  static int import_marks_file_ignore_missing;
+ static int import_marks_file_done;
  static int relative_marks_paths;
  
  /* Our last blob */
@@@ -414,7 -415,7 +415,7 @@@ static void write_crash_report(const ch
        struct recent_command *rc;
  
        if (!rpt) {
 -              error("can't write crash report %s: %s", loc, strerror(errno));
 +              error_errno("can't write crash report %s", loc);
                free(loc);
                return;
        }
@@@ -1512,7 -1513,7 +1513,7 @@@ static int tree_content_set
        t = root->tree;
        for (i = 0; i < t->entry_count; i++) {
                e = t->entries[i];
 -              if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
 +              if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
                        if (!*slash1) {
                                if (!S_ISDIR(mode)
                                                && e->versions[1].mode == mode
@@@ -1602,7 -1603,7 +1603,7 @@@ static int tree_content_remove
        t = root->tree;
        for (i = 0; i < t->entry_count; i++) {
                e = t->entries[i];
 -              if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
 +              if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
                        if (*slash1 && !S_ISDIR(e->versions[1].mode))
                                /*
                                 * If p names a file in some subdirectory, and a
@@@ -1669,7 -1670,7 +1670,7 @@@ static int tree_content_get
        t = root->tree;
        for (i = 0; i < t->entry_count; i++) {
                e = t->entries[i];
 -              if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
 +              if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
                        if (!*slash1)
                                goto found_entry;
                        if (!S_ISDIR(e->versions[1].mode))
@@@ -1802,12 -1803,12 +1803,12 @@@ static void dump_marks(void
        static struct lock_file mark_lock;
        FILE *f;
  
-       if (!export_marks_file)
+       if (!export_marks_file || (import_marks_file && !import_marks_file_done))
                return;
  
        if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
 -              failure |= error("Unable to write marks file %s: %s",
 -                      export_marks_file, strerror(errno));
 +              failure |= error_errno("Unable to write marks file %s",
 +                                     export_marks_file);
                return;
        }
  
  
        dump_marks_helper(f, 0, marks);
        if (commit_lock_file(&mark_lock)) {
 -              failure |= error("Unable to write file %s: %s",
 -                      export_marks_file, strerror(errno));
 +              failure |= error_errno("Unable to write file %s",
 +                                     export_marks_file);
                return;
        }
  }
@@@ -1835,7 -1836,7 +1836,7 @@@ static void read_marks(void
        if (f)
                ;
        else if (import_marks_file_ignore_missing && errno == ENOENT)
-               return; /* Marks file does not exist */
+               goto done; /* Marks file does not exist */
        else
                die_errno("cannot read '%s'", import_marks_file);
        while (fgets(line, sizeof(line), f)) {
                insert_mark(mark, e);
        }
        fclose(f);
+ done:
+       import_marks_file_done = 1;
  }