@@ -296,6 +296,8 @@ static unsigned long branch_load_count;
296
296
static int failure ;
297
297
static FILE * pack_edges ;
298
298
static unsigned int show_stats = 1 ;
299
+ static int global_argc ;
300
+ static const char * * global_argv ;
299
301
300
302
/* Memory pools */
301
303
static size_t mem_pool_alloc = 2 * 1024 * 1024 - sizeof (struct mem_pool );
@@ -355,6 +357,8 @@ static uintmax_t next_mark;
355
357
static struct strbuf new_data = STRBUF_INIT ;
356
358
static int seen_data_command ;
357
359
360
+ static void parse_argv (void );
361
+
358
362
static void write_branch_report (FILE * rpt , struct branch * b )
359
363
{
360
364
fprintf (rpt , "%s:\n" , b -> name );
@@ -1706,8 +1710,9 @@ static int read_next_command(void)
1706
1710
return EOF ;
1707
1711
1708
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 ();
1711
1716
}
1712
1717
1713
1718
rc = rc_free ;
@@ -2512,31 +2517,25 @@ static void option_export_pack_edges(const char *edges)
2512
2517
die_errno ("Cannot open '%s'" , edges );
2513
2518
}
2514
2519
2515
- static void parse_one_option (const char * option )
2520
+ static int parse_one_option (const char * option )
2516
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=" )) {
2520
2523
option_max_pack_size (option + 14 );
2521
2524
} else if (!prefixcmp (option , "depth=" )) {
2522
2525
option_depth (option + 6 );
2523
2526
} else if (!prefixcmp (option , "active-branches=" )) {
2524
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 );
2529
2528
} else if (!prefixcmp (option , "export-pack-edges=" )) {
2530
2529
option_export_pack_edges (option + 18 );
2531
- } else if (!prefixcmp (option , "force" )) {
2532
- force_update = 1 ;
2533
2530
} else if (!prefixcmp (option , "quiet" )) {
2534
2531
show_stats = 0 ;
2535
2532
} else if (!prefixcmp (option , "stats" )) {
2536
2533
show_stats = 1 ;
2537
2534
} else {
2538
- die ( "Unsupported option: %s" , option ) ;
2535
+ return 0 ;
2539
2536
}
2537
+
2538
+ return 1 ;
2540
2539
}
2541
2540
2542
2541
static int parse_one_feature (const char * feature )
@@ -2569,6 +2568,19 @@ static void parse_feature(void)
2569
2568
die ("This version of fast-import does not support feature %s." , feature );
2570
2569
}
2571
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
+
2572
2584
static int git_pack_config (const char * k , const char * v , void * cb )
2573
2585
{
2574
2586
if (!strcmp (k , "pack.depth" )) {
@@ -2593,6 +2605,32 @@ static int git_pack_config(const char *k, const char *v, void *cb)
2593
2605
static const char fast_import_usage [] =
2594
2606
"git fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]" ;
2595
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
+
2596
2634
int main (int argc , const char * * argv )
2597
2635
{
2598
2636
unsigned int i ;
@@ -2614,18 +2652,8 @@ int main(int argc, const char **argv)
2614
2652
avail_tree_table = xcalloc (avail_tree_table_sz , sizeof (struct avail_tree_content * ));
2615
2653
marks = pool_calloc (1 , sizeof (struct mark_set ));
2616
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 ;
2629
2657
2630
2658
rc_free = pool_alloc (cmd_save * sizeof (* rc_free ));
2631
2659
for (i = 0 ; i < (cmd_save - 1 ); i ++ )
@@ -2650,9 +2678,18 @@ int main(int argc, const char **argv)
2650
2678
parse_progress ();
2651
2679
else if (!prefixcmp (command_buf .buf , "feature " ))
2652
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*/ ;
2653
2685
else
2654
2686
die ("Unsupported command: %s" , command_buf .buf );
2655
2687
}
2688
+
2689
+ /* argv hasn't been parsed yet, do so */
2690
+ if (!seen_data_command )
2691
+ parse_argv ();
2692
+
2656
2693
end_packfile ();
2657
2694
2658
2695
dump_branches ();
0 commit comments