@@ -212,12 +212,12 @@ static void clean_tracked_sparse_directories(struct repository *r)
212
212
"sparse-checkout:was full" );
213
213
}
214
214
215
- static int update_working_directory (struct pattern_list * pl )
215
+ static int update_working_directory (struct repository * r ,
216
+ struct pattern_list * pl )
216
217
{
217
218
enum update_sparsity_result result ;
218
219
struct unpack_trees_options o ;
219
220
struct lock_file lock_file = LOCK_INIT ;
220
- struct repository * r = the_repository ;
221
221
struct pattern_list * old_pl ;
222
222
223
223
/* If no branch has been checked out, there are no updates to make. */
@@ -335,7 +335,8 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl)
335
335
string_list_clear (& sl , 0 );
336
336
}
337
337
338
- static int write_patterns_and_update (struct pattern_list * pl )
338
+ static int write_patterns_and_update (struct repository * repo ,
339
+ struct pattern_list * pl )
339
340
{
340
341
char * sparse_filename ;
341
342
FILE * fp ;
@@ -344,15 +345,15 @@ static int write_patterns_and_update(struct pattern_list *pl)
344
345
345
346
sparse_filename = get_sparse_checkout_filename ();
346
347
347
- if (safe_create_leading_directories (the_repository , sparse_filename ))
348
+ if (safe_create_leading_directories (repo , sparse_filename ))
348
349
die (_ ("failed to create directory for sparse-checkout file" ));
349
350
350
351
hold_lock_file_for_update (& lk , sparse_filename , LOCK_DIE_ON_ERROR );
351
352
352
- result = update_working_directory (pl );
353
+ result = update_working_directory (repo , pl );
353
354
if (result ) {
354
355
rollback_lock_file (& lk );
355
- update_working_directory (NULL );
356
+ update_working_directory (repo , NULL );
356
357
goto out ;
357
358
}
358
359
@@ -380,25 +381,26 @@ enum sparse_checkout_mode {
380
381
MODE_CONE_PATTERNS = 2 ,
381
382
};
382
383
383
- static int set_config (enum sparse_checkout_mode mode )
384
+ static int set_config (struct repository * repo ,
385
+ enum sparse_checkout_mode mode )
384
386
{
385
387
/* Update to use worktree config, if not already. */
386
- if (init_worktree_config (the_repository )) {
388
+ if (init_worktree_config (repo )) {
387
389
error (_ ("failed to initialize worktree config" ));
388
390
return 1 ;
389
391
}
390
392
391
- if (repo_config_set_worktree_gently (the_repository ,
393
+ if (repo_config_set_worktree_gently (repo ,
392
394
"core.sparseCheckout" ,
393
395
mode ? "true" : "false" ) ||
394
- repo_config_set_worktree_gently (the_repository ,
396
+ repo_config_set_worktree_gently (repo ,
395
397
"core.sparseCheckoutCone" ,
396
398
mode == MODE_CONE_PATTERNS ?
397
399
"true" : "false" ))
398
400
return 1 ;
399
401
400
402
if (mode == MODE_NO_PATTERNS )
401
- return set_sparse_index_config (the_repository , 0 );
403
+ return set_sparse_index_config (repo , 0 );
402
404
403
405
return 0 ;
404
406
}
@@ -418,28 +420,28 @@ static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
418
420
return MODE_ALL_PATTERNS ;
419
421
}
420
422
421
- static int update_modes (int * cone_mode , int * sparse_index )
423
+ static int update_modes (struct repository * repo , int * cone_mode , int * sparse_index )
422
424
{
423
425
int mode , record_mode ;
424
426
425
427
/* Determine if we need to record the mode; ensure sparse checkout on */
426
428
record_mode = (* cone_mode != -1 ) || !core_apply_sparse_checkout ;
427
429
428
430
mode = update_cone_mode (cone_mode );
429
- if (record_mode && set_config (mode ))
431
+ if (record_mode && set_config (repo , mode ))
430
432
return 1 ;
431
433
432
434
/* Set sparse-index/non-sparse-index mode if specified */
433
435
if (* sparse_index >= 0 ) {
434
- if (set_sparse_index_config (the_repository , * sparse_index ) < 0 )
436
+ if (set_sparse_index_config (repo , * sparse_index ) < 0 )
435
437
die (_ ("failed to modify sparse-index config" ));
436
438
437
439
/* force an index rewrite */
438
- repo_read_index (the_repository );
439
- the_repository -> index -> updated_workdir = 1 ;
440
+ repo_read_index (repo );
441
+ repo -> index -> updated_workdir = 1 ;
440
442
441
443
if (!* sparse_index )
442
- ensure_full_index_with_reason (the_repository -> index ,
444
+ ensure_full_index_with_reason (repo -> index ,
443
445
"sparse-checkout:disabling sparse index" );
444
446
}
445
447
@@ -457,7 +459,7 @@ static struct sparse_checkout_init_opts {
457
459
} init_opts ;
458
460
459
461
static int sparse_checkout_init (int argc , const char * * argv , const char * prefix ,
460
- struct repository * repo UNUSED )
462
+ struct repository * repo )
461
463
{
462
464
struct pattern_list pl ;
463
465
char * sparse_filename ;
@@ -473,7 +475,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
473
475
};
474
476
475
477
setup_work_tree ();
476
- repo_read_index (the_repository );
478
+ repo_read_index (repo );
477
479
478
480
init_opts .cone_mode = -1 ;
479
481
init_opts .sparse_index = -1 ;
@@ -482,7 +484,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
482
484
builtin_sparse_checkout_init_options ,
483
485
builtin_sparse_checkout_init_usage , 0 );
484
486
485
- if (update_modes (& init_opts .cone_mode , & init_opts .sparse_index ))
487
+ if (update_modes (repo , & init_opts .cone_mode , & init_opts .sparse_index ))
486
488
return 1 ;
487
489
488
490
memset (& pl , 0 , sizeof (pl ));
@@ -494,14 +496,14 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
494
496
if (res >= 0 ) {
495
497
free (sparse_filename );
496
498
clear_pattern_list (& pl );
497
- return update_working_directory (NULL );
499
+ return update_working_directory (repo , NULL );
498
500
}
499
501
500
- if (repo_get_oid (the_repository , "HEAD" , & oid )) {
502
+ if (repo_get_oid (repo , "HEAD" , & oid )) {
501
503
FILE * fp ;
502
504
503
505
/* assume we are in a fresh repo, but update the sparse-checkout file */
504
- if (safe_create_leading_directories (the_repository , sparse_filename ))
506
+ if (safe_create_leading_directories (repo , sparse_filename ))
505
507
die (_ ("unable to create leading directories of %s" ),
506
508
sparse_filename );
507
509
fp = xfopen (sparse_filename , "w" );
@@ -520,7 +522,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix,
520
522
add_pattern ("!/*/" , empty_base , 0 , & pl , 0 );
521
523
pl .use_cone_patterns = init_opts .cone_mode ;
522
524
523
- return write_patterns_and_update (& pl );
525
+ return write_patterns_and_update (repo , & pl );
524
526
}
525
527
526
528
static void insert_recursive_pattern (struct pattern_list * pl , struct strbuf * path )
@@ -683,7 +685,8 @@ static void add_patterns_literal(int argc, const char **argv,
683
685
add_patterns_from_input (pl , argc , argv , use_stdin ? stdin : NULL );
684
686
}
685
687
686
- static int modify_pattern_list (struct strvec * args , int use_stdin ,
688
+ static int modify_pattern_list (struct repository * repo ,
689
+ struct strvec * args , int use_stdin ,
687
690
enum modify_type m )
688
691
{
689
692
int result ;
@@ -705,22 +708,23 @@ static int modify_pattern_list(struct strvec *args, int use_stdin,
705
708
}
706
709
707
710
if (!core_apply_sparse_checkout ) {
708
- set_config (MODE_ALL_PATTERNS );
711
+ set_config (repo , MODE_ALL_PATTERNS );
709
712
core_apply_sparse_checkout = 1 ;
710
713
changed_config = 1 ;
711
714
}
712
715
713
- result = write_patterns_and_update (pl );
716
+ result = write_patterns_and_update (repo , pl );
714
717
715
718
if (result && changed_config )
716
- set_config (MODE_NO_PATTERNS );
719
+ set_config (repo , MODE_NO_PATTERNS );
717
720
718
721
clear_pattern_list (pl );
719
722
free (pl );
720
723
return result ;
721
724
}
722
725
723
- static void sanitize_paths (struct strvec * args ,
726
+ static void sanitize_paths (struct repository * repo ,
727
+ struct strvec * args ,
724
728
const char * prefix , int skip_checks )
725
729
{
726
730
int i ;
@@ -761,7 +765,7 @@ static void sanitize_paths(struct strvec *args,
761
765
762
766
for (i = 0 ; i < args -> nr ; i ++ ) {
763
767
struct cache_entry * ce ;
764
- struct index_state * index = the_repository -> index ;
768
+ struct index_state * index = repo -> index ;
765
769
int pos = index_name_pos (index , args -> v [i ], strlen (args -> v [i ]));
766
770
767
771
if (pos < 0 )
@@ -788,7 +792,7 @@ static struct sparse_checkout_add_opts {
788
792
} add_opts ;
789
793
790
794
static int sparse_checkout_add (int argc , const char * * argv , const char * prefix ,
791
- struct repository * repo UNUSED )
795
+ struct repository * repo )
792
796
{
793
797
static struct option builtin_sparse_checkout_add_options [] = {
794
798
OPT_BOOL_F (0 , "skip-checks" , & add_opts .skip_checks ,
@@ -805,17 +809,17 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
805
809
if (!core_apply_sparse_checkout )
806
810
die (_ ("no sparse-checkout to add to" ));
807
811
808
- repo_read_index (the_repository );
812
+ repo_read_index (repo );
809
813
810
814
argc = parse_options (argc , argv , prefix ,
811
815
builtin_sparse_checkout_add_options ,
812
816
builtin_sparse_checkout_add_usage , 0 );
813
817
814
818
for (int i = 0 ; i < argc ; i ++ )
815
819
strvec_push (& patterns , argv [i ]);
816
- sanitize_paths (& patterns , prefix , add_opts .skip_checks );
820
+ sanitize_paths (repo , & patterns , prefix , add_opts .skip_checks );
817
821
818
- ret = modify_pattern_list (& patterns , add_opts .use_stdin , ADD );
822
+ ret = modify_pattern_list (repo , & patterns , add_opts .use_stdin , ADD );
819
823
820
824
strvec_clear (& patterns );
821
825
return ret ;
@@ -834,7 +838,7 @@ static struct sparse_checkout_set_opts {
834
838
} set_opts ;
835
839
836
840
static int sparse_checkout_set (int argc , const char * * argv , const char * prefix ,
837
- struct repository * repo UNUSED )
841
+ struct repository * repo )
838
842
{
839
843
int default_patterns_nr = 2 ;
840
844
const char * default_patterns [] = {"/*" , "!/*/" , NULL };
@@ -856,7 +860,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
856
860
int ret ;
857
861
858
862
setup_work_tree ();
859
- repo_read_index (the_repository );
863
+ repo_read_index (repo );
860
864
861
865
set_opts .cone_mode = -1 ;
862
866
set_opts .sparse_index = -1 ;
@@ -865,7 +869,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
865
869
builtin_sparse_checkout_set_options ,
866
870
builtin_sparse_checkout_set_usage , 0 );
867
871
868
- if (update_modes (& set_opts .cone_mode , & set_opts .sparse_index ))
872
+ if (update_modes (repo , & set_opts .cone_mode , & set_opts .sparse_index ))
869
873
return 1 ;
870
874
871
875
/*
@@ -879,10 +883,10 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
879
883
} else {
880
884
for (int i = 0 ; i < argc ; i ++ )
881
885
strvec_push (& patterns , argv [i ]);
882
- sanitize_paths (& patterns , prefix , set_opts .skip_checks );
886
+ sanitize_paths (repo , & patterns , prefix , set_opts .skip_checks );
883
887
}
884
888
885
- ret = modify_pattern_list (& patterns , set_opts .use_stdin , REPLACE );
889
+ ret = modify_pattern_list (repo , & patterns , set_opts .use_stdin , REPLACE );
886
890
887
891
strvec_clear (& patterns );
888
892
return ret ;
@@ -900,7 +904,7 @@ static struct sparse_checkout_reapply_opts {
900
904
901
905
static int sparse_checkout_reapply (int argc , const char * * argv ,
902
906
const char * prefix ,
903
- struct repository * repo UNUSED )
907
+ struct repository * repo )
904
908
{
905
909
static struct option builtin_sparse_checkout_reapply_options [] = {
906
910
OPT_BOOL (0 , "cone" , & reapply_opts .cone_mode ,
@@ -921,12 +925,12 @@ static int sparse_checkout_reapply(int argc, const char **argv,
921
925
builtin_sparse_checkout_reapply_options ,
922
926
builtin_sparse_checkout_reapply_usage , 0 );
923
927
924
- repo_read_index (the_repository );
928
+ repo_read_index (repo );
925
929
926
- if (update_modes (& reapply_opts .cone_mode , & reapply_opts .sparse_index ))
930
+ if (update_modes (repo , & reapply_opts .cone_mode , & reapply_opts .sparse_index ))
927
931
return 1 ;
928
932
929
- return update_working_directory (NULL );
933
+ return update_working_directory (repo , NULL );
930
934
}
931
935
932
936
static char const * const builtin_sparse_checkout_disable_usage [] = {
@@ -936,7 +940,7 @@ static char const * const builtin_sparse_checkout_disable_usage[] = {
936
940
937
941
static int sparse_checkout_disable (int argc , const char * * argv ,
938
942
const char * prefix ,
939
- struct repository * repo UNUSED )
943
+ struct repository * repo )
940
944
{
941
945
static struct option builtin_sparse_checkout_disable_options [] = {
942
946
OPT_END (),
@@ -964,7 +968,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
964
968
* are expecting to do that when disabling sparse-checkout.
965
969
*/
966
970
give_advice_on_expansion = 0 ;
967
- repo_read_index (the_repository );
971
+ repo_read_index (repo );
968
972
969
973
memset (& pl , 0 , sizeof (pl ));
970
974
hashmap_init (& pl .recursive_hashmap , pl_hashmap_cmp , NULL , 0 );
@@ -977,11 +981,11 @@ static int sparse_checkout_disable(int argc, const char **argv,
977
981
prepare_repo_settings (the_repository );
978
982
the_repository -> settings .sparse_index = 0 ;
979
983
980
- if (update_working_directory (& pl ))
984
+ if (update_working_directory (repo , & pl ))
981
985
die (_ ("error while refreshing working directory" ));
982
986
983
987
clear_pattern_list (& pl );
984
- return set_config (MODE_NO_PATTERNS );
988
+ return set_config (repo , MODE_NO_PATTERNS );
985
989
}
986
990
987
991
static char const * const builtin_sparse_checkout_check_rules_usage [] = {
@@ -996,14 +1000,17 @@ static struct sparse_checkout_check_rules_opts {
996
1000
char * rules_file ;
997
1001
} check_rules_opts ;
998
1002
999
- static int check_rules (struct pattern_list * pl , int null_terminated ) {
1003
+ static int check_rules (struct repository * repo ,
1004
+ struct pattern_list * pl ,
1005
+ int null_terminated )
1006
+ {
1000
1007
struct strbuf line = STRBUF_INIT ;
1001
1008
struct strbuf unquoted = STRBUF_INIT ;
1002
1009
char * path ;
1003
1010
int line_terminator = null_terminated ? 0 : '\n' ;
1004
1011
strbuf_getline_fn getline_fn = null_terminated ? strbuf_getline_nul
1005
1012
: strbuf_getline ;
1006
- the_repository -> index -> sparse_checkout_patterns = pl ;
1013
+ repo -> index -> sparse_checkout_patterns = pl ;
1007
1014
while (!getline_fn (& line , stdin )) {
1008
1015
path = line .buf ;
1009
1016
if (!null_terminated && line .buf [0 ] == '"' ) {
@@ -1015,7 +1022,7 @@ static int check_rules(struct pattern_list *pl, int null_terminated) {
1015
1022
path = unquoted .buf ;
1016
1023
}
1017
1024
1018
- if (path_in_sparse_checkout (path , the_repository -> index ))
1025
+ if (path_in_sparse_checkout (path , repo -> index ))
1019
1026
write_name_quoted (path , stdout , line_terminator );
1020
1027
}
1021
1028
strbuf_release (& line );
@@ -1025,7 +1032,7 @@ static int check_rules(struct pattern_list *pl, int null_terminated) {
1025
1032
}
1026
1033
1027
1034
static int sparse_checkout_check_rules (int argc , const char * * argv , const char * prefix ,
1028
- struct repository * repo UNUSED )
1035
+ struct repository * repo )
1029
1036
{
1030
1037
static struct option builtin_sparse_checkout_check_rules_options [] = {
1031
1038
OPT_BOOL ('z' , NULL , & check_rules_opts .null_termination ,
@@ -1064,7 +1071,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
1064
1071
free (sparse_filename );
1065
1072
}
1066
1073
1067
- ret = check_rules (& pl , check_rules_opts .null_termination );
1074
+ ret = check_rules (repo , & pl , check_rules_opts .null_termination );
1068
1075
clear_pattern_list (& pl );
1069
1076
free (check_rules_opts .rules_file );
1070
1077
return ret ;
@@ -1093,8 +1100,8 @@ int cmd_sparse_checkout(int argc,
1093
1100
1094
1101
repo_config (the_repository , git_default_config , NULL );
1095
1102
1096
- prepare_repo_settings (the_repository );
1097
- the_repository -> settings .command_requires_full_index = 0 ;
1103
+ prepare_repo_settings (repo );
1104
+ repo -> settings .command_requires_full_index = 0 ;
1098
1105
1099
1106
return fn (argc , argv , prefix , repo );
1100
1107
}
0 commit comments