git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] git-maintenance quality-of-life improvements
@ 2022-11-05 18:45 Ronan Pigott
  2022-11-05 18:45 ` [PATCH 1/2] for-each-repo: interpolate repo path arguments Ronan Pigott
  2022-11-05 18:45 ` [PATCH 2/2] maintenance: add option to register in a specific config Ronan Pigott
  0 siblings, 2 replies; 8+ messages in thread
From: Ronan Pigott @ 2022-11-05 18:45 UTC (permalink / raw)
  To: git

This is a pair of quality-of-life patches for git-maintenance that have
helped me in my workflow. PTAL.

Ronan Pigott (2):
  for-each-repo: interpolate repo path arguments
  maintenance: add option to register in a specific config

 Documentation/git-maintenance.txt | 14 +++++++-------
 builtin/for-each-repo.c           |  5 ++++-
 builtin/gc.c                      | 28 +++++++++++++++++-----------
 t/t7900-maintenance.sh            | 15 +++++++++++++++
 4 files changed, 43 insertions(+), 19 deletions(-)

-- 
2.38.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] for-each-repo: interpolate repo path arguments
  2022-11-05 18:45 [PATCH 0/2] git-maintenance quality-of-life improvements Ronan Pigott
@ 2022-11-05 18:45 ` Ronan Pigott
  2022-11-06  0:30   ` Taylor Blau
  2022-11-05 18:45 ` [PATCH 2/2] maintenance: add option to register in a specific config Ronan Pigott
  1 sibling, 1 reply; 8+ messages in thread
From: Ronan Pigott @ 2022-11-05 18:45 UTC (permalink / raw)
  To: git; +Cc: Derrick Stolee, Andrzej Hunt, Junio C Hamano, Andrzej Hunt

This is a quality of life change for git-maintenance, so repos can be
recorded with the tilde syntax. The register subcommand will not record
repos in this format by default.

Signed-off-by: Ronan Pigott <ronan@rjp.ie>
---
 builtin/for-each-repo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index d45d873f57..6aeac37148 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -14,13 +14,16 @@ static int run_command_on_repo(const char *path, int argc, const char ** argv)
 {
 	int i;
 	struct child_process child = CHILD_PROCESS_INIT;
+	char *abspath = interpolate_path(path, 0);
 
 	child.git_cmd = 1;
-	strvec_pushl(&child.args, "-C", path, NULL);
+	strvec_pushl(&child.args, "-C", abspath, NULL);
 
 	for (i = 0; i < argc; i++)
 		strvec_push(&child.args, argv[i]);
 
+	free(abspath);
+
 	return run_command(&child);
 }
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] maintenance: add option to register in a specific config
  2022-11-05 18:45 [PATCH 0/2] git-maintenance quality-of-life improvements Ronan Pigott
  2022-11-05 18:45 ` [PATCH 1/2] for-each-repo: interpolate repo path arguments Ronan Pigott
@ 2022-11-05 18:45 ` Ronan Pigott
  2022-11-06  0:28   ` Taylor Blau
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Ronan Pigott @ 2022-11-05 18:45 UTC (permalink / raw)
  To: git
  Cc: Jeff King, Eric Sunshine, Clement Moyroud, Derrick Stolee,
	Alex Henrie, Junio C Hamano, SZEDER Gábor, Martin Ågren,
	Thomas Ackermann

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>
---

