@@ -412,36 +412,16 @@ static struct sparse_checkout_set_opts {
412
412
int use_stdin ;
413
413
} set_opts ;
414
414
415
- static int sparse_checkout_set (int argc , const char * * argv , const char * prefix )
415
+ static void add_patterns_from_input (struct pattern_list * pl ,
416
+ int argc , const char * * argv )
416
417
{
417
418
int i ;
418
- struct pattern_list pl ;
419
- int result ;
420
- int changed_config = 0 ;
421
-
422
- static struct option builtin_sparse_checkout_set_options [] = {
423
- OPT_BOOL (0 , "stdin" , & set_opts .use_stdin ,
424
- N_ ("read patterns from standard in" )),
425
- OPT_END (),
426
- };
427
-
428
- repo_read_index (the_repository );
429
- require_clean_work_tree (the_repository ,
430
- N_ ("set sparse-checkout patterns" ), NULL , 1 , 0 );
431
-
432
- memset (& pl , 0 , sizeof (pl ));
433
-
434
- argc = parse_options (argc , argv , prefix ,
435
- builtin_sparse_checkout_set_options ,
436
- builtin_sparse_checkout_set_usage ,
437
- PARSE_OPT_KEEP_UNKNOWN );
438
-
439
419
if (core_sparse_checkout_cone ) {
440
420
struct strbuf line = STRBUF_INIT ;
441
421
442
- hashmap_init (& pl . recursive_hashmap , pl_hashmap_cmp , NULL , 0 );
443
- hashmap_init (& pl . parent_hashmap , pl_hashmap_cmp , NULL , 0 );
444
- pl . use_cone_patterns = 1 ;
422
+ hashmap_init (& pl -> recursive_hashmap , pl_hashmap_cmp , NULL , 0 );
423
+ hashmap_init (& pl -> parent_hashmap , pl_hashmap_cmp , NULL , 0 );
424
+ pl -> use_cone_patterns = 1 ;
445
425
446
426
if (set_opts .use_stdin ) {
447
427
struct strbuf unquoted = STRBUF_INIT ;
@@ -455,15 +435,15 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
455
435
strbuf_swap (& unquoted , & line );
456
436
}
457
437
458
- strbuf_to_cone_pattern (& line , & pl );
438
+ strbuf_to_cone_pattern (& line , pl );
459
439
}
460
440
461
441
strbuf_release (& unquoted );
462
442
} else {
463
443
for (i = 0 ; i < argc ; i ++ ) {
464
444
strbuf_setlen (& line , 0 );
465
445
strbuf_addstr (& line , argv [i ]);
466
- strbuf_to_cone_pattern (& line , & pl );
446
+ strbuf_to_cone_pattern (& line , pl );
467
447
}
468
448
}
469
449
} else {
@@ -473,13 +453,39 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
473
453
while (!strbuf_getline (& line , stdin )) {
474
454
size_t len ;
475
455
char * buf = strbuf_detach (& line , & len );
476
- add_pattern (buf , empty_base , 0 , & pl , 0 );
456
+ add_pattern (buf , empty_base , 0 , pl , 0 );
477
457
}
478
458
} else {
479
459
for (i = 0 ; i < argc ; i ++ )
480
- add_pattern (argv [i ], empty_base , 0 , & pl , 0 );
460
+ add_pattern (argv [i ], empty_base , 0 , pl , 0 );
481
461
}
482
462
}
463
+ }
464
+
465
+ static int sparse_checkout_set (int argc , const char * * argv , const char * prefix )
466
+ {
467
+ struct pattern_list pl ;
468
+ int result ;
469
+ int changed_config = 0 ;
470
+
471
+ static struct option builtin_sparse_checkout_set_options [] = {
472
+ OPT_BOOL (0 , "stdin" , & set_opts .use_stdin ,
473
+ N_ ("read patterns from standard in" )),
474
+ OPT_END (),
475
+ };
476
+
477
+ repo_read_index (the_repository );
478
+ require_clean_work_tree (the_repository ,
479
+ N_ ("set sparse-checkout patterns" ), NULL , 1 , 0 );
480
+
481
+ memset (& pl , 0 , sizeof (pl ));
482
+
483
+ argc = parse_options (argc , argv , prefix ,
484
+ builtin_sparse_checkout_set_options ,
485
+ builtin_sparse_checkout_set_usage ,
486
+ PARSE_OPT_KEEP_UNKNOWN );
487
+
488
+ add_patterns_from_input (& pl , argc , argv );
483
489
484
490
if (!core_apply_sparse_checkout ) {
485
491
set_config (MODE_ALL_PATTERNS );
0 commit comments