{"thread":{"id":"58780","subject":"[PATCH v3 0/2] git-maintenance quality-of-life improvements","startedAt":"2022-11-09T19:07:27Z","lastAt":"2022-11-09T21:25:10Z","messageCount":4,"participants":["Ronan Pigott","Taylor Blau"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"466976","messageId":"20221109190708.22725-1-ronan@rjp.ie","threadId":"58780","inReplyTo":null,"subject":"[PATCH v3 0/2] git-maintenance quality-of-life improvements","fromName":"Ronan Pigott","fromEmail":"ronan@rjp.ie","sentAt":"2022-11-09T19:07:06Z","receivedAt":"2022-11-09T19:07:27Z","isPatch":true,"sender":{"key":"ronan@rjp.ie","avatar":"https://avatars.githubusercontent.com/u/12577529?v=4"},"body":"This is a pair of quality-of-life patches for git-maintenance that have\nhelped me in my workflow. PTAL.\n\nChanges in v2:\n - Added a test case for path interpolation in for-each-repo\n - Changed [--config <file>] to [--config-file <path>] in\n   register/unregister\n - Dropped the short-name option, -c\n - Avoid finding the global config when the user has supplied the config\n   on the command line\n\nChanges in v3:\n - Report an error in unregister when the user specifies a config where\n   the repo is not already registered\n - Add a test case for the above\n - Correct option description in the docs\n\nRonan Pigott (2):\n  for-each-repo: interpolate repo path arguments\n  maintenance: add option to register in a specific config\n\n Documentation/git-maintenance.txt | 14 +++++-----\n builtin/for-each-repo.c           |  5 +++-\n builtin/gc.c                      | 45 ++++++++++++++++++++++---------\n t/t0068-for-each-repo.sh          |  6 +++++\n t/t7900-maintenance.sh            | 21 ++++++++++++++-\n 5 files changed, 69 insertions(+), 22 deletions(-)\n\n-- \n2.38.1\n\n"},{"id":"466977","messageId":"20221109190708.22725-2-ronan@rjp.ie","threadId":"58780","inReplyTo":"20221109190708.22725-1-ronan@rjp.ie","subject":"[PATCH v3 1/2] for-each-repo: interpolate repo path arguments","fromName":"Ronan Pigott","fromEmail":"ronan@rjp.ie","sentAt":"2022-11-09T19:07:07Z","receivedAt":"2022-11-09T19:07:28Z","isPatch":true,"sender":{"key":"ronan@rjp.ie","avatar":"https://avatars.githubusercontent.com/u/12577529?v=4"},"body":"This is a quality of life change for git-maintenance, so repos can be\nrecorded with the tilde syntax. The register subcommand will not record\nrepos in this format by default.\n\nSigned-off-by: Ronan Pigott <ronan@rjp.ie>\n---\n builtin/for-each-repo.c  | 5 ++++-\n t/t0068-for-each-repo.sh | 6 ++++++\n 2 files changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c\nindex d45d873f57..6aeac37148 100644\n--- a/builtin/for-each-repo.c\n+++ b/builtin/for-each-repo.c\n@@ -14,13 +14,16 @@ static int run_command_on_repo(const char *path, int argc, const char ** argv)\n {\n \tint i;\n \tstruct child_process child = CHILD_PROCESS_INIT;\n+\tchar *abspath = interpolate_path(path, 0);\n \n \tchild.git_cmd = 1;\n-\tstrvec_pushl(&child.args, \"-C\", path, NULL);\n+\tstrvec_pushl(&child.args, \"-C\", abspath, NULL);\n \n \tfor (i = 0; i < argc; i++)\n \t\tstrvec_push(&child.args, argv[i]);\n \n+\tfree(abspath);\n+\n \treturn run_command(&child);\n }\n \ndiff --git a/t/t0068-for-each-repo.sh b/t/t0068-for-each-repo.sh\nindex 4675e85251..c6e0d65563 100755\n--- a/t/t0068-for-each-repo.sh\n+++ b/t/t0068-for-each-repo.sh\n@@ -8,9 +8,11 @@ test_expect_success 'run based on configured value' '\n \tgit init one &&\n \tgit init two &&\n \tgit init three &&\n+\tgit init ~/four &&\n \tgit -C two commit --allow-empty -m \"DID NOT RUN\" &&\n \tgit config run.key \"$TRASH_DIRECTORY/one\" &&\n \tgit config --add run.key \"$TRASH_DIRECTORY/three\" &&\n+\tgit config --add run.key \"~/four\" &&\n \tgit for-each-repo --config=run.key commit --allow-empty -m \"ran\" &&\n \tgit -C one log -1 --pretty=format:%s >message &&\n \tgrep ran message &&\n@@ -18,12 +20,16 @@ test_expect_success 'run based on configured value' '\n \t! grep ran message &&\n \tgit -C three log -1 --pretty=format:%s >message &&\n \tgrep ran message &&\n+\tgit -C ~/four log -1 --pretty=format:%s >message &&\n+\tgrep ran message &&\n \tgit for-each-repo --config=run.key -- commit --allow-empty -m \"ran again\" &&\n \tgit -C one log -1 --pretty=format:%s >message &&\n \tgrep again message &&\n \tgit -C two log -1 --pretty=format:%s >message &&\n \t! grep again message &&\n \tgit -C three log -1 --pretty=format:%s >message &&\n+\tgrep again message &&\n+\tgit -C ~/four log -1 --pretty=format:%s >message &&\n \tgrep again message\n '\n \n-- \n2.38.1\n\n"},{"id":"466978","messageId":"20221109190708.22725-3-ronan@rjp.ie","threadId":"58780","inReplyTo":"20221109190708.22725-1-ronan@rjp.ie","subject":"[PATCH v3 2/2] maintenance: add option to register in a specific config","fromName":"Ronan Pigott","fromEmail":"ronan@rjp.ie","sentAt":"2022-11-09T19:07:08Z","receivedAt":"2022-11-09T19:07:30Z","isPatch":true,"sender":{"key":"ronan@rjp.ie","avatar":"https://avatars.githubusercontent.com/u/12577529?v=4"},"body":"maintenance register currently records the maintenance repo exclusively\nwithin the user's global configuration, but other configuration files\nmay be relevant when running maintenance if they are included from the\nglobal config. This option allows the user to choose where maintenance\nrepos are recorded.\n\nSigned-off-by: Ronan Pigott <ronan@rjp.ie>\n---\n Documentation/git-maintenance.txt | 14 +++++-----\n builtin/gc.c                      | 45 ++++++++++++++++++++++---------\n t/t7900-maintenance.sh            | 21 ++++++++++++++-\n 3 files changed, 59 insertions(+), 21 deletions(-)\n\ndiff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt\nindex bb888690e4..805e5a2e3a 100644\n--- a/Documentation/git-maintenance.txt\n+++ b/Documentation/git-maintenance.txt\n@@ -50,13 +50,13 @@ stop::\n \tthe background maintenance is restarted later.\n \n register::\n-\tInitialize Git config values so any scheduled maintenance will\n-\tstart running on this repository. This adds the repository to the\n-\t`maintenance.repo` config variable in the current user's global\n-\tconfig and enables some recommended configuration values for\n-\t`maintenance.<task>.schedule`. The tasks that are enabled are safe\n-\tfor running in the background without disrupting foreground\n-\tprocesses.\n+\tInitialize Git config values so any scheduled maintenance will start\n+\trunning on this repository. This adds the repository to the\n+\t`maintenance.repo` config variable in the current user's global config,\n+\tor the config specified by --config-file option, and enables some\n+\trecommended configuration values for `maintenance.<task>.schedule`. The\n+\ttasks that are enabled are safe for running in the background without\n+\tdisrupting foreground processes.\n +\n The `register` subcommand will also set the `maintenance.strategy` config\n value to `incremental`, if this value is not previously set. The\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 24ea85c7af..56b107e7f0 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -1454,13 +1454,15 @@ static char *get_maintpath(void)\n }\n \n static char const * const builtin_maintenance_register_usage[] = {\n-\t\"git maintenance register\",\n+\t\"git maintenance register [--config-file <path>]\",\n \tNULL\n };\n \n static int maintenance_register(int argc, const char **argv, const char *prefix)\n {\n+\tchar *config_file = NULL;\n \tstruct option options[] = {\n+\t\tOPT_STRING(0, \"config-file\", &config_file, N_(\"file\"), N_(\"use given config file\")),\n \t\tOPT_END(),\n \t};\n \tint found = 0;\n@@ -1497,12 +1499,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)\n \n \tif (!found) {\n \t\tint rc;\n-\t\tchar *user_config, *xdg_config;\n-\t\tgit_global_config(&user_config, &xdg_config);\n-\t\tif (!user_config)\n-\t\t\tdie(_(\"$HOME not set\"));\n+\t\tchar *user_config = NULL, *xdg_config = NULL;\n+\n+\t\tif (!config_file) {\n+\t\t\tgit_global_config(&user_config, &xdg_config);\n+\t\t\tconfig_file = user_config;\n+\t\t\tif (!user_config)\n+\t\t\t\tdie(_(\"$HOME not set\"));\n+\t\t}\n \t\trc = git_config_set_multivar_in_file_gently(\n-\t\t\tuser_config, \"maintenance.repo\", maintpath,\n+\t\t\tconfig_file, \"maintenance.repo\", maintpath,\n \t\t\tCONFIG_REGEX_NONE, 0);\n \t\tfree(user_config);\n \t\tfree(xdg_config);\n@@ -1517,14 +1523,16 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)\n }\n \n static char const * const builtin_maintenance_unregister_usage[] = {\n-\t\"git maintenance unregister [--force]\",\n+\t\"git maintenance unregister [--config-file <path>] [--force]\",\n \tNULL\n };\n \n static int maintenance_unregister(int argc, const char **argv, const char *prefix)\n {\n \tint force = 0;\n+\tchar *config_file = NULL;\n \tstruct option options[] = {\n+\t\tOPT_STRING(0, \"config-file\", &config_file, N_(\"file\"), N_(\"use given config file\")),\n \t\tOPT__FORCE(&force,\n \t\t\t   N_(\"return success even if repository was not registered\"),\n \t\t\t   PARSE_OPT_NOCOMPLETE),\n@@ -1542,7 +1550,14 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi\n \t\tusage_with_options(builtin_maintenance_unregister_usage,\n \t\t\t\t   options);\n \n-\tlist = git_config_get_value_multi(key);\n+\tstruct config_set cs;\n+\tif (config_file) {\n+\t\tgit_configset_init(&cs);\n+\t\tgit_configset_add_file(&cs, config_file);\n+\t\tlist = git_configset_get_value_multi(&cs, key);\n+\t} else {\n+\t\tlist = git_config_get_value_multi(key);\n+\t}\n \tif (list) {\n \t\tfor_each_string_list_item(item, list) {\n \t\t\tif (!strcmp(maintpath, item->string)) {\n@@ -1554,12 +1569,15 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi\n \n \tif (found) {\n \t\tint rc;\n-\t\tchar *user_config, *xdg_config;\n-\t\tgit_global_config(&user_config, &xdg_config);\n-\t\tif (!user_config)\n-\t\t\tdie(_(\"$HOME not set\"));\n+\t\tchar *user_config = NULL, *xdg_config = NULL;\n+\t\tif (!config_file) {\n+\t\t\tgit_global_config(&user_config, &xdg_config);\n+\t\t\tconfig_file = user_config;\n+\t\t\tif (!user_config)\n+\t\t\t\tdie(_(\"$HOME not set\"));\n+\t\t}\n \t\trc = git_config_set_multivar_in_file_gently(\n-\t\t\tuser_config, key, NULL, maintpath,\n+\t\t\tconfig_file, key, NULL, maintpath,\n \t\t\tCONFIG_FLAGS_MULTI_REPLACE | CONFIG_FLAGS_FIXED_VALUE);\n \t\tfree(user_config);\n \t\tfree(xdg_config);\n@@ -1572,6 +1590,7 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi\n \t\tdie(_(\"repository '%s' is not registered\"), maintpath);\n \t}\n \n+\tgit_configset_clear(&cs);\n \tfree(maintpath);\n \treturn 0;\n }\ndiff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh\nindex 96bdd42045..823331e44a 100755\n--- a/t/t7900-maintenance.sh\n+++ b/t/t7900-maintenance.sh\n@@ -500,9 +500,28 @@ test_expect_success 'register and unregister' '\n \tgit config --global --get-all maintenance.repo >actual &&\n \ttest_cmp before actual &&\n \n+\tgit config --file ./other --add maintenance.repo /existing1 &&\n+\tgit config --file ./other --add maintenance.repo /existing2 &&\n+\tgit config --file ./other --get-all maintenance.repo >before &&\n+\n+\tgit maintenance register --config-file ./other &&\n+\ttest_cmp_config false maintenance.auto &&\n+\tgit config --file ./other --get-all maintenance.repo >between &&\n+\tcp before expect &&\n+\tpwd >>expect &&\n+\ttest_cmp expect between &&\n+\n+\tgit maintenance unregister --config-file ./other &&\n+\tgit config --file ./other --get-all maintenance.repo >actual &&\n+\ttest_cmp before actual &&\n+\n \ttest_must_fail git maintenance unregister 2>err &&\n \tgrep \"is not registered\" err &&\n-\tgit maintenance unregister --force\n+\tgit maintenance unregister --force &&\n+\n+\ttest_must_fail git maintenance unregister --config-file ./other 2>err &&\n+\tgrep \"is not registered\" err &&\n+\tgit maintenance unregister --config-file ./other --force\n '\n \n test_expect_success !MINGW 'register and unregister with regex metacharacters' '\n-- \n2.38.1\n\n"},{"id":"466990","messageId":"Y2wasWB58cEZBWA8@nand.local","threadId":"58780","inReplyTo":"20221109190708.22725-1-ronan@rjp.ie","subject":"Re: [PATCH v3 0/2] git-maintenance quality-of-life improvements","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-09T21:25:05Z","receivedAt":"2022-11-09T21:25:10Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi Ronan,\n\nOn Wed, Nov 09, 2022 at 12:07:06PM -0700, Ronan Pigott wrote:\n> Changes in v3:\n>  - Report an error in unregister when the user specifies a config where\n>    the repo is not already registered\n>  - Add a test case for the above\n>  - Correct option description in the docs\n\nSince this series is already in 'next', the existing patches are frozen\nand won't be changed.\n\nWould you mind re-submitting this as one or more patches on top of the\n'rp/maintenance-qol' branch in my fork at\nhttps://github.com/ttaylorr/git?\n\nIf you have any questions about how to do that, please feel free to\ncontact me off-list and I can give you a hand.\n\nThanks,\nTaylor\n"}]}