@@ -1480,13 +1480,15 @@ static char *get_maintpath(void)
14801480}
14811481
14821482static char const * const builtin_maintenance_register_usage [] = {
1483- "git maintenance register" ,
1483+ "git maintenance register [--config-file <path>] " ,
14841484 NULL
14851485};
14861486
14871487static int maintenance_register (int argc , const char * * argv , const char * prefix )
14881488{
1489+ char * config_file = NULL ;
14891490 struct option options [] = {
1491+ OPT_STRING (0 , "config-file" , & config_file , N_ ("file" ), N_ ("use given config file" )),
14901492 OPT_END (),
14911493 };
14921494 int found = 0 ;
@@ -1523,12 +1525,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
15231525
15241526 if (!found ) {
15251527 int rc ;
1526- char * user_config , * xdg_config ;
1527- git_global_config (& user_config , & xdg_config );
1528- if (!user_config )
1529- die (_ ("$HOME not set" ));
1528+ char * user_config = NULL , * xdg_config = NULL ;
1529+
1530+ if (!config_file ) {
1531+ git_global_config (& user_config , & xdg_config );
1532+ config_file = user_config ;
1533+ if (!user_config )
1534+ die (_ ("$HOME not set" ));
1535+ }
15301536 rc = git_config_set_multivar_in_file_gently (
1531- user_config , "maintenance.repo" , maintpath ,
1537+ config_file , "maintenance.repo" , maintpath ,
15321538 CONFIG_REGEX_NONE , 0 );
15331539 free (user_config );
15341540 free (xdg_config );
@@ -1543,14 +1549,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
15431549}
15441550
15451551static char const * const builtin_maintenance_unregister_usage [] = {
1546- "git maintenance unregister [--force]" ,
1552+ "git maintenance unregister [--config-file <path>] [-- force]" ,
15471553 NULL
15481554};
15491555
15501556static int maintenance_unregister (int argc , const char * * argv , const char * prefix )
15511557{
15521558 int force = 0 ;
1559+ char * config_file = NULL ;
15531560 struct option options [] = {
1561+ OPT_STRING (0 , "config-file" , & config_file , N_ ("file" ), N_ ("use given config file" )),
15541562 OPT__FORCE (& force ,
15551563 N_ ("return success even if repository was not registered" ),
15561564 PARSE_OPT_NOCOMPLETE ),
@@ -1561,14 +1569,21 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
15611569 int found = 0 ;
15621570 struct string_list_item * item ;
15631571 const struct string_list * list ;
1572+ struct config_set cs = { { 0 } };
15641573
15651574 argc = parse_options (argc , argv , prefix , options ,
15661575 builtin_maintenance_unregister_usage , 0 );
15671576 if (argc )
15681577 usage_with_options (builtin_maintenance_unregister_usage ,
15691578 options );
15701579
1571- list = git_config_get_value_multi (key );
1580+ if (config_file ) {
1581+ git_configset_init (& cs );
1582+ git_configset_add_file (& cs , config_file );
1583+ list = git_configset_get_value_multi (& cs , key );
1584+ } else {
1585+ list = git_config_get_value_multi (key );
1586+ }
15721587 if (list ) {
15731588 for_each_string_list_item (item , list ) {
15741589 if (!strcmp (maintpath , item -> string )) {
@@ -1580,12 +1595,15 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
15801595
15811596 if (found ) {
15821597 int rc ;
1583- char * user_config , * xdg_config ;
1584- git_global_config (& user_config , & xdg_config );
1585- if (!user_config )
1586- die (_ ("$HOME not set" ));
1598+ char * user_config = NULL , * xdg_config = NULL ;
1599+ if (!config_file ) {
1600+ git_global_config (& user_config , & xdg_config );
1601+ config_file = user_config ;
1602+ if (!user_config )
1603+ die (_ ("$HOME not set" ));
1604+ }
15871605 rc = git_config_set_multivar_in_file_gently (
1588- user_config , key , NULL , maintpath ,
1606+ config_file , key , NULL , maintpath ,
15891607 CONFIG_FLAGS_MULTI_REPLACE | CONFIG_FLAGS_FIXED_VALUE );
15901608 free (user_config );
15911609 free (xdg_config );
@@ -1598,6 +1616,7 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
15981616 die (_ ("repository '%s' is not registered" ), maintpath );
15991617 }
16001618
1619+ git_configset_clear (& cs );
16011620 free (maintpath );
16021621 return 0 ;
16031622}
0 commit comments