From: Ronan Pigott <ronan@rjp.ie>
To: git@vger.kernel.org
Cc: me@ttaylor.com, derrickstolee@github.com
Subject: [PATCH v2 2/2] maintenance: add option to register in a specific config
Date: Tue, 8 Nov 2022 12:49:30 -0700 [thread overview]
Message-ID: <20221108194930.25805-3-ronan@rjp.ie> (raw)
In-Reply-To: <20221108194930.25805-1-ronan@rjp.ie>
maintenance register currently records the maintenance repo exclusively
within the user's global configuration, but other configuration files
may be relevant when running maintenance if they are included from the
global config. This option allows the user to choose where maintenance
repos are recorded.
Signed-off-by: Ronan Pigott <ronan@rjp.ie>
---
Documentation/git-maintenance.txt | 14 ++++-----
builtin/gc.c | 51 +++++++++++++++++++------------
t/t7900-maintenance.sh | 15 +++++++++
3 files changed, 54 insertions(+), 26 deletions(-)
diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt
index bb888690e4..eb3ae9fbd5 100644
--- a/Documentation/git-maintenance.txt
+++ b/Documentation/git-maintenance.txt
@@ -50,13 +50,13 @@ stop::
the background maintenance is restarted later.
register::
- Initialize Git config values so any scheduled maintenance will
- start running on this repository. This adds the repository to the
- `maintenance.repo` config variable in the current user's global
- config and enables some recommended configuration values for
- `maintenance.<task>.schedule`. The tasks that are enabled are safe
- for running in the background without disrupting foreground
- processes.
+ Initialize Git config values so any scheduled maintenance will start
+ running on this repository. This adds the repository to the
+ `maintenance.repo` config variable in the current user's global config,
+ or the config specified by --config option, and enables some
+ recommended configuration values for `maintenance.<task>.schedule`. The
+ tasks that are enabled are safe for running in the background without
+ disrupting foreground processes.
+
The `register` subcommand will also set the `maintenance.strategy` config
value to `incremental`, if this value is not previously set. The
diff --git a/builtin/gc.c b/builtin/gc.c
index 24ea85c7af..1709355bce 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1454,13 +1454,15 @@ static char *get_maintpath(void)
}
static char const * const builtin_maintenance_register_usage[] = {
- "git maintenance register",
+ "git maintenance register [--config-file <path>]",
NULL
};
static int maintenance_register(int argc, const char **argv, const char *prefix)
{
+ char *config_file = NULL;
struct option options[] = {
+ OPT_STRING(0, "config-file", &config_file, N_("file"), N_("use given config file")),
OPT_END(),
};
int found = 0;
@@ -1497,12 +1499,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
if (!found) {
int rc;
- char *user_config, *xdg_config;
- git_global_config(&user_config, &xdg_config);
- if (!user_config)
- die(_("$HOME not set"));
+ char *user_config = NULL, *xdg_config = NULL;
+
+ if (!config_file) {
+ git_global_config(&user_config, &xdg_config);
+ config_file = user_config;
+ if (!user_config)
+ die(_("$HOME not set"));
+ }
rc = git_config_set_multivar_in_file_gently(
- user_config, "maintenance.repo", maintpath,
+ config_file, "maintenance.repo", maintpath,
CONFIG_REGEX_NONE, 0);
free(user_config);
free(xdg_config);
@@ -1517,14 +1523,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
}
static char const * const builtin_maintenance_unregister_usage[] = {
- "git maintenance unregister [--force]",
+ "git maintenance unregister [--config-file <path>] [--force]",
NULL
};
static int maintenance_unregister(int argc, const char **argv, const char *prefix)
{
int force = 0;
+ char *config_file = NULL;
struct option options[] = {
+ OPT_STRING(0, "config-file", &config_file, N_("file"), N_("use given config file")),
OPT__FORCE(&force,
N_("return success even if repository was not registered"),
PARSE_OPT_NOCOMPLETE),
@@ -1542,24 +1550,29 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
usage_with_options(builtin_maintenance_unregister_usage,
options);
- list = git_config_get_value_multi(key);
- if (list) {
- for_each_string_list_item(item, list) {
- if (!strcmp(maintpath, item->string)) {
- found = 1;
- break;
+ if (!config_file) {
+ list = git_config_get_value_multi(key);
+ if (list) {
+ for_each_string_list_item(item, list) {
+ if (!strcmp(maintpath, item->string)) {
+ found = 1;
+ break;
+ }
}
}
}
- if (found) {
+ if (found || config_file) {
int rc;
- char *user_config, *xdg_config;
- git_global_config(&user_config, &xdg_config);
- if (!user_config)
- die(_("$HOME not set"));
+ char *user_config = NULL, *xdg_config = NULL;
+ if (!config_file) {
+ git_global_config(&user_config, &xdg_config);
+ config_file = user_config;
+ if (!user_config)
+ die(_("$HOME not set"));
+ }
rc = git_config_set_multivar_in_file_gently(
- user_config, key, NULL, maintpath,
+ config_file, key, NULL, maintpath,
CONFIG_FLAGS_MULTI_REPLACE | CONFIG_FLAGS_FIXED_VALUE);
free(user_config);
free(xdg_config);
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 96bdd42045..091da683a8 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -500,6 +500,21 @@ test_expect_success 'register and unregister' '
git config --global --get-all maintenance.repo >actual &&
test_cmp before actual &&
+ git config --file ./other --add maintenance.repo /existing1 &&
+ git config --file ./other --add maintenance.repo /existing2 &&
+ git config --file ./other --get-all maintenance.repo >before &&
+
+ git maintenance register --config-file ./other &&
+ test_cmp_config false maintenance.auto &&
+ git config --file ./other --get-all maintenance.repo >between &&
+ cp before expect &&
+ pwd >>expect &&
+ test_cmp expect between &&
+
+ git maintenance unregister --config-file ./other &&
+ git config --file ./other --get-all maintenance.repo >actual &&
+ test_cmp before actual &&
+
test_must_fail git maintenance unregister 2>err &&
grep "is not registered" err &&
git maintenance unregister --force
--
2.38.1
next prev parent reply other threads:[~2022-11-08 19:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 19:49 [PATCH v2 0/2] git-maintenance quality-of-life improvements Ronan Pigott
2022-11-08 19:49 ` [PATCH v2 1/2] for-each-repo: interpolate repo path arguments Ronan Pigott
2022-11-08 19:49 ` Ronan Pigott [this message]
2022-11-08 20:38 ` [PATCH v2 2/2] maintenance: add option to register in a specific config Phillip Wood
2022-11-08 20:57 ` Taylor Blau
2022-11-08 21:28 ` Phillip Wood
2022-11-08 22:45 ` ronan
2022-11-09 15:05 ` Derrick Stolee
2022-11-10 2:38 ` Taylor Blau
2022-11-08 19:54 ` [PATCH v2 0/2] git-maintenance quality-of-life improvements Taylor Blau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221108194930.25805-3-ronan@rjp.ie \
--to=ronan@rjp.ie \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=me@ttaylor.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).