git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, vdye@github.com,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Derrick Stolee" <derrickstolee@github.com>
Subject: [PATCH v4 0/4] scalar: make unregister idempotent
Date: Tue, 27 Sep 2022 13:56:57 +0000	[thread overview]
Message-ID: <pull.1358.v4.git.1664287021.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1358.v3.git.1664218087.gitgitgadget@gmail.com>

I noticed this while we were updating the microsoft/git fork to include
v2.38.0-rc0. I don't think 'git maintenance unregister' was idempotent
before, but instead some change in 'scalar unregister' led to it relying on
the return code of 'git maintenance unregister'. Our functional tests expect
'scalar unregister' to be idempotent, and I think that's a good pattern for
'git maintenance unregister', so I'm fixing it at that layer.

Despite finding this during the 2.38.0-rc0 integration, this isn't critical
to the release.

Perhaps an argument could be made that "failure means it wasn't registered
before", but I think that isn't terribly helpful.

Our functional tests are running the unregister subcommand to disable
maintenance in order to run tests on the object store (such as running
maintenance commands in the foreground and checking the object store
afterwards). This is a form of automation using 'unregister' as a check that
maintenance will not run at the same time, and it doesn't care if
maintenance was already disabled. I can imagine other scripting scenarios
wanting that kind of guarantee.


Updates in v4
=============

 * The previous version would segfault if 'git maintenance unregister' was
   called with an empty 'maintenance.repo' config list. This scenario is
   fixed and tested.
 * Part of the issue is that for_each_string_list_item() cannot handle a
   NULL value. The macro can't be made smarter without failing
   -Werror=address issues, so for now I added a patch that adds a warning to
   its doc comment.


Updates in v3
=============

 * The --force option now uses OPT_FORCE and is hidden from autocomplete.
 * A new commit is added that removes the use of Git subprocesses in favor
   of git_config_set_multivar_in_file_gently().


Updates in v2
=============

 * This is now a two-patch series.
 * I rebased onto v2.38.0-rc1 for two reasons: Scalar is now merged, and the
   usage for 'git maintenance unregister' removed its translation markers.
 * Instead of making git maintenance unregister idempotent, add a --force
   option for those who do not want to require that the repository is
   already registered.
 * Make scalar unregister idempotent, with reasons argued in patch 2.

Thanks, -Stolee

Derrick Stolee (4):
  maintenance: add 'unregister --force'
  scalar: make 'unregister' idempotent
  gc: replace config subprocesses with API calls
  string-list: document iterator behavior on NULL input

 Documentation/git-maintenance.txt |  6 +-
 builtin/gc.c                      | 98 +++++++++++++++++++++----------
 scalar.c                          |  5 +-
 string-list.h                     |  7 ++-
 t/t7900-maintenance.sh            | 11 +++-
 t/t9210-scalar.sh                 |  5 +-
 6 files changed, 96 insertions(+), 36 deletions(-)


base-commit: 1b3d6e17fe83eb6f79ffbac2f2c61bbf1eaef5f8
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1358%2Fderrickstolee%2Fmaintenance-unregister-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1358/derrickstolee/maintenance-unregister-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/1358

