Skip to content

Commit bc4b924

Browse files
committed
Merge branch 'fc/fast-import-broken-marks-file'
"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
2 parents f3913c2 + f4beed6 commit bc4b924

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

fast-import.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ static const char *export_marks_file;
329329
static const char *import_marks_file;
330330
static int import_marks_file_from_stream;
331331
static int import_marks_file_ignore_missing;
332+
static int import_marks_file_done;
332333
static int relative_marks_paths;
333334

334335
/* Our last blob */
@@ -1802,7 +1803,7 @@ static void dump_marks(void)
18021803
static struct lock_file mark_lock;
18031804
FILE *f;
18041805

1805-
if (!export_marks_file)
1806+
if (!export_marks_file || (import_marks_file && !import_marks_file_done))
18061807
return;
18071808

18081809
if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
@@ -1835,7 +1836,7 @@ static void read_marks(void)
18351836
if (f)
18361837
;
18371838
else if (import_marks_file_ignore_missing && errno == ENOENT)
1838-
return; /* Marks file does not exist */
1839+
goto done; /* Marks file does not exist */
18391840
else
18401841
die_errno("cannot read '%s'", import_marks_file);
18411842
while (fgets(line, sizeof(line), f)) {
@@ -1865,6 +1866,8 @@ static void read_marks(void)
18651866
insert_mark(mark, e);
18661867
}
18671868
fclose(f);
1869+
done:
1870+
import_marks_file_done = 1;
18681871
}
18691872

18701873

t/t9300-fast-import.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,21 @@ test_expect_success 'R: ignore non-git options' '
26502650
git fast-import <input
26512651
'
26522652

2653+
test_expect_success 'R: corrupt lines do not mess marks file' '
2654+
rm -f io.marks &&
2655+
blob=$(echo hi | git hash-object --stdin) &&
2656+
cat >expect <<-EOF &&
2657+
:3 0000000000000000000000000000000000000000
2658+
:1 $blob
2659+
:2 $blob
2660+
EOF
2661+
cp expect io.marks &&
2662+
test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2663+
2664+
EOF
2665+
test_cmp expect io.marks
2666+
'
2667+
26532668
##
26542669
## R: very large blobs
26552670
##

0 commit comments

Comments
 (0)