@matheusbsbs / matheus-bagliano / commits / 9c8398f0c9
Fork 0

fast-import: add option command

This allows the frontend to specify any of the supported options as long as no non-option command has been given. This way the user does not have to include any frontend-specific options, but instead she can rely on the frontend to tell fast-import what it needs. Also factor out parsing of argv and have it execute when we reach the first non-option command, or after all commands have been read and no non-option command has been encountered. Non-git options are ignored, unrecognised options result in an error. 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 9c8398f0c9d1fc92df5c1a7a52c810294d8ac3f8
2 files changed +94 -25
Documentation/git-fast-import.txt
+32
@@ -307,6 +307,11 @@ and control the current import process. More detailed discussion
307 Require that fast-import supports the specified feature, or
308 abort if it does not.
309
310 +`option`::
311 + Specify any of the options listed under OPTIONS that do not
312 + change stream semantic to suit the frontend's needs. This
313 + command is optional and is not needed to perform an import.
314 +
315 `commit`
316 ~~~~~~~~
317 Create or update a branch with a new commit, recording one logical
@@ -871,6 +876,33 @@ The following features are currently supported:
876 * export-marks
877 * force
878
879 +`option`
880 +~~~~~~~~
881 +Processes the specified option so that git fast-import behaves in a
882 +way that suits the frontend's needs.
883 +Note that options specified by the frontend are overridden by any
884 +options the user may specify to git fast-import itself.
885 +
886 +....
887 + 'option' SP <option> LF
888 +....
889 +
890 +The `<option>` part of the command may contain any of the options
891 +listed in the OPTIONS section that do not change import semantics,
892 +without the leading '--' and is treated in the same way.
893 +
894 +Option commands must be the first commands on the input (not counting
895 +feature commands), to give an option command after any non-option
896 +command is an error.
897 +
898 +The following commandline options change import semantics and may therefore
899 +not be passed as option:
900 +
901 +* date-format
902 +* import-marks
903 +* export-marks
904 +* force
905 +
906 Crash Reports
907 -------------
908 If fast-import is supplied invalid input it will terminate with a
fast-import.c
+62 -25
@@ -296,6 +296,8 @@ static unsigned long branch_load_count;
296 static int failure;
297 static FILE *pack_edges;
298 static unsigned int show_stats = 1;
299 +static int global_argc;
300 +static const char **global_argv;
301
302 /* Memory pools */
303 static size_t mem_pool_alloc = 2*1024*1024 - sizeof(struct mem_pool);
@@ -355,6 +357,8 @@ static uintmax_t next_mark;
357 static struct strbuf new_data = STRBUF_INIT;
358 static int seen_data_command;
359
360 +static void parse_argv(void);
361 +
362 static void write_branch_report(FILE *rpt, struct branch *b)
363 {
364 fprintf(rpt, "%s:\n", b->name);
@@ -1706,8 +1710,9 @@ static int read_next_command(void)
1710 return EOF;
1711
1712 if (!seen_data_command
1709 - && prefixcmp(command_buf.buf, "feature ")) {
1710 - seen_data_command = 1;
1713 + && prefixcmp(command_buf.buf, "feature ")
1714 + && prefixcmp(command_buf.buf, "option ")) {
1715 + parse_argv();
1716 }
1717
1718 rc = rc_free;
@@ -2512,31 +2517,25 @@ static void option_export_pack_edges(const char *edges)
2517 die_errno("Cannot open '%s'", edges);
2518 }
2519
2515 -static void parse_one_option(const char *option)
2520 +static int parse_one_option(const char *option)
2521 {
2517 - if (!prefixcmp(option, "date-format=")) {
2518 - option_date_format(option + 12);
2519 - } else if (!prefixcmp(option, "max-pack-size=")) {
2522 + if (!prefixcmp(option, "max-pack-size=")) {
2523 option_max_pack_size(option + 14);
2524 } else if (!prefixcmp(option, "depth=")) {
2525 option_depth(option + 6);
2526 } else if (!prefixcmp(option, "active-branches=")) {
2527 option_active_branches(option + 16);
2525 - } else if (!prefixcmp(option, "import-marks=")) {
2526 - option_import_marks(option + 13);
2527 - } else if (!prefixcmp(option, "export-marks=")) {
2528 - option_export_marks(option + 13);
2528 } else if (!prefixcmp(option, "export-pack-edges=")) {
2529 option_export_pack_edges(option + 18);
2531 - } else if (!prefixcmp(option, "force")) {
2532 - force_update = 1;
2530 } else if (!prefixcmp(option, "quiet")) {
2531 show_stats = 0;
2532 } else if (!prefixcmp(option, "stats")) {
2533 show_stats = 1;
2534 } else {
2538 - die("Unsupported option: %s", option);
2535 + return 0;
2536 }
2537 +
2538 + return 1;
2539 }
2540
2541 static int parse_one_feature(const char *feature)
@@ -2569,6 +2568,19 @@ static void parse_feature(void)
2568 die("This version of fast-import does not support feature %s.", feature);
2569 }
2570
2571 +static void parse_option(void)
2572 +{
2573 + char *option = command_buf.buf + 11;
2574 +
2575 + if (seen_data_command)
2576 + die("Got option command '%s' after data command", option);
2577 +
2578 + if (parse_one_option(option))
2579 + return;
2580 +
2581 + die("This version of fast-import does not support option: %s", option);
2582 +}
2583 +
2584 static int git_pack_config(const char *k, const char *v, void *cb)
2585 {
2586 if (!strcmp(k, "pack.depth")) {
@@ -2593,6 +2605,32 @@ static int git_pack_config(const char *k, const char *v, void *cb)
2605 static const char fast_import_usage[] =
2606 "git fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
2607
2608 +static void parse_argv(void)
2609 +{
2610 + unsigned int i;
2611 +
2612 + for (i = 1; i < global_argc; i++) {
2613 + const char *a = global_argv[i];
2614 +
2615 + if (*a != '-' || !strcmp(a, "--"))
2616 + break;
2617 +
2618 + if (parse_one_option(a + 2))
2619 + continue;
2620 +
2621 + if (parse_one_feature(a + 2))
2622 + continue;
2623 +
2624 + die("unknown option %s", a);
2625 + }
2626 + if (i != global_argc)
2627 + usage(fast_import_usage);
2628 +
2629 + seen_data_command = 1;
2630 + if (import_marks_file)
2631 + read_marks();
2632 +}
2633 +
2634 int main(int argc, const char **argv)
2635 {
2636 unsigned int i;
@@ -2614,18 +2652,8 @@ int main(int argc, const char **argv)
2652 avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
2653 marks = pool_calloc(1, sizeof(struct mark_set));
2654
2617 - for (i = 1; i < argc; i++) {
2618 - const char *a = argv[i];
2619 -
2620 - if (*a != '-' || !strcmp(a, "--"))
2621 - break;
2622 -
2623 - parse_one_option(a + 2);
2624 - }
2625 - if (i != argc)
2626 - usage(fast_import_usage);
2627 - if (import_marks_file)
2628 - read_marks();
2655 + global_argc = argc;
2656 + global_argv = argv;
2657
2658 rc_free = pool_alloc(cmd_save * sizeof(*rc_free));
2659 for (i = 0; i < (cmd_save - 1); i++)
@@ -2650,9 +2678,18 @@ int main(int argc, const char **argv)
2678 parse_progress();
2679 else if (!prefixcmp(command_buf.buf, "feature "))
2680 parse_feature();
2681 + else if (!prefixcmp(command_buf.buf, "option git "))
2682 + parse_option();
2683 + else if (!prefixcmp(command_buf.buf, "option "))
2684 + /* ignore non-git options*/;
2685 else
2686 die("Unsupported command: %s", command_buf.buf);
2687 }
2688 +
2689 + /* argv hasn't been parsed yet, do so */
2690 + if (!seen_data_command)
2691 + parse_argv();
2692 +
2693 end_packfile();
2694
2695 dump_branches();