Range-diff vs v3:

 1:  8a8bffaec89 ! 1:  c3301e21109 maintenance: add 'unregister --force'
     @@ Commit message
          '--force' option that will siltently succeed if the repository is not
          already registered.
      
     +    Also add an extra test of 'git maintenance unregister' at a point where
     +    there are no registered repositories. This should fail without --force.
     +
          Signed-off-by: Derrick Stolee <derrickstolee@github.com>
      
       ## Documentation/git-maintenance.txt ##
     @@ builtin/gc.c: done:
       	char *maintpath = get_maintpath();
      +	int found = 0;
      +	struct string_list_item *item;
     -+	const struct string_list *list = git_config_get_value_multi(key);
     ++	const struct string_list *list;
       
       	argc = parse_options(argc, argv, prefix, options,
       			     builtin_maintenance_unregister_usage, 0);
     @@ builtin/gc.c: static int maintenance_unregister(int argc, const char **argv, con
      -	config_unset.git_cmd = 1;
      -	strvec_pushl(&config_unset.args, "config", "--global", "--unset",
      -		     "--fixed-value", "maintenance.repo", maintpath, NULL);
     -+	for_each_string_list_item(item, list) {
     -+		if (!strcmp(maintpath, item->string)) {
     -+			found = 1;
     -+			break;
     ++	list = git_config_get_value_multi(key);
     ++	if (list) {
     ++		for_each_string_list_item(item, list) {
     ++			if (!strcmp(maintpath, item->string)) {
     ++				found = 1;
     ++				break;
     ++			}
      +		}
      +	}
      +
     @@ builtin/gc.c: static int maintenance_unregister(int argc, const char **argv, con
       }
      
       ## t/t7900-maintenance.sh ##
     +@@ t/t7900-maintenance.sh: test_expect_success 'maintenance.strategy inheritance' '
     + 
     + test_expect_success 'register and unregister' '
     + 	test_when_finished git config --global --unset-all maintenance.repo &&
     ++
     ++	test_must_fail git maintenance unregister 2>err &&
     ++	grep "is not registered" err &&
     ++	git maintenance unregister --force &&
     ++
     + 	git config --global --add maintenance.repo /existing1 &&
     + 	git config --global --add maintenance.repo /existing2 &&
     + 	git config --global --get-all maintenance.repo >before &&
      @@ t/t7900-maintenance.sh: test_expect_success 'register and unregister' '
       
       	git maintenance unregister &&
 2:  06d5ef3fc57 = 2:  a768c326c0f scalar: make 'unregister' idempotent
 3:  260d7bee36e = 3:  5aa9cc1d6b9 gc: replace config subprocesses with API calls
 -:  ----------- > 4:  73a262cdca4 string-list: document iterator behavior on NULL input

-- 
gitgitgadget

  parent reply	other threads:[~2022-09-27 13:57 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20  1:02 [PATCH] maintenance: make unregister idempotent Derrick Stolee via GitGitGadget
2022-09-21 17:19 ` Junio C Hamano
2022-09-22 12:37   ` Derrick Stolee
2022-09-22 19:31     ` Junio C Hamano
2022-09-22 19:46       ` Derrick Stolee
2022-09-22 20:44         ` Junio C Hamano
2022-09-22 13:37 ` [PATCH v2 0/2] scalar: " Derrick Stolee via GitGitGadget
2022-09-22 13:37   ` [PATCH v2 1/2] maintenance: add 'unregister --force' Derrick Stolee via GitGitGadget
2022-09-23 13:08     ` SZEDER Gábor
2022-09-26 13:32       ` Derrick Stolee
2022-09-26 15:39         ` Ævar Arnfjörð Bjarmason
2022-09-26 17:25           ` Derrick Stolee
2022-09-26 19:17             ` Junio C Hamano
2022-09-22 13:37   ` [PATCH v2 2/2] scalar: make 'unregister' idempotent Derrick Stolee via GitGitGadget
2022-09-26 18:48   ` [PATCH v3 0/3] scalar: make unregister idempotent Derrick Stolee via GitGitGadget
2022-09-26 18:48     ` [PATCH v3 1/3] maintenance: add 'unregister --force' Derrick Stolee via GitGitGadget
2022-09-26 19:23       ` Junio C Hamano
2022-09-26 20:49         ` Derrick Stolee
2022-09-26 21:55       ` Junio C Hamano
2022-09-27 11:38         ` Derrick Stolee
2022-09-27 11:54           ` Derrick Stolee
2022-09-27 13:36             ` Ævar Arnfjörð Bjarmason
2022-09-27 13:55               ` Derrick Stolee
2022-09-26 18:48     ` [PATCH v3 2/3] scalar: make 'unregister' idempotent Derrick Stolee via GitGitGadget
2022-09-26 18:48     ` [PATCH v3 3/3] gc: replace config subprocesses with API calls Derrick Stolee via GitGitGadget
2022-09-26 19:27       ` Junio C Hamano
2022-09-27 13:56     ` Derrick Stolee via GitGitGadget [this message]
2022-09-27 13:56       ` [PATCH v4 1/4] maintenance: add 'unregister --force' Derrick Stolee via GitGitGadget
2022-09-27 13:56       ` [PATCH v4 2/4] scalar: make 'unregister' idempotent Derrick Stolee via GitGitGadget
2022-09-27 13:57       ` [PATCH v4 3/4] gc: replace config subprocesses with API calls Derrick Stolee via GitGitGadget
2022-09-27 13:57       ` [PATCH v4 4/4] string-list: document iterator behavior on NULL input Derrick Stolee via GitGitGadget
2022-09-27 16:39         ` Junio C Hamano
2022-09-27 16:31       ` [PATCH v4 0/4] scalar: make unregister idempotent Junio C Hamano
2022-09-27 16:54         ` Derrick Stolee

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=pull.1358.v4.git.1664287021.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=avarab@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=szeder.dev@gmail.com \
    --cc=vdye@github.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).