@@ -29,10 +29,11 @@ static int use_worktree_config;
29
29
static struct git_config_source given_config_source ;
30
30
static int actions , type ;
31
31
static char * default_value ;
32
- static int end_null ;
32
+ static int end_nul ;
33
33
static int respect_includes_opt = -1 ;
34
34
static struct config_options config_options ;
35
35
static int show_origin ;
36
+ static int show_scope ;
36
37
37
38
#define ACTION_GET (1<<0)
38
39
#define ACTION_GET_ALL (1<<1)
@@ -151,10 +152,11 @@ static struct option builtin_config_options[] = {
151
152
OPT_CALLBACK_VALUE (0 , "path" , & type , N_ ("value is a path (file or directory name)" ), TYPE_PATH ),
152
153
OPT_CALLBACK_VALUE (0 , "expiry-date" , & type , N_ ("value is an expiry date" ), TYPE_EXPIRY_DATE ),
153
154
OPT_GROUP (N_ ("Other" )),
154
- OPT_BOOL ('z' , "null" , & end_null , N_ ("terminate values with NUL byte" )),
155
+ OPT_BOOL ('z' , "null" , & end_nul , N_ ("terminate values with NUL byte" )),
155
156
OPT_BOOL (0 , "name-only" , & omit_values , N_ ("show variable names only" )),
156
157
OPT_BOOL (0 , "includes" , & respect_includes_opt , N_ ("respect include directives on lookup" )),
157
158
OPT_BOOL (0 , "show-origin" , & show_origin , N_ ("show origin of config (file, standard input, blob, command line)" )),
159
+ OPT_BOOL (0 , "show-scope" , & show_scope , N_ ("show scope of config (worktree, local, global, system, command)" )),
158
160
OPT_STRING (0 , "default" , & default_value , N_ ("value" ), N_ ("with --get, use default value when missing entry" )),
159
161
OPT_END (),
160
162
};
@@ -178,22 +180,34 @@ static void check_argc(int argc, int min, int max)
178
180
179
181
static void show_config_origin (struct strbuf * buf )
180
182
{
181
- const char term = end_null ? '\0' : '\t' ;
183
+ const char term = end_nul ? '\0' : '\t' ;
182
184
183
185
strbuf_addstr (buf , current_config_origin_type ());
184
186
strbuf_addch (buf , ':' );
185
- if (end_null )
187
+ if (end_nul )
186
188
strbuf_addstr (buf , current_config_name ());
187
189
else
188
190
quote_c_style (current_config_name (), buf , NULL , 0 );
189
191
strbuf_addch (buf , term );
190
192
}
191
193
194
+ static void show_config_scope (struct strbuf * buf )
195
+ {
196
+ const char term = end_nul ? '\0' : '\t' ;
197
+ const char * scope = config_scope_name (current_config_scope ());
198
+
199
+ strbuf_addstr (buf , N_ (scope ));
200
+ strbuf_addch (buf , term );
201
+ }
202
+
192
203
static int show_all_config (const char * key_ , const char * value_ , void * cb )
193
204
{
194
- if (show_origin ) {
205
+ if (show_origin || show_scope ) {
195
206
struct strbuf buf = STRBUF_INIT ;
196
- show_config_origin (& buf );
207
+ if (show_scope )
208
+ show_config_scope (& buf );
209
+ if (show_origin )
210
+ show_config_origin (& buf );
197
211
/* Use fwrite as "buf" can contain \0's if "end_null" is set. */
198
212
fwrite (buf .buf , 1 , buf .len , stdout );
199
213
strbuf_release (& buf );
@@ -213,6 +227,8 @@ struct strbuf_list {
213
227
214
228
static int format_config (struct strbuf * buf , const char * key_ , const char * value_ )
215
229
{
230
+ if (show_scope )
231
+ show_config_scope (buf );
216
232
if (show_origin )
217
233
show_config_origin (buf );
218
234
if (show_keys )
@@ -622,6 +638,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
622
638
!strcmp (given_config_source .file , "-" )) {
623
639
given_config_source .file = NULL ;
624
640
given_config_source .use_stdin = 1 ;
641
+ given_config_source .scope = CONFIG_SCOPE_COMMAND ;
625
642
}
626
643
627
644
if (use_global_config ) {
@@ -637,6 +654,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
637
654
*/
638
655
die (_ ("$HOME not set" ));
639
656
657
+ given_config_source .scope = CONFIG_SCOPE_GLOBAL ;
658
+
640
659
if (access_or_warn (user_config , R_OK , 0 ) &&
641
660
xdg_config && !access_or_warn (xdg_config , R_OK , 0 )) {
642
661
given_config_source .file = xdg_config ;
@@ -646,11 +665,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
646
665
free (xdg_config );
647
666
}
648
667
}
649
- else if (use_system_config )
668
+ else if (use_system_config ) {
650
669
given_config_source .file = git_etc_gitconfig ();
651
- else if (use_local_config )
670
+ given_config_source .scope = CONFIG_SCOPE_SYSTEM ;
671
+ } else if (use_local_config ) {
652
672
given_config_source .file = git_pathdup ("config" );
653
- else if (use_worktree_config ) {
673
+ given_config_source .scope = CONFIG_SCOPE_LOCAL ;
674
+ } else if (use_worktree_config ) {
654
675
struct worktree * * worktrees = get_worktrees (0 );
655
676
if (repository_format_worktree_config )
656
677
given_config_source .file = git_pathdup ("config.worktree" );
@@ -662,13 +683,18 @@ int cmd_config(int argc, const char **argv, const char *prefix)
662
683
"section in \"git help worktree\" for details" ));
663
684
else
664
685
given_config_source .file = git_pathdup ("config" );
686
+ given_config_source .scope = CONFIG_SCOPE_LOCAL ;
665
687
free_worktrees (worktrees );
666
688
} else if (given_config_source .file ) {
667
689
if (!is_absolute_path (given_config_source .file ) && prefix )
668
690
given_config_source .file =
669
691
prefix_filename (prefix , given_config_source .file );
692
+ given_config_source .scope = CONFIG_SCOPE_COMMAND ;
693
+ } else if (given_config_source .blob ) {
694
+ given_config_source .scope = CONFIG_SCOPE_COMMAND ;
670
695
}
671
696
697
+
672
698
if (respect_includes_opt == -1 )
673
699
config_options .respect_includes = !given_config_source .file ;
674
700
else
@@ -678,7 +704,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
678
704
config_options .git_dir = get_git_dir ();
679
705
}
680
706
681
- if (end_null ) {
707
+ if (end_nul ) {
682
708
term = '\0' ;
683
709
delim = '\n' ;
684
710
key_delim = '\n' ;
0 commit comments