@@ -1454,13 +1454,15 @@ static char *get_maintpath(void)
1454
1454
}
1455
1455
1456
1456
static char const * const builtin_maintenance_register_usage [] = {
1457
- "git maintenance register" ,
1457
+ "git maintenance register [--config-file <path>] " ,
1458
1458
NULL
1459
1459
};
1460
1460
1461
1461
static int maintenance_register (int argc , const char * * argv , const char * prefix )
1462
1462
{
1463
+ char * config_file = NULL ;
1463
1464
struct option options [] = {
1465
+ OPT_STRING (0 , "config-file" , & config_file , N_ ("file" ), N_ ("use given config file" )),
1464
1466
OPT_END (),
1465
1467
};
1466
1468
int found = 0 ;
@@ -1497,12 +1499,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
1497
1499
1498
1500
if (!found ) {
1499
1501
int rc ;
1500
- char * user_config , * xdg_config ;
1501
- git_global_config (& user_config , & xdg_config );
1502
- if (!user_config )
1503
- die (_ ("$HOME not set" ));
1502
+ char * user_config = NULL , * xdg_config = NULL ;
1503
+
1504
+ if (!config_file ) {
1505
+ git_global_config (& user_config , & xdg_config );
1506
+ config_file = user_config ;
1507
+ if (!user_config )
1508
+ die (_ ("$HOME not set" ));
1509
+ }
1504
1510
rc = git_config_set_multivar_in_file_gently (
1505
- user_config , "maintenance.repo" , maintpath ,
1511
+ config_file , "maintenance.repo" , maintpath ,
1506
1512
CONFIG_REGEX_NONE , 0 );
1507
1513
free (user_config );
1508
1514
free (xdg_config );
@@ -1517,14 +1523,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
1517
1523
}
1518
1524
1519
1525
static char const * const builtin_maintenance_unregister_usage [] = {
1520
- "git maintenance unregister [--force]" ,
1526
+ "git maintenance unregister [--config-file <path>] [-- force]" ,
1521
1527
NULL
1522
1528
};
1523
1529
1524
1530
static int maintenance_unregister (int argc , const char * * argv , const char * prefix )
1525
1531
{
1526
1532
int force = 0 ;
1533
+ char * config_file = NULL ;
1527
1534
struct option options [] = {
1535
+ OPT_STRING (0 , "config-file" , & config_file , N_ ("file" ), N_ ("use given config file" )),
1528
1536
OPT__FORCE (& force ,
1529
1537
N_ ("return success even if repository was not registered" ),
1530
1538
PARSE_OPT_NOCOMPLETE ),
@@ -1542,7 +1550,14 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
1542
1550
usage_with_options (builtin_maintenance_unregister_usage ,
1543
1551
options );
1544
1552
1545
- list = git_config_get_value_multi (key );
1553
+ struct config_set cs ;
1554
+ if (config_file ) {
1555
+ git_configset_init (& cs );
1556
+ git_configset_add_file (& cs , config_file );
1557
+ list = git_configset_get_value_multi (& cs , key );
1558
+ } else {
1559
+ list = git_config_get_value_multi (key );
1560
+ }
1546
1561
if (list ) {
1547
1562
for_each_string_list_item (item , list ) {
1548
1563
if (!strcmp (maintpath , item -> string )) {
@@ -1554,12 +1569,15 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
1554
1569
1555
1570
if (found ) {
1556
1571
int rc ;
1557
- char * user_config , * xdg_config ;
1558
- git_global_config (& user_config , & xdg_config );
1559
- if (!user_config )
1560
- die (_ ("$HOME not set" ));
1572
+ char * user_config = NULL , * xdg_config = NULL ;
1573
+ if (!config_file ) {
1574
+ git_global_config (& user_config , & xdg_config );
1575
+ config_file = user_config ;
1576
+ if (!user_config )
1577
+ die (_ ("$HOME not set" ));
1578
+ }
1561
1579
rc = git_config_set_multivar_in_file_gently (
1562
- user_config , key , NULL , maintpath ,
1580
+ config_file , key , NULL , maintpath ,
1563
1581
CONFIG_FLAGS_MULTI_REPLACE | CONFIG_FLAGS_FIXED_VALUE );
1564
1582
free (user_config );
1565
1583
free (xdg_config );
@@ -1572,6 +1590,7 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
1572
1590
die (_ ("repository '%s' is not registered" ), maintpath );
1573
1591
}
1574
1592
1593
+ git_configset_clear (& cs );
1575
1594
free (maintpath );
1576
1595
return 0 ;
1577
1596
}
0 commit comments