3
3
*
4
4
* Copyright (C) 2006 Linus Torvalds
5
5
*/
6
- #define USE_THE_REPOSITORY_VARIABLE
7
6
#include "builtin.h"
8
7
#include "advice.h"
9
8
#include "config.h"
@@ -35,24 +34,27 @@ static int pathspec_file_nul;
35
34
static int include_sparse ;
36
35
static const char * pathspec_from_file ;
37
36
38
- static int chmod_pathspec (struct pathspec * pathspec , char flip , int show_only )
37
+ static int chmod_pathspec (struct repository * repo ,
38
+ struct pathspec * pathspec ,
39
+ char flip ,
40
+ int show_only )
39
41
{
40
42
int i , ret = 0 ;
41
43
42
- for (i = 0 ; i < the_repository -> index -> cache_nr ; i ++ ) {
43
- struct cache_entry * ce = the_repository -> index -> cache [i ];
44
+ for (i = 0 ; i < repo -> index -> cache_nr ; i ++ ) {
45
+ struct cache_entry * ce = repo -> index -> cache [i ];
44
46
int err ;
45
47
46
48
if (!include_sparse &&
47
49
(ce_skip_worktree (ce ) ||
48
- !path_in_sparse_checkout (ce -> name , the_repository -> index )))
50
+ !path_in_sparse_checkout (ce -> name , repo -> index )))
49
51
continue ;
50
52
51
- if (pathspec && !ce_path_match (the_repository -> index , ce , pathspec , NULL ))
53
+ if (pathspec && !ce_path_match (repo -> index , ce , pathspec , NULL ))
52
54
continue ;
53
55
54
56
if (!show_only )
55
- err = chmod_index_entry (the_repository -> index , ce , flip );
57
+ err = chmod_index_entry (repo -> index , ce , flip );
56
58
else
57
59
err = S_ISREG (ce -> ce_mode ) ? 0 : -1 ;
58
60
@@ -63,31 +65,36 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
63
65
return ret ;
64
66
}
65
67
66
- static int renormalize_tracked_files (const struct pathspec * pathspec , int flags )
68
+ static int renormalize_tracked_files (struct repository * repo ,
69
+ const struct pathspec * pathspec ,
70
+ int flags )
67
71
{
68
72
int i , retval = 0 ;
69
73
70
- for (i = 0 ; i < the_repository -> index -> cache_nr ; i ++ ) {
71
- struct cache_entry * ce = the_repository -> index -> cache [i ];
74
+ for (i = 0 ; i < repo -> index -> cache_nr ; i ++ ) {
75
+ struct cache_entry * ce = repo -> index -> cache [i ];
72
76
73
77
if (!include_sparse &&
74
78
(ce_skip_worktree (ce ) ||
75
- !path_in_sparse_checkout (ce -> name , the_repository -> index )))
79
+ !path_in_sparse_checkout (ce -> name , repo -> index )))
76
80
continue ;
77
81
if (ce_stage (ce ))
78
82
continue ; /* do not touch unmerged paths */
79
83
if (!S_ISREG (ce -> ce_mode ) && !S_ISLNK (ce -> ce_mode ))
80
84
continue ; /* do not touch non blobs */
81
- if (pathspec && !ce_path_match (the_repository -> index , ce , pathspec , NULL ))
85
+ if (pathspec && !ce_path_match (repo -> index , ce , pathspec , NULL ))
82
86
continue ;
83
- retval |= add_file_to_index (the_repository -> index , ce -> name ,
87
+ retval |= add_file_to_index (repo -> index , ce -> name ,
84
88
flags | ADD_CACHE_RENORMALIZE );
85
89
}
86
90
87
91
return retval ;
88
92
}
89
93
90
- static char * prune_directory (struct dir_struct * dir , struct pathspec * pathspec , int prefix )
94
+ static char * prune_directory (struct repository * repo ,
95
+ struct dir_struct * dir ,
96
+ struct pathspec * pathspec ,
97
+ int prefix )
91
98
{
92
99
char * seen ;
93
100
int i ;
@@ -99,16 +106,16 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
99
106
i = dir -> nr ;
100
107
while (-- i >= 0 ) {
101
108
struct dir_entry * entry = * src ++ ;
102
- if (dir_path_match (the_repository -> index , entry , pathspec , prefix , seen ))
109
+ if (dir_path_match (repo -> index , entry , pathspec , prefix , seen ))
103
110
* dst ++ = entry ;
104
111
}
105
112
dir -> nr = dst - dir -> entries ;
106
- add_pathspec_matches_against_index (pathspec , the_repository -> index , seen ,
113
+ add_pathspec_matches_against_index (pathspec , repo -> index , seen ,
107
114
PS_IGNORE_SKIP_WORKTREE );
108
115
return seen ;
109
116
}
110
117
111
- static int refresh (int verbose , const struct pathspec * pathspec )
118
+ static int refresh (struct repository * repo , int verbose , const struct pathspec * pathspec )
112
119
{
113
120
char * seen ;
114
121
int i , ret = 0 ;
@@ -118,14 +125,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)
118
125
(verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET );
119
126
120
127
seen = xcalloc (pathspec -> nr , 1 );
121
- refresh_index (the_repository -> index , flags , pathspec , seen ,
128
+ refresh_index (repo -> index , flags , pathspec , seen ,
122
129
_ ("Unstaged changes after refreshing the index:" ));
123
130
for (i = 0 ; i < pathspec -> nr ; i ++ ) {
124
131
if (!seen [i ]) {
125
132
const char * path = pathspec -> items [i ].original ;
126
133
127
134
if (matches_skip_worktree (pathspec , i , & skip_worktree_seen ) ||
128
- !path_in_sparse_checkout (path , the_repository -> index )) {
135
+ !path_in_sparse_checkout (path , repo -> index )) {
129
136
string_list_append (& only_match_skip_worktree ,
130
137
pathspec -> items [i ].original );
131
138
} else {
@@ -146,7 +153,10 @@ static int refresh(int verbose, const struct pathspec *pathspec)
146
153
return ret ;
147
154
}
148
155
149
- int interactive_add (const char * * argv , const char * prefix , int patch )
156
+ int interactive_add (struct repository * repo ,
157
+ const char * * argv ,
158
+ const char * prefix ,
159
+ int patch )
150
160
{
151
161
struct pathspec pathspec ;
152
162
int ret ;
@@ -158,31 +168,31 @@ int interactive_add(const char **argv, const char *prefix, int patch)
158
168
prefix , argv );
159
169
160
170
if (patch )
161
- ret = !!run_add_p (the_repository , ADD_P_ADD , NULL , & pathspec );
171
+ ret = !!run_add_p (repo , ADD_P_ADD , NULL , & pathspec );
162
172
else
163
- ret = !!run_add_i (the_repository , & pathspec );
173
+ ret = !!run_add_i (repo , & pathspec );
164
174
165
175
clear_pathspec (& pathspec );
166
176
return ret ;
167
177
}
168
178
169
- static int edit_patch (int argc ,
179
+ static int edit_patch (struct repository * repo ,
180
+ int argc ,
170
181
const char * * argv ,
171
- const char * prefix ,
172
- struct repository * repo UNUSED )
182
+ const char * prefix )
173
183
{
174
- char * file = git_pathdup ( "ADD_EDIT.patch" );
184
+ char * file = repo_git_path ( repo , "ADD_EDIT.patch" );
175
185
struct child_process child = CHILD_PROCESS_INIT ;
176
186
struct rev_info rev ;
177
187
int out ;
178
188
struct stat st ;
179
189
180
- git_config ( git_diff_basic_config , NULL ); /* no "diff" UI options */
190
+ repo_config ( repo , git_diff_basic_config , NULL );
181
191
182
- if (repo_read_index (the_repository ) < 0 )
192
+ if (repo_read_index (repo ) < 0 )
183
193
die (_ ("could not read the index" ));
184
194
185
- repo_init_revisions (the_repository , & rev , prefix );
195
+ repo_init_revisions (repo , & rev , prefix );
186
196
rev .diffopt .context = 7 ;
187
197
188
198
argc = setup_revisions (argc , argv , & rev , NULL );
@@ -320,7 +330,7 @@ static void check_embedded_repo(const char *path)
320
330
strbuf_release (& name );
321
331
}
322
332
323
- static int add_files (struct dir_struct * dir , int flags )
333
+ static int add_files (struct repository * repo , struct dir_struct * dir , int flags )
324
334
{
325
335
int i , exit_status = 0 ;
326
336
struct string_list matched_sparse_paths = STRING_LIST_INIT_NODUP ;
@@ -336,12 +346,12 @@ static int add_files(struct dir_struct *dir, int flags)
336
346
337
347
for (i = 0 ; i < dir -> nr ; i ++ ) {
338
348
if (!include_sparse &&
339
- !path_in_sparse_checkout (dir -> entries [i ]-> name , the_repository -> index )) {
349
+ !path_in_sparse_checkout (dir -> entries [i ]-> name , repo -> index )) {
340
350
string_list_append (& matched_sparse_paths ,
341
351
dir -> entries [i ]-> name );
342
352
continue ;
343
353
}
344
- if (add_file_to_index (the_repository -> index , dir -> entries [i ]-> name , flags )) {
354
+ if (add_file_to_index (repo -> index , dir -> entries [i ]-> name , flags )) {
345
355
if (!ignore_add_errors )
346
356
die (_ ("adding files failed" ));
347
357
exit_status = 1 ;
@@ -363,7 +373,7 @@ static int add_files(struct dir_struct *dir, int flags)
363
373
int cmd_add (int argc ,
364
374
const char * * argv ,
365
375
const char * prefix ,
366
- struct repository * repo UNUSED )
376
+ struct repository * repo )
367
377
{
368
378
int exit_status = 0 ;
369
379
struct pathspec pathspec ;
@@ -375,7 +385,7 @@ int cmd_add(int argc,
375
385
char * ps_matched = NULL ;
376
386
struct lock_file lock_file = LOCK_INIT ;
377
387
378
- git_config ( add_config , NULL );
388
+ repo_config ( repo , add_config , NULL );
379
389
380
390
argc = parse_options (argc , argv , prefix , builtin_add_options ,
381
391
builtin_add_usage , PARSE_OPT_KEEP_ARGV0 );
@@ -386,13 +396,13 @@ int cmd_add(int argc,
386
396
die (_ ("options '%s' and '%s' cannot be used together" ), "--dry-run" , "--interactive/--patch" );
387
397
if (pathspec_from_file )
388
398
die (_ ("options '%s' and '%s' cannot be used together" ), "--pathspec-from-file" , "--interactive/--patch" );
389
- exit (interactive_add (argv + 1 , prefix , patch_interactive ));
399
+ exit (interactive_add (repo , argv + 1 , prefix , patch_interactive ));
390
400
}
391
401
392
402
if (edit_interactive ) {
393
403
if (pathspec_from_file )
394
404
die (_ ("options '%s' and '%s' cannot be used together" ), "--pathspec-from-file" , "--edit" );
395
- return (edit_patch (argc , argv , prefix , the_repository ));
405
+ return (edit_patch (repo , argc , argv , prefix ));
396
406
}
397
407
argc -- ;
398
408
argv ++ ;
@@ -415,10 +425,10 @@ int cmd_add(int argc,
415
425
add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize ;
416
426
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit ));
417
427
418
- prepare_repo_settings (the_repository );
419
- the_repository -> settings .command_requires_full_index = 0 ;
428
+ prepare_repo_settings (repo );
429
+ repo -> settings .command_requires_full_index = 0 ;
420
430
421
- repo_hold_locked_index (the_repository , & lock_file , LOCK_DIE_ON_ERROR );
431
+ repo_hold_locked_index (repo , & lock_file , LOCK_DIE_ON_ERROR );
422
432
423
433
/*
424
434
* Check the "pathspec '%s' did not match any files" block
@@ -459,11 +469,11 @@ int cmd_add(int argc,
459
469
(!(addremove || take_worktree_changes )
460
470
? ADD_CACHE_IGNORE_REMOVAL : 0 ));
461
471
462
- if (repo_read_index_preload (the_repository , & pathspec , 0 ) < 0 )
472
+ if (repo_read_index_preload (repo , & pathspec , 0 ) < 0 )
463
473
die (_ ("index file corrupt" ));
464
474
465
- die_in_unpopulated_submodule (the_repository -> index , prefix );
466
- die_path_inside_submodule (the_repository -> index , & pathspec );
475
+ die_in_unpopulated_submodule (repo -> index , prefix );
476
+ die_path_inside_submodule (repo -> index , & pathspec );
467
477
468
478
if (add_new_files ) {
469
479
int baselen ;
@@ -475,13 +485,13 @@ int cmd_add(int argc,
475
485
}
476
486
477
487
/* This picks up the paths that are not tracked */
478
- baselen = fill_directory (& dir , the_repository -> index , & pathspec );
488
+ baselen = fill_directory (& dir , repo -> index , & pathspec );
479
489
if (pathspec .nr )
480
- seen = prune_directory (& dir , & pathspec , baselen );
490
+ seen = prune_directory (repo , & dir , & pathspec , baselen );
481
491
}
482
492
483
493
if (refresh_only ) {
484
- exit_status |= refresh (verbose , & pathspec );
494
+ exit_status |= refresh (repo , verbose , & pathspec );
485
495
goto finish ;
486
496
}
487
497
@@ -492,7 +502,7 @@ int cmd_add(int argc,
492
502
493
503
if (!seen )
494
504
seen = find_pathspecs_matching_against_index (& pathspec ,
495
- the_repository -> index , PS_IGNORE_SKIP_WORKTREE );
505
+ repo -> index , PS_IGNORE_SKIP_WORKTREE );
496
506
497
507
/*
498
508
* file_exists() assumes exact match
@@ -528,8 +538,8 @@ int cmd_add(int argc,
528
538
!file_exists (path )) {
529
539
if (ignore_missing ) {
530
540
int dtype = DT_UNKNOWN ;
531
- if (is_excluded (& dir , the_repository -> index , path , & dtype ))
532
- dir_add_ignored (& dir , the_repository -> index ,
541
+ if (is_excluded (& dir , repo -> index , path , & dtype ))
542
+ dir_add_ignored (& dir , repo -> index ,
533
543
path , pathspec .items [i ].len );
534
544
} else
535
545
die (_ ("pathspec '%s' did not match any files" ),
@@ -552,9 +562,9 @@ int cmd_add(int argc,
552
562
553
563
ps_matched = xcalloc (pathspec .nr , 1 );
554
564
if (add_renormalize )
555
- exit_status |= renormalize_tracked_files (& pathspec , flags );
565
+ exit_status |= renormalize_tracked_files (repo , & pathspec , flags );
556
566
else
557
- exit_status |= add_files_to_cache (the_repository , prefix ,
567
+ exit_status |= add_files_to_cache (repo , prefix ,
558
568
& pathspec , ps_matched ,
559
569
include_sparse , flags );
560
570
@@ -563,14 +573,14 @@ int cmd_add(int argc,
563
573
exit (128 );
564
574
565
575
if (add_new_files )
566
- exit_status |= add_files (& dir , flags );
576
+ exit_status |= add_files (repo , & dir , flags );
567
577
568
578
if (chmod_arg && pathspec .nr )
569
- exit_status |= chmod_pathspec (& pathspec , chmod_arg [0 ], show_only );
579
+ exit_status |= chmod_pathspec (repo , & pathspec , chmod_arg [0 ], show_only );
570
580
end_odb_transaction ();
571
581
572
582
finish :
573
- if (write_locked_index (the_repository -> index , & lock_file ,
583
+ if (write_locked_index (repo -> index , & lock_file ,
574
584
COMMIT_LOCK | SKIP_IF_UNCHANGED ))
575
585
die (_ ("unable to write new index file" ));
576
586
0 commit comments