Skip to content

Commit 0196830

Browse files
peffdscho
authored andcommitted
fast-import: delay creating leading directories for export-marks
When we parse the --export-marks option, we don't immediately open the file, but we do create any leading directories. This can be especially confusing when a command-line option overrides an in-stream one, in which case we'd create the leading directory for the in-stream file, even though we never actually write the file. Let's instead create the directories just before opening the file, which means we'll create only useful directories. Note that this could change the handling of relative paths if we chdir() in between, but we don't actually do so; the only permanent chdir is from setup_git_directory() which runs before either code path (potentially we should take the pre-setup dir into account to avoid surprising the user, but that's an orthogonal change). The test just adapts the existing "override" test to use paths with leading directories. This checks both that the correct directory is created (which worked before but was not tested), and that the overridden one is not (our new fix here). While we're here, let's also check the error result of safe_create_leading_directories(). We'd presumably notice any failure immediately after when we try to open the file itself, but we can give a more specific error message in this case. Signed-off-by: Jeff King <[email protected]>
1 parent e075dba commit 0196830

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

fast-import.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,12 @@ static void dump_marks(void)
18611861
if (!export_marks_file || (import_marks_file && !import_marks_file_done))
18621862
return;
18631863

1864+
if (safe_create_leading_directories_const(export_marks_file)) {
1865+
failure |= error_errno("unable to create leading directories of %s",
1866+
export_marks_file);
1867+
return;
1868+
}
1869+
18641870
if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
18651871
failure |= error_errno("Unable to write marks file %s",
18661872
export_marks_file);
@@ -3268,7 +3274,6 @@ static void option_active_branches(const char *branches)
32683274
static void option_export_marks(const char *marks)
32693275
{
32703276
export_marks_file = make_fast_import_path(marks);
3271-
safe_create_leading_directories_const(export_marks_file);
32723277
}
32733278

32743279
static void option_cat_blob_fd(const char *fd)

t/t9300-fast-import.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,8 +2132,17 @@ test_expect_success 'R: export-marks feature results in a marks file being creat
21322132
'
21332133

21342134
test_expect_success 'R: export-marks options can be overridden by commandline options' '
2135-
git fast-import --export-marks=other.marks <input &&
2136-
grep :1 other.marks
2135+
cat >input <<-\EOF &&
2136+
feature export-marks=feature-sub/git.marks
2137+
blob
2138+
mark :1
2139+
data 3
2140+
hi
2141+
2142+
EOF
2143+
git fast-import --export-marks=cmdline-sub/other.marks <input &&
2144+
grep :1 cmdline-sub/other.marks &&
2145+
test_path_is_missing feature-sub
21372146
'
21382147

21392148
test_expect_success 'R: catch typo in marks file name' '

0 commit comments

Comments
 (0)