Skip to content

Commit 081751c

Browse files
SRabbeliergitster
authored andcommitted
fast-import: allow for multiple --import-marks= arguments
The --import-marks= option may be specified multiple times on the commandline and should result in all marks being read in. Only one import-marks feature may be specified in the stream, which is overriden by any --import-marks= commandline options. If one wishes to specify import-marks files in addition to the one specified in the stream, it is easy to repeat the stream option as a --import-marks= commandline option. Also verify this behavior with tests. Signed-off-by: Sverre Rabbelier <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2792f26 commit 081751c

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

Documentation/git-fast-import.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ it does not.
867867
The <feature> part of the command may be any string matching
868868
^[a-zA-Z][a-zA-Z-]*$ and should be understood by fast-import.
869869

870-
Feature work identical as their option counterparts.
870+
Feature work identical as their option counterparts with the
871+
exception of the import-marks feature, see below.
871872

872873
The following features are currently supported:
873874

@@ -876,6 +877,11 @@ The following features are currently supported:
876877
* export-marks
877878
* force
878879

880+
The import-marks behaves differently from when it is specified as
881+
commandline option in that only one "feature import-marks" is allowed
882+
per stream. Also, any --import-marks= specified on the commandline
883+
will override those from the stream (if any).
884+
879885
`option`
880886
~~~~~~~~
881887
Processes the specified option so that git fast-import behaves in a

fast-import.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ static struct object_entry *object_table[1 << 16];
322322
static struct mark_set *marks;
323323
static const char *export_marks_file;
324324
static const char *import_marks_file;
325+
static int import_marks_file_from_stream;
325326

326327
/* Our last blob */
327328
static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
@@ -2469,9 +2470,19 @@ static void parse_progress(void)
24692470
skip_optional_lf();
24702471
}
24712472

2472-
static void option_import_marks(const char *marks)
2473+
static void option_import_marks(const char *marks, int from_stream)
24732474
{
2475+
if (import_marks_file) {
2476+
if (from_stream)
2477+
die("Only one import-marks command allowed per stream");
2478+
2479+
/* read previous mark file */
2480+
if(!import_marks_file_from_stream)
2481+
read_marks();
2482+
}
2483+
24742484
import_marks_file = xstrdup(marks);
2485+
import_marks_file_from_stream = from_stream;
24752486
}
24762487

24772488
static void option_date_format(const char *fmt)
@@ -2538,12 +2549,12 @@ static int parse_one_option(const char *option)
25382549
return 1;
25392550
}
25402551

2541-
static int parse_one_feature(const char *feature)
2552+
static int parse_one_feature(const char *feature, int from_stream)
25422553
{
25432554
if (!prefixcmp(feature, "date-format=")) {
25442555
option_date_format(feature + 12);
25452556
} else if (!prefixcmp(feature, "import-marks=")) {
2546-
option_import_marks(feature + 13);
2557+
option_import_marks(feature + 13, from_stream);
25472558
} else if (!prefixcmp(feature, "export-marks=")) {
25482559
option_export_marks(feature + 13);
25492560
} else if (!prefixcmp(feature, "force")) {
@@ -2562,7 +2573,7 @@ static void parse_feature(void)
25622573
if (seen_data_command)
25632574
die("Got feature command '%s' after data command", feature);
25642575

2565-
if (parse_one_feature(feature))
2576+
if (parse_one_feature(feature, 1))
25662577
return;
25672578

25682579
die("This version of fast-import does not support feature %s.", feature);
@@ -2618,7 +2629,7 @@ static void parse_argv(void)
26182629
if (parse_one_option(a + 2))
26192630
continue;
26202631

2621-
if (parse_one_feature(a + 2))
2632+
if (parse_one_feature(a + 2, 0))
26222633
continue;
26232634

26242635
die("unknown option %s", a);

t/t9300-fast-import.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,15 @@ test_expect_success 'R: abort on receiving feature after data command' '
12851285
test_must_fail git fast-import <input
12861286
'
12871287

1288+
cat >input << EOF
1289+
feature import-marks=git.marks
1290+
feature import-marks=git2.marks
1291+
EOF
1292+
1293+
test_expect_success 'R: only one import-marks feature allowed per stream' '
1294+
test_must_fail git fast-import <input
1295+
'
1296+
12881297
cat >input << EOF
12891298
feature export-marks=git.marks
12901299
blob
@@ -1324,6 +1333,19 @@ test_expect_success \
13241333
'cat input | git fast-import --import-marks=marks.out &&
13251334
test_cmp marks.out marks.new'
13261335

1336+
1337+
cat >input <<EOF
1338+
feature import-marks=nonexistant.marks
1339+
feature export-marks=combined.marks
1340+
EOF
1341+
1342+
test_expect_success 'R: multiple --import-marks= should be honoured' '
1343+
head -n2 marks.out > one.marks &&
1344+
tail -n +3 marks.out > two.marks &&
1345+
git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
1346+
test_cmp marks.out combined.marks
1347+
'
1348+
13271349
cat >input << EOF
13281350
option git quiet
13291351
blob

0 commit comments

Comments
 (0)