Skip to content

Commit 208d692

Browse files
newrengitster
authored andcommitted
fast-export: add support for --import-marks-if-exists
fast-import has support for both an --import-marks flag and an --import-marks-if-exists flag; the latter of which will not die() if the file does not exist. fast-export only had support for an --import-marks flag; add an --import-marks-if-exists flag for consistency. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b8f50e5 commit 208d692

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

builtin/fast-export.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,11 +1052,16 @@ static void export_marks(char *file)
10521052
error("Unable to write marks file %s.", file);
10531053
}
10541054

1055-
static void import_marks(char *input_file)
1055+
static void import_marks(char *input_file, int check_exists)
10561056
{
10571057
char line[512];
1058-
FILE *f = xfopen(input_file, "r");
1058+
FILE *f;
1059+
struct stat sb;
1060+
1061+
if (check_exists && stat(input_file, &sb))
1062+
return;
10591063

1064+
f = xfopen(input_file, "r");
10601065
while (fgets(line, sizeof(line), f)) {
10611066
uint32_t mark;
10621067
char *line_end, *mark_end;
@@ -1120,7 +1125,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
11201125
struct rev_info revs;
11211126
struct object_array commits = OBJECT_ARRAY_INIT;
11221127
struct commit *commit;
1123-
char *export_filename = NULL, *import_filename = NULL;
1128+
char *export_filename = NULL,
1129+
*import_filename = NULL,
1130+
*import_filename_if_exists = NULL;
11241131
uint32_t lastimportid;
11251132
struct string_list refspecs_list = STRING_LIST_INIT_NODUP;
11261133
struct string_list paths_of_changed_objects = STRING_LIST_INIT_DUP;
@@ -1140,6 +1147,10 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
11401147
N_("Dump marks to this file")),
11411148
OPT_STRING(0, "import-marks", &import_filename, N_("file"),
11421149
N_("Import marks from this file")),
1150+
OPT_STRING(0, "import-marks-if-exists",
1151+
&import_filename_if_exists,
1152+
N_("file"),
1153+
N_("Import marks from this file if it exists")),
11431154
OPT_BOOL(0, "fake-missing-tagger", &fake_missing_tagger,
11441155
N_("Fake a tagger when tags lack one")),
11451156
OPT_BOOL(0, "full-tree", &full_tree,
@@ -1187,8 +1198,12 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
11871198
if (use_done_feature)
11881199
printf("feature done\n");
11891200

1201+
if (import_filename && import_filename_if_exists)
1202+
die(_("Cannot pass both --import-marks and --import-marks-if-exists"));
11901203
if (import_filename)
1191-
import_marks(import_filename);
1204+
import_marks(import_filename, 0);
1205+
else if (import_filename_if_exists)
1206+
import_marks(import_filename_if_exists, 1);
11921207
lastimportid = last_idnum;
11931208

11941209
if (import_filename && revs.prune_data.nr)

t/t9350-fast-export.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,17 +580,15 @@ test_expect_success 'fast-export quotes pathnames' '
580580
'
581581

582582
test_expect_success 'test bidirectionality' '
583-
>marks-cur &&
584-
>marks-new &&
585583
git init marks-test &&
586-
git fast-export --export-marks=marks-cur --import-marks=marks-cur --branches | \
587-
git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks=marks-new &&
584+
git fast-export --export-marks=marks-cur --import-marks-if-exists=marks-cur --branches | \
585+
git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks-if-exists=marks-new &&
588586
(cd marks-test &&
589587
git reset --hard &&
590588
echo Wohlauf > file &&
591589
git commit -a -m "back in time") &&
592-
git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks=marks-new --branches | \
593-
git fast-import --export-marks=marks-cur --import-marks=marks-cur
590+
git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks-if-exists=marks-new --branches | \
591+
git fast-import --export-marks=marks-cur --import-marks-if-exists=marks-cur
594592
'
595593

596594
cat > expected << EOF

0 commit comments

Comments
 (0)