@matheusbsbs / matheus-bagliano / commits / 081751c882
Fork 0

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 <srabbelier@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sverre Rabbelier committed Dec 4, 2009 at 18:06 UTC 081751c882f8398081b94335faa23912a655fb1c
3 files changed +45 -6
Documentation/git-fast-import.txt
+7 -1
@@ -867,7 +867,8 @@ it does not.
867 The <feature> part of the command may be any string matching
868 ^[a-zA-Z][a-zA-Z-]*$ and should be understood by fast-import.
869
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.
872
873 The following features are currently supported:
874
@@ -876,6 +877,11 @@ The following features are currently supported:
877 * export-marks
878 * force
879
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 +
885 `option`
886 ~~~~~~~~
887 Processes the specified option so that git fast-import behaves in a
fast-import.c
+16 -5
@@ -322,6 +322,7 @@ static struct object_entry *object_table[1 << 16];
322 static struct mark_set *marks;
323 static const char *export_marks_file;
324 static const char *import_marks_file;
325 +static int import_marks_file_from_stream;
326
327 /* Our last blob */
328 static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
@@ -2469,9 +2470,19 @@ static void parse_progress(void)
2470 skip_optional_lf();
2471 }
2472
2472 -static void option_import_marks(const char *marks)
2473 +static void option_import_marks(const char *marks, int from_stream)
2474 {
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 +
2484 import_marks_file = xstrdup(marks);
2485 + import_marks_file_from_stream = from_stream;
2486 }
2487
2488 static void option_date_format(const char *fmt)
@@ -2538,12 +2549,12 @@ static int parse_one_option(const char *option)
2549 return 1;
2550 }
2551
2541 -static int parse_one_feature(const char *feature)
2552 +static int parse_one_feature(const char *feature, int from_stream)
2553 {
2554 if (!prefixcmp(feature, "date-format=")) {
2555 option_date_format(feature + 12);
2556 } else if (!prefixcmp(feature, "import-marks=")) {
2546 - option_import_marks(feature + 13);
2557 + option_import_marks(feature + 13, from_stream);
2558 } else if (!prefixcmp(feature, "export-marks=")) {
2559 option_export_marks(feature + 13);
2560 } else if (!prefixcmp(feature, "force")) {
@@ -2562,7 +2573,7 @@ static void parse_feature(void)
2573 if (seen_data_command)
2574 die("Got feature command '%s' after data command", feature);
2575
2565 - if (parse_one_feature(feature))
2576 + if (parse_one_feature(feature, 1))
2577 return;
2578
2579 die("This version of fast-import does not support feature %s.", feature);
@@ -2618,7 +2629,7 @@ static void parse_argv(void)
2629 if (parse_one_option(a + 2))
2630 continue;
2631
2621 - if (parse_one_feature(a + 2))
2632 + if (parse_one_feature(a + 2, 0))
2633 continue;
2634
2635 die("unknown option %s", a);
t/t9300-fast-import.sh
+22
@@ -1285,6 +1285,15 @@ test_expect_success 'R: abort on receiving feature after data command' '
1285 test_must_fail git fast-import <input
1286 '
1287
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 +
1297 cat >input << EOF
1298 feature export-marks=git.marks
1299 blob
@@ -1324,6 +1333,19 @@ test_expect_success \
1333 'cat input | git fast-import --import-marks=marks.out &&
1334 test_cmp marks.out marks.new'
1335
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 +
1349 cat >input << EOF
1350 option git quiet
1351 blob