@@ -24,6 +24,7 @@ struct config_source {
2424 size_t pos ;
2525 } buf ;
2626 } u ;
27+ const char * origin_type ;
2728 const char * name ;
2829 const char * path ;
2930 int die_on_error ;
@@ -471,9 +472,9 @@ static int git_parse_source(config_fn_t fn, void *data)
471472 break ;
472473 }
473474 if (cf -> die_on_error )
474- die (_ ("bad config file line %d in %s" ), cf -> linenr , cf -> name );
475+ die (_ ("bad config line %d in %s %s " ), cf -> linenr , cf -> origin_type , cf -> name );
475476 else
476- return error (_ ("bad config file line %d in %s" ), cf -> linenr , cf -> name );
477+ return error (_ ("bad config line %d in %s %s " ), cf -> linenr , cf -> origin_type , cf -> name );
477478}
478479
479480static int parse_unit_factor (const char * end , uintmax_t * val )
@@ -588,9 +589,9 @@ static void die_bad_number(const char *name, const char *value)
588589 if (!value )
589590 value = "" ;
590591
591- if (cf && cf -> name )
592- die (_ ("bad numeric config value '%s' for '%s' in %s: %s" ),
593- value , name , cf -> name , reason );
592+ if (cf && cf -> origin_type && cf -> name )
593+ die (_ ("bad numeric config value '%s' for '%s' in %s %s : %s" ),
594+ value , name , cf -> origin_type , cf -> name , reason );
594595 die (_ ("bad numeric config value '%s' for '%s': %s" ), value , name , reason );
595596}
596597
@@ -1061,11 +1062,13 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data)
10611062}
10621063
10631064static int do_config_from_file (config_fn_t fn ,
1064- const char * name , const char * path , FILE * f , void * data )
1065+ const char * origin_type , const char * name , const char * path , FILE * f ,
1066+ void * data )
10651067{
10661068 struct config_source top ;
10671069
10681070 top .u .file = f ;
1071+ top .origin_type = origin_type ;
10691072 top .name = name ;
10701073 top .path = path ;
10711074 top .die_on_error = 1 ;
@@ -1078,7 +1081,7 @@ static int do_config_from_file(config_fn_t fn,
10781081
10791082static int git_config_from_stdin (config_fn_t fn , void * data )
10801083{
1081- return do_config_from_file (fn , "<stdin> " , NULL , stdin , data );
1084+ return do_config_from_file (fn , "standard input" , " " , NULL , stdin , data );
10821085}
10831086
10841087int git_config_from_file (config_fn_t fn , const char * filename , void * data )
@@ -1089,21 +1092,22 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
10891092 f = fopen (filename , "r" );
10901093 if (f ) {
10911094 flockfile (f );
1092- ret = do_config_from_file (fn , filename , filename , f , data );
1095+ ret = do_config_from_file (fn , "file" , filename , filename , f , data );
10931096 funlockfile (f );
10941097 fclose (f );
10951098 }
10961099 return ret ;
10971100}
10981101
1099- int git_config_from_buf (config_fn_t fn , const char * name , const char * buf ,
1100- size_t len , void * data )
1102+ int git_config_from_mem (config_fn_t fn , const char * origin_type ,
1103+ const char * name , const char * buf , size_t len , void * data )
11011104{
11021105 struct config_source top ;
11031106
11041107 top .u .buf .buf = buf ;
11051108 top .u .buf .len = len ;
11061109 top .u .buf .pos = 0 ;
1110+ top .origin_type = origin_type ;
11071111 top .name = name ;
11081112 top .path = NULL ;
11091113 top .die_on_error = 0 ;
@@ -1132,7 +1136,7 @@ static int git_config_from_blob_sha1(config_fn_t fn,
11321136 return error ("reference '%s' does not point to a blob" , name );
11331137 }
11341138
1135- ret = git_config_from_buf (fn , name , buf , size , data );
1139+ ret = git_config_from_mem (fn , "blob" , name , buf , size , data );
11361140 free (buf );
11371141
11381142 return ret ;
@@ -2407,3 +2411,13 @@ int parse_config_key(const char *var,
24072411
24082412 return 0 ;
24092413}
2414+
2415+ const char * current_config_origin_type (void )
2416+ {
2417+ return cf && cf -> origin_type ? cf -> origin_type : "command line" ;
2418+ }
2419+
2420+ const char * current_config_name (void )
2421+ {
2422+ return cf && cf -> name ? cf -> name : "" ;
2423+ }
0 commit comments