@@ -29,10 +29,11 @@ static int use_worktree_config;
2929static struct git_config_source given_config_source ;
3030static int actions , type ;
3131static char * default_value ;
32- static int end_null ;
32+ static int end_nul ;
3333static int respect_includes_opt = -1 ;
3434static struct config_options config_options ;
3535static int show_origin ;
36+ static int show_scope ;
3637
3738#define ACTION_GET (1<<0)
3839#define ACTION_GET_ALL (1<<1)
@@ -151,10 +152,11 @@ static struct option builtin_config_options[] = {
151152 OPT_CALLBACK_VALUE (0 , "path" , & type , N_ ("value is a path (file or directory name)" ), TYPE_PATH ),
152153 OPT_CALLBACK_VALUE (0 , "expiry-date" , & type , N_ ("value is an expiry date" ), TYPE_EXPIRY_DATE ),
153154 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" )),
155156 OPT_BOOL (0 , "name-only" , & omit_values , N_ ("show variable names only" )),
156157 OPT_BOOL (0 , "includes" , & respect_includes_opt , N_ ("respect include directives on lookup" )),
157158 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)" )),
158160 OPT_STRING (0 , "default" , & default_value , N_ ("value" ), N_ ("with --get, use default value when missing entry" )),
159161 OPT_END (),
160162};
@@ -178,22 +180,34 @@ static void check_argc(int argc, int min, int max)
178180
179181static void show_config_origin (struct strbuf * buf )
180182{
181- const char term = end_null ? '\0' : '\t' ;
183+ const char term = end_nul ? '\0' : '\t' ;
182184
183185 strbuf_addstr (buf , current_config_origin_type ());
184186 strbuf_addch (buf , ':' );
185- if (end_null )
187+ if (end_nul )
186188 strbuf_addstr (buf , current_config_name ());
187189 else
188190 quote_c_style (current_config_name (), buf , NULL , 0 );
189191 strbuf_addch (buf , term );
190192}
191193
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+
192203static int show_all_config (const char * key_ , const char * value_ , void * cb )
193204{
194- if (show_origin ) {
205+ if (show_origin || show_scope ) {
195206 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 );
197211 /* Use fwrite as "buf" can contain \0's if "end_null" is set. */
198212 fwrite (buf .buf , 1 , buf .len , stdout );
199213 strbuf_release (& buf );
@@ -213,6 +227,8 @@ struct strbuf_list {
213227
214228static int format_config (struct strbuf * buf , const char * key_ , const char * value_ )
215229{
230+ if (show_scope )
231+ show_config_scope (buf );
216232 if (show_origin )
217233 show_config_origin (buf );
218234 if (show_keys )
@@ -622,6 +638,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
622638 !strcmp (given_config_source .file , "-" )) {
623639 given_config_source .file = NULL ;
624640 given_config_source .use_stdin = 1 ;
641+ given_config_source .scope = CONFIG_SCOPE_COMMAND ;
625642 }
626643
627644 if (use_global_config ) {
@@ -637,6 +654,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
637654 */
638655 die (_ ("$HOME not set" ));
639656
657+ given_config_source .scope = CONFIG_SCOPE_GLOBAL ;
658+
640659 if (access_or_warn (user_config , R_OK , 0 ) &&
641660 xdg_config && !access_or_warn (xdg_config , R_OK , 0 )) {
642661 given_config_source .file = xdg_config ;
@@ -646,11 +665,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
646665 free (xdg_config );
647666 }
648667 }
649- else if (use_system_config )
668+ else if (use_system_config ) {
650669 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 ) {
652672 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 ) {
654675 struct worktree * * worktrees = get_worktrees (0 );
655676 if (repository_format_worktree_config )
656677 given_config_source .file = git_pathdup ("config.worktree" );
@@ -662,13 +683,18 @@ int cmd_config(int argc, const char **argv, const char *prefix)
662683 "section in \"git help worktree\" for details" ));
663684 else
664685 given_config_source .file = git_pathdup ("config" );
686+ given_config_source .scope = CONFIG_SCOPE_LOCAL ;
665687 free_worktrees (worktrees );
666688 } else if (given_config_source .file ) {
667689 if (!is_absolute_path (given_config_source .file ) && prefix )
668690 given_config_source .file =
669691 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 ;
670695 }
671696
697+
672698 if (respect_includes_opt == -1 )
673699 config_options .respect_includes = !given_config_source .file ;
674700 else
@@ -678,7 +704,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
678704 config_options .git_dir = get_git_dir ();
679705 }
680706
681- if (end_null ) {
707+ if (end_nul ) {
682708 term = '\0' ;
683709 delim = '\n' ;
684710 key_delim = '\n' ;
0 commit comments