I track my global config in a bare gitrepo, and include host-specific
configuration from an auxiliary path. Since on each host I may work on
different repos, at different paths, and have different preferences for
prefetch or gc frequency, I record maintenance repos in this
host-specific config. This option will facilitate this use case.

 Documentation/git-maintenance.txt | 14 +++++++-------
 builtin/gc.c                      | 28 +++++++++++++++++-----------
 t/t7900-maintenance.sh            | 15 +++++++++++++++
 3 files changed, 39 insertions(+), 18 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..5da6905033 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>]",
 	NULL
 };
 
 static int maintenance_register(int argc, const char **argv, const char *prefix)
 {
+	const char *config_file = NULL;
 	struct option options[] = {
+		OPT_STRING('c', "config", &config_file, N_("file"), N_("use given config file")),
 		OPT_END(),
 	};
 	int found = 0;
@@ -1502,7 +1504,7 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
 		if (!user_config)
 			die(_("$HOME not set"));
 		rc = git_config_set_multivar_in_file_gently(
-			user_config, "maintenance.repo", maintpath,
+			config_file ?: user_config, "maintenance.repo", maintpath,
 			CONFIG_REGEX_NONE, 0);
 		free(user_config);
 		free(xdg_config);
@@ -1517,14 +1519,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>] [--force]",
 	NULL
 };
 
 static int maintenance_unregister(int argc, const char **argv, const char *prefix)
 {
 	int force = 0;
+	const char *config_file = NULL;
 	struct option options[] = {
+		OPT_STRING('c', "config", &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 +1546,26 @@ 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"));
 		rc = git_config_set_multivar_in_file_gently(
-			user_config, key, NULL, maintpath,
+			config_file ?: user_config, 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..c2c2dbbb5f 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 ./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 ./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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] maintenance: add option to register in a specific config
  2022-11-05 18:45 ` [PATCH 2/2] maintenance: add option to register in a specific config Ronan Pigott
@ 2022-11-06  0:28   ` Taylor Blau
  2022-11-06  0:42   ` Taylor Blau
  2022-11-07 20:49   ` Derrick Stolee
  2 siblings, 0 replies; 8+ messages in thread
From: Taylor Blau @ 2022-11-06  0:28 UTC (permalink / raw)
  To: Ronan Pigott
  Cc: git, Jeff King, Eric Sunshine, Clement Moyroud, Derrick Stolee,
	Alex Henrie, Junio C Hamano, SZEDER Gábor, Martin Ågren,
	Thomas Ackermann

On Sat, Nov 05, 2022 at 11:45:32AM -0700, Ronan Pigott wrote:
> @@ -1502,7 +1504,7 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
>  		if (!user_config)
>  			die(_("$HOME not set"));
>  		rc = git_config_set_multivar_in_file_gently(
> -			user_config, "maintenance.repo", maintpath,
> +			config_file ?: user_config, "maintenance.repo", maintpath,
>  			CONFIG_REGEX_NONE, 0);
>  		free(user_config);
>  		free(xdg_config);

The "?:" construct is a GNU extension which we do not use.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] for-each-repo: interpolate repo path arguments
  2022-11-05 18:45 ` [PATCH 1/2] for-each-repo: interpolate repo path arguments Ronan Pigott
@ 2022-11-06  0:30   ` Taylor Blau
  2022-11-07 20:46     ` Derrick Stolee
  0 siblings, 1 reply; 8+ messages in thread
From: Taylor Blau @ 2022-11-06  0:30 UTC (permalink / raw)
  To: Ronan Pigott
  Cc: git, Derrick Stolee, Andrzej Hunt, Junio C Hamano, Andrzej Hunt

On Sat, Nov 05, 2022 at 11:45:31AM -0700, Ronan Pigott wrote:
> This is a quality of life change for git-maintenance, so repos can be
> recorded with the tilde syntax. The register subcommand will not record
> repos in this format by default.
>
> Signed-off-by: Ronan Pigott <ronan@rjp.ie>
> ---
>  builtin/for-each-repo.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Seems reasonable. So the 'register' subcommand will never write a record
that isn't an absolute path, but a user may manually munge the
maintenance configuration and we want to err on the side of flexibility.

OK, sounds good. Missing test, though?

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] maintenance: add option to register in a specific config
  2022-11-05 18:45 ` [PATCH 2/2] maintenance: add option to register in a specific config Ronan Pigott
  2022-11-06  0:28   ` Taylor Blau
@ 2022-11-06  0:42   ` Taylor Blau
  2022-11-07 20:49   ` Derrick Stolee
  2 siblings, 0 replies; 8+ messages in thread
From: Taylor Blau @ 2022-11-06  0:42 UTC (permalink / raw)
  To: Ronan Pigott
  Cc: git, Jeff King, Eric Sunshine, Clement Moyroud, Derrick Stolee,
	Alex Henrie, Junio C Hamano, SZEDER Gábor, Martin Ågren,
	Thomas Ackermann

On Sat, Nov 05, 2022 at 11:45:32AM -0700, Ronan Pigott wrote:
> 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.

I see. So we don't change the location of the config that 'maintenance
run/start' are reading from, but we can change the location of the
config we use to record which repositories are maintenance candidates.

I guess it makes sense if you are including arbitrary configuration
files in your global config, so this seems reasonable to me.

> Signed-off-by: Ronan Pigott <ronan@rjp.ie>
> ---
>
> I track my global config in a bare gitrepo, and include host-specific
> configuration from an auxiliary path. Since on each host I may work on
> different repos, at different paths, and have different preferences for
> prefetch or gc frequency, I record maintenance repos in this
> host-specific config. This option will facilitate this use case.
>
>  Documentation/git-maintenance.txt | 14 +++++++-------
>  builtin/gc.c                      | 28 +++++++++++++++++-----------
>  t/t7900-maintenance.sh            | 15 +++++++++++++++
>  3 files changed, 39 insertions(+), 18 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 new text looks good, but there is some unnecessary line re-wrapping
that occurred around it.

>  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..5da6905033 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>" (instead of "<file>") is slightly more common these days.

>  	NULL
>  };
>
>  static int maintenance_register(int argc, const char **argv, const char *prefix)
>  {
> +	const char *config_file = NULL;
>  	struct option options[] = {
> +		OPT_STRING('c', "config", &config_file, N_("file"), N_("use given config file")),
>  		OPT_END(),
>  	};
>  	int found = 0;
> @@ -1502,7 +1504,7 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
>  		if (!user_config)
>  			die(_("$HOME not set"));

Hmm. I wonder if we want to avoid calling git_global_config() when we
don't need to. Maybe something like this:

--- >8 ---
diff --git a/builtin/gc.c b/builtin/gc.c
index 5da6905033..13a2633912 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1460,7 +1460,7 @@ static char const * const builtin_maintenance_register_usage[] = {

 static int maintenance_register(int argc, const char **argv, const char *prefix)
 {
-	const char *config_file = NULL;
+	char *config_file = NULL;
 	struct option options[] = {
 		OPT_STRING('c', "config", &config_file, N_("file"), N_("use given config file")),
 		OPT_END(),
@@ -1499,14 +1499,21 @@ 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;
+		char *to_free = NULL;
+
+		if (config_file) {
+			user_config = config_file;
+		} else {
+			git_global_config(&user_config, &xdg_config);
+			to_free = user_config;
+			if (!user_config)
+				die(_("$HOME not set"));
+		}
 		rc = git_config_set_multivar_in_file_gently(
-			config_file ?: user_config, "maintenance.repo", maintpath,
+			user_config, "maintenance.repo", maintpath,
 			CONFIG_REGEX_NONE, 0);
-		free(user_config);
+		free(to_free);
 		free(xdg_config);

 		if (rc)
--- 8< ---

> -			user_config, key, NULL, maintpath,
> +			config_file ?: user_config, key, NULL, maintpath,

Same note(s) here, too.

> @@ -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 &&

I was wondering why you didn't bother writing all of this into "expect",
and then appending "pwd" onto the end of it.

> +	git maintenance register --config ./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 &&

...since it would have simplified the setup here.

> +	git maintenance unregister --config ./other &&
> +	git config --file ./other --get-all maintenance.repo >actual &&
> +	test_cmp before actual &&

...but here you want to compare the output you got above with everything
that was configured before, i.e., just what came out of the first three
lines. Makes sense.

Thanks,
Taylor

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] for-each-repo: interpolate repo path arguments
  2022-11-06  0:30   ` Taylor Blau
@ 2022-11-07 20:46     ` Derrick Stolee
  0 siblings, 0 replies; 8+ messages in thread
From: Derrick Stolee @ 2022-11-07 20:46 UTC (permalink / raw)
  To: Taylor Blau, Ronan Pigott; +Cc: git, Andrzej Hunt, Junio C Hamano, Andrzej Hunt

On 11/5/22 8:30 PM, Taylor Blau wrote:
> On Sat, Nov 05, 2022 at 11:45:31AM -0700, Ronan Pigott wrote:
>> This is a quality of life change for git-maintenance, so repos can be
>> recorded with the tilde syntax. The register subcommand will not record
>> repos in this format by default.
>>
>> Signed-off-by: Ronan Pigott <ronan@rjp.ie>
>> ---
>>  builtin/for-each-repo.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> Seems reasonable. So the 'register' subcommand will never write a record
> that isn't an absolute path, but a user may manually munge the
> maintenance configuration and we want to err on the side of flexibility.
> 
> OK, sounds good. Missing test, though?

I agree that this implementation looks good, but a test
would be helpful to be sure.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] maintenance: add option to register in a specific config
  2022-11-05 18:45 ` [PATCH 2/2] maintenance: add option to register in a specific config Ronan Pigott
  2022-11-06  0:28   ` Taylor Blau
  2022-11-06  0:42   ` Taylor Blau
@ 2022-11-07 20:49   ` Derrick Stolee
  2 siblings, 0 replies; 8+ messages in thread
From: Derrick Stolee @ 2022-11-07 20:49 UTC (permalink / raw)
  To: Ronan Pigott, git
  Cc: Jeff King, Eric Sunshine, Clement Moyroud, Alex Henrie,
	Junio C Hamano, SZEDER Gábor, Martin Ågren,
	Thomas Ackermann

On 11/5/22 2:45 PM, Ronan Pigott wrote:
> 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.

Taylor already provided most of the feedback that I would have given.

>  static char const * const builtin_maintenance_register_usage[] = {
> -	"git maintenance register",
> +	"git maintenance register [--config <file>]",

The only recommendation I have remaining is to rename this option to
`--config-file=<file>` since it is unclear from just "--config" if it
is a config _file_ or a config _key_.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-07 20:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-05 18:45 [PATCH 0/2] git-maintenance quality-of-life improvements Ronan Pigott
2022-11-05 18:45 ` [PATCH 1/2] for-each-repo: interpolate repo path arguments Ronan Pigott
2022-11-06  0:30   ` Taylor Blau
2022-11-07 20:46     ` Derrick Stolee
2022-11-05 18:45 ` [PATCH 2/2] maintenance: add option to register in a specific config Ronan Pigott
2022-11-06  0:28   ` Taylor Blau
2022-11-06  0:42   ` Taylor Blau
2022-11-07 20:49   ` Derrick Stolee

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).