@@ -204,12 +204,12 @@ static void clean_tracked_sparse_directories(struct repository *r)
204
204
ensure_full_index (r -> index );
205
205
}
206
206
207
- static int update_working_directory (struct pattern_list * pl )
207
+ static int update_working_directory (struct repository * r ,
208
+ struct pattern_list * pl )
208
209
{
209
210
enum update_sparsity_result result ;
210
211
struct unpack_trees_options o ;
211
212
struct lock_file lock_file = LOCK_INIT ;
212
- struct repository * r = the_repository ;
213
213
struct pattern_list * old_pl ;
214
214
215
215
/* If no branch has been checked out, there are no updates to make. */
@@ -327,7 +327,8 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl)
327
327
string_list_clear (& sl , 0 );
328
328
}
329
329
330
- static int write_patterns_and_update (struct pattern_list * pl )
330
+ static int write_patterns_and_update (struct repository * repo ,
331
+ struct pattern_list * pl )
331
332
{
332
333
char * sparse_filename ;
333
334
FILE * fp ;
@@ -336,15 +337,15 @@ static int write_patterns_and_update(struct pattern_list *pl)
336
337
337
338
sparse_filename = get_sparse_checkout_filename ();
338
339
339
- if (safe_create_leading_directories (the_repository , sparse_filename ))
340
+ if (safe_create_leading_directories (repo , sparse_filename ))
340
341
die (_ ("failed to create directory for sparse-checkout file" ));
341
342
342
343
hold_lock_file_for_update (& lk , sparse_filename , LOCK_DIE_ON_ERROR );
343
344
344
- result = update_working_directory (pl );
345
+ result = update_working_directory (repo , pl );
345
346
if (result ) {
346
347
rollback_lock_file (& lk );
347
- update_working_directory (NULL );
348
+ update_working_directory (repo , NULL );
348
349
goto out ;
349
350
}
350
351
@@ -372,25 +373,26 @@ enum sparse_checkout_mode {
372
373
MODE_CONE_PATTERNS = 2 ,
373
374
};
374
375
375
- static int set_config (enum sparse_checkout_mode mode )
376
+ static int set_config (struct repository * repo ,
377
+ enum sparse_checkout_mode mode )
376
378
{
377
379
/* Update to use worktree config, if not already. */
378
- if (init_worktree_config (the_repository )) {
380
+ if (init_worktree_config (repo )) {
379
381
error (_ ("failed to initialize worktree config" ));
380
382
return 1 ;
381
383
}
382
384
383
- if (repo_config_set_worktree_gently (the_repository ,
385
+ if (repo_config_set_worktree_gently (repo ,
384
386
"core.sparseCheckout" ,
385
387
mode ? "true" : "false" ) ||
386
- repo_config_set_worktree_gently (the_repository ,
388
+ repo_config_set_worktree_gently (repo ,
387
389
"core.sparseCheckoutCone" ,
388
390
mode == MODE_CONE_PATTERNS ?
389
391
"true" : "false" ))
390
392
return 1 ;
391
393
392
394
if (mode == MODE_NO_PATTERNS )
393
- return set_sparse_index_config (the_repository , 0 );
395
+ return set_sparse_index_config (repo , 0 );
394
396
395
397
return 0 ;
396
398
}
@@ -410,28 +412,28 @@ static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
410
412
return MODE_ALL_PATTERNS ;
411
413
}
412
414
413
- static int update_modes (int * cone_mode , int * sparse_index )
415
+ static int update_modes (struct repository * repo , int * cone_mode , int * sparse_index )
414
416
{
415
417
int mode , record_mode ;
416
418
417
419
/* Determine if we need to record the mode; ensure sparse checkout on */
418
420
record_mode = (* cone_mode != -1 ) || !core_apply_sparse_checkout ;
419
421
420
422
mode = update_cone_mode (cone_mode );
421
- if (record_mode && set_config (mode ))
423
+ if (record_mode && set_config (repo , mode ))
422
424
return 1 ;
423
425
424
426
/* Set sparse-index/non-sparse-index mode if specified */
425
427
if (* sparse_index >= 0 ) {
426
- if (set_sparse_index_config (the_repository , * sparse_index ) < 0 )
428
+ if (set_sparse_index_config (repo , * sparse_index ) < 0 )
427
429
die (_ ("failed to modify sparse-index config" ));
428
430
429
431
/* force an index rewrite */
430
- repo_read_index (the_repository );
431
- the_repository -> index -> updated_workdir = 1 ;
432
+ repo_read_index (repo );
433
+ repo -> index -> updated_workdir = 1 ;
432
434
433
435
if (!* sparse_index )
434
- ensure_full_index (the_repository -> index );
436
+ ensure_full_index (repo -> index );
435
437
}
436
438
437
439
return 0 ;
@@ -448,7 +450,7 @@ static struct sparse_checkout_init_opts {
448
450
} init_opts ;
449
451
450
452
static int sparse_checkout_init (int argc , const char * * argv , const char * prefix ,
451
- struct repository * repo UNUSED )
453
+ struct repository * repo )
452
454
{
453
455
struct pattern_list pl ;
454
456
char * sparse_filename ;
@@ -464,7 +466,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
464
466
};
465
467
466
468
setup_work_tree ();
467
- repo_read_index (the_repository );
469
+ repo_read_index (repo );
468
470
469
471
init_opts .cone_mode = -1 ;
470
472
init_opts .sparse_index = -1 ;
@@ -473,7 +475,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
473
475
builtin_sparse_checkout_init_options ,
474
476
builtin_sparse_checkout_init_usage , 0 );
475
477
476
- if (update_modes (& init_opts .cone_mode , & init_opts .sparse_index ))
478
+ if (update_modes (repo , & init_opts .cone_mode , & init_opts .sparse_index ))
477
479
return 1 ;
478
480
479
481
memset (& pl , 0 , sizeof (pl ));
@@ -485,14 +487,14 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
485
487
if (res >= 0 ) {
486
488
free (sparse_filename );
487
489
clear_pattern_list (& pl );
488
- return update_working_directory (NULL );
490
+ return update_working_directory (repo , NULL );
489
491
}
490
492
491
- if (repo_get_oid (the_repository , "HEAD" , & oid )) {
493
+ if (repo_get_oid (repo , "HEAD" , & oid )) {
492
494
FILE * fp ;
493
495
494
496
/* assume we are in a fresh repo, but update the sparse-checkout file */
495
- if (safe_create_leading_directories (the_repository , sparse_filename ))
497
+ if (safe_create_leading_directories (repo , sparse_filename ))
496
498
die (_ ("unable to create leading directories of %s" ),
497
499
sparse_filename );
498
500
fp = xfopen (sparse_filename , "w" );
@@ -511,7 +513,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
511
513
add_pattern ("!/*/" , empty_base , 0 , & pl , 0 );
512
514
pl .use_cone_patterns = init_opts .cone_mode ;
513
515
514
- return write_patterns_and_update (& pl );
516
+ return write_patterns_and_update (repo , & pl );
515
517
}
516
518
517
519
static void insert_recursive_pattern (struct pattern_list * pl , struct strbuf * path )
@@ -674,7 +676,8 @@ static void add_patterns_literal(int argc, const char **argv,
674
676
add_patterns_from_input (pl , argc , argv , use_stdin ? stdin : NULL );
675
677
}
676
678
677
- static int modify_pattern_list (struct strvec * args , int use_stdin ,
679
+ static int modify_pattern_list (struct repository * repo ,
680
+ struct strvec * args , int use_stdin ,
678
681
enum modify_type m )
679
682
{
680
683
int result ;
@@ -696,22 +699,23 @@ static int modify_pattern_list(struct strvec *args, int use_stdin,
696
699
}
697
700
698
701
if (!core_apply_sparse_checkout ) {
699
- set_config (MODE_ALL_PATTERNS );
702
+ set_config (repo , MODE_ALL_PATTERNS );
700
703
core_apply_sparse_checkout = 1 ;
701
704
changed_config = 1 ;
702
705
}
703
706
704
- result = write_patterns_and_update (pl );
707
+ result = write_patterns_and_update (repo , pl );
705
708
706
709
if (result && changed_config )
707
- set_config (MODE_NO_PATTERNS );
710
+ set_config (repo , MODE_NO_PATTERNS );
708
711
709
712
clear_pattern_list (pl );
710
713
free (pl );
711
714
return result ;
712
715
}
713
716
714
- static void sanitize_paths (struct strvec * args ,
717
+ static void sanitize_paths (struct repository * repo ,
718
+ struct strvec * args ,
715
719
const char * prefix , int skip_checks )
716
720
{
717
721
int i ;
@@ -752,7 +756,7 @@ static void sanitize_paths(struct strvec *args,
752
756
753
757
for (i = 0 ; i < args -> nr ; i ++ ) {
754
758
struct cache_entry * ce ;
755
- struct index_state * index = the_repository -> index ;
759
+ struct index_state * index = repo -> index ;
756
760
int pos = index_name_pos (index , args -> v [i ], strlen (args -> v [i ]));
757
761
758
762
if (pos < 0 )
@@ -779,7 +783,7 @@ static struct sparse_checkout_add_opts {
779
783
} add_opts ;
780
784
781
785
static int sparse_checkout_add (int argc , const char * * argv , const char * prefix ,
782
- struct repository * repo UNUSED )
786
+ struct repository * repo )
783
787
{
784
788
static struct option builtin_sparse_checkout_add_options [] = {
785
789
OPT_BOOL_F (0 , "skip-checks" , & add_opts .skip_checks ,
@@ -796,17 +800,17 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
796
800
if (!core_apply_sparse_checkout )
797
801
die (_ ("no sparse-checkout to add to" ));
798
802
799
- repo_read_index (the_repository );
803
+ repo_read_index (repo );
800
804
801
805
argc = parse_options (argc , argv , prefix ,
802
806
builtin_sparse_checkout_add_options ,
803
807
builtin_sparse_checkout_add_usage , 0 );
804
808
805
809
for (int i = 0 ; i < argc ; i ++ )
806
810
strvec_push (& patterns , argv [i ]);
807
- sanitize_paths (& patterns , prefix , add_opts .skip_checks );
811
+ sanitize_paths (repo , & patterns , prefix , add_opts .skip_checks );
808
812
809
- ret = modify_pattern_list (& patterns , add_opts .use_stdin , ADD );
813
+ ret = modify_pattern_list (repo , & patterns , add_opts .use_stdin , ADD );
810
814
811
815
strvec_clear (& patterns );
812
816
return ret ;
@@ -825,7 +829,7 @@ static struct sparse_checkout_set_opts {
825
829
} set_opts ;
826
830
827
831
static int sparse_checkout_set (int argc , const char * * argv , const char * prefix ,
828
- struct repository * repo UNUSED )
832
+ struct repository * repo )
829
833
{
830
834
int default_patterns_nr = 2 ;
831
835
const char * default_patterns [] = {"/*" , "!/*/" , NULL };
@@ -847,7 +851,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
847
851
int ret ;
848
852
849
853
setup_work_tree ();
850
- repo_read_index (the_repository );
854
+ repo_read_index (repo );
851
855
852
856
set_opts .cone_mode = -1 ;
853
857
set_opts .sparse_index = -1 ;
@@ -856,7 +860,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
856
860
builtin_sparse_checkout_set_options ,
857
861
builtin_sparse_checkout_set_usage , 0 );
858
862
859
- if (update_modes (& set_opts .cone_mode , & set_opts .sparse_index ))
863
+ if (update_modes (repo , & set_opts .cone_mode , & set_opts .sparse_index ))
860
864
return 1 ;
861
865
862
866
/*
@@ -870,10 +874,10 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
870
874
} else {
871
875
for (int i = 0 ; i < argc ; i ++ )
872
876
strvec_push (& patterns , argv [i ]);
873
- sanitize_paths (& patterns , prefix , set_opts .skip_checks );
877
+ sanitize_paths (repo , & patterns , prefix , set_opts .skip_checks );
874
878
}
875
879
876
- ret = modify_pattern_list (& patterns , set_opts .use_stdin , REPLACE );
880
+ ret = modify_pattern_list (repo , & patterns , set_opts .use_stdin , REPLACE );
877
881
878
882
strvec_clear (& patterns );
879
883
return ret ;
@@ -891,7 +895,7 @@ static struct sparse_checkout_reapply_opts {
891
895
892
896
static int sparse_checkout_reapply (int argc , const char * * argv ,
893
897
const char * prefix ,
894
- struct repository * repo UNUSED )
898
+ struct repository * repo )
895
899
{
896
900
static struct option builtin_sparse_checkout_reapply_options [] = {
897
901
OPT_BOOL (0 , "cone" , & reapply_opts .cone_mode ,
@@ -912,12 +916,12 @@ static int sparse_checkout_reapply(int argc, const char **argv,
912
916
builtin_sparse_checkout_reapply_options ,
913
917
builtin_sparse_checkout_reapply_usage , 0 );
914
918
915
- repo_read_index (the_repository );
919
+ repo_read_index (repo );
916
920
917
- if (update_modes (& reapply_opts .cone_mode , & reapply_opts .sparse_index ))
921
+ if (update_modes (repo , & reapply_opts .cone_mode , & reapply_opts .sparse_index ))
918
922
return 1 ;
919
923
920
- return update_working_directory (NULL );
924
+ return update_working_directory (repo , NULL );
921
925
}
922
926
923
927
static char const * const builtin_sparse_checkout_disable_usage [] = {
@@ -927,7 +931,7 @@ static char const * const builtin_sparse_checkout_disable_usage[] = {
927
931
928
932
static int sparse_checkout_disable (int argc , const char * * argv ,
929
933
const char * prefix ,
930
- struct repository * repo UNUSED )
934
+ struct repository * repo )
931
935
{
932
936
static struct option builtin_sparse_checkout_disable_options [] = {
933
937
OPT_END (),
@@ -955,7 +959,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
955
959
* are expecting to do that when disabling sparse-checkout.
956
960
*/
957
961
give_advice_on_expansion = 0 ;
958
- repo_read_index (the_repository );
962
+ repo_read_index (repo );
959
963
960
964
memset (& pl , 0 , sizeof (pl ));
961
965
hashmap_init (& pl .recursive_hashmap , pl_hashmap_cmp , NULL , 0 );
@@ -966,13 +970,13 @@ static int sparse_checkout_disable(int argc, const char **argv,
966
970
add_pattern ("/*" , empty_base , 0 , & pl , 0 );
967
971
968
972
prepare_repo_settings (the_repository );
969
- the_repository -> settings .sparse_index = 0 ;
973
+ repo -> settings .sparse_index = 0 ;
970
974
971
- if (update_working_directory (& pl ))
975
+ if (update_working_directory (repo , & pl ))
972
976
die (_ ("error while refreshing working directory" ));
973
977
974
978
clear_pattern_list (& pl );
975
- return set_config (MODE_NO_PATTERNS );
979
+ return set_config (repo , MODE_NO_PATTERNS );
976
980
}
977
981
978
982
static char const * const builtin_sparse_checkout_check_rules_usage [] = {
@@ -987,14 +991,17 @@ static struct sparse_checkout_check_rules_opts {
987
991
char * rules_file ;
988
992
} check_rules_opts ;
989
993
990
- static int check_rules (struct pattern_list * pl , int null_terminated ) {
994
+ static int check_rules (struct repository * repo ,
995
+ struct pattern_list * pl ,
996
+ int null_terminated )
997
+ {
991
998
struct strbuf line = STRBUF_INIT ;
992
999
struct strbuf unquoted = STRBUF_INIT ;
993
1000
char * path ;
994
1001
int line_terminator = null_terminated ? 0 : '\n' ;
995
1002
strbuf_getline_fn getline_fn = null_terminated ? strbuf_getline_nul
996
1003
: strbuf_getline ;
997
- the_repository -> index -> sparse_checkout_patterns = pl ;
1004
+ repo -> index -> sparse_checkout_patterns = pl ;
998
1005
while (!getline_fn (& line , stdin )) {
999
1006
path = line .buf ;
1000
1007
if (!null_terminated && line .buf [0 ] == '"' ) {
@@ -1006,7 +1013,7 @@ static int check_rules(struct pattern_list *pl, int null_terminated) {
1006
1013
path = unquoted .buf ;
1007
1014
}
1008
1015
1009
- if (path_in_sparse_checkout (path , the_repository -> index ))
1016
+ if (path_in_sparse_checkout (path , repo -> index ))
1010
1017
write_name_quoted (path , stdout , line_terminator );
1011
1018
}
1012
1019
strbuf_release (& line );
@@ -1016,7 +1023,7 @@ static int check_rules(struct pattern_list *pl, int null_terminated) {
1016
1023
}
1017
1024
1018
1025
static int sparse_checkout_check_rules (int argc , const char * * argv , const char * prefix ,
1019
- struct repository * repo UNUSED )
1026
+ struct repository * repo )
1020
1027
{
1021
1028
static struct option builtin_sparse_checkout_check_rules_options [] = {
1022
1029
OPT_BOOL ('z' , NULL , & check_rules_opts .null_termination ,
@@ -1055,7 +1062,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
1055
1062
free (sparse_filename );
1056
1063
}
1057
1064
1058
- ret = check_rules (& pl , check_rules_opts .null_termination );
1065
+ ret = check_rules (repo , & pl , check_rules_opts .null_termination );
1059
1066
clear_pattern_list (& pl );
1060
1067
free (check_rules_opts .rules_file );
1061
1068
return ret ;
@@ -1084,8 +1091,8 @@ int cmd_sparse_checkout(int argc,
1084
1091
1085
1092
repo_config (the_repository , git_default_config , NULL );
1086
1093
1087
- prepare_repo_settings (the_repository );
1088
- the_repository -> settings .command_requires_full_index = 0 ;
1094
+ prepare_repo_settings (repo );
1095
+ repo -> settings .command_requires_full_index = 0 ;
1089
1096
1090
1097
return fn (argc , argv , prefix , repo );
1091
1098
}
0 commit comments