git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] scalar: make 'unregister' idempotent

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 22, 2022, 13:37 UTC
Message-ID
<f5d8d6e490102202147c965a4d50c4f3b02d4a5d.1663853837.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1358.v2.git.1663853837.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>

The 'scalar unregister' command removes a repository from the list of registered Scalar repositories and removes it from the list of repositories registered for background maintenance. If the repository was not already registered for background maintenance, then the command fails, even if the repository was still registered as a Scalar repository.

After using 'scalar clone' or 'scalar register', the repository would be enrolled in background maintenance since those commands run 'git maintenance start'. If the user runs 'git maintenance unregister' on that repository, then it is still in the list of repositories which get new config updates from 'scalar reconfigure'. The 'scalar unregister' command would fail since 'git maintenance unregister' would fail.

Further, the add_or_remove_enlistment() method in scalar.c already has this idempotent nature built in as an expectation since it returns zero when the scalar.repo list already has the proper containment of the repository.

The previous change added the 'git maintenance unregister --force' option, so use it within 'scalar unregister' to make it idempotent.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
---
 scalar.c          | 5 ++++-
 t/t9210-scalar.sh | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/scalar.c b/scalar.c
index c5c1ce68919..6de9c0ee523 100644
--- a/scalar.c
+++ b/scalar.c
@@ -207,7 +207,10 @@ static int set_recommended_config(int reconfigure)
 
 static int toggle_maintenance(int enable)
 {
-	return run_git("maintenance", enable ? "start" : "unregister", NULL);
+	return run_git("maintenance",
+		       enable ? "start" : "unregister",
+		       enable ? NULL : "--force",
+		       NULL);
 }
 
 static int add_or_remove_enlistment(int add)
diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh
index 14ca575a214..be51a8bb7a4 100755
--- a/t/t9210-scalar.sh
+++ b/t/t9210-scalar.sh
@@ -116,7 +116,10 @@ test_expect_success 'scalar unregister' '
 	test_must_fail git config --get --global --fixed-value \
 		maintenance.repo "$(pwd)/vanish/src" &&
 	scalar list >scalar.repos &&
-	! grep -F "$(pwd)/vanish/src" scalar.repos
+	! grep -F "$(pwd)/vanish/src" scalar.repos &&
+
+	# scalar unregister should be idempotent
+	scalar unregister vanish
 '
 
 test_expect_success 'set up repository to clone' '
-- 
gitgitgadget
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee via GitGitGadget
Message 8 of 34 in “maintenance: make unregister idempotent”
  1. maintenance: make unregister idempotentDerrick Stolee via GitGitGadget, Sep 20, 2022
  2. Junio C HamanoSep 21, 2022
  3. Derrick StoleeSep 22, 2022
  4. Junio C HamanoSep 22, 2022
  5. Derrick StoleeSep 22, 2022
  6. Junio C HamanoSep 22, 2022
  7. 0/2 scalar: make unregister idempotentDerrick Stolee via GitGitGadget, Sep 22, 2022
  8. 2/2 scalar: make 'unregister' idempotentDerrick Stolee via GitGitGadget, Sep 22, 2022
  9. 1/2 maintenance: add 'unregister --force'Derrick Stolee via GitGitGadget, Sep 22, 2022
  10. SZEDER GáborSep 23, 2022
  11. Derrick StoleeSep 26, 2022
  12. Ævar Arnfjörð BjarmasonSep 26, 2022
  13. Derrick StoleeSep 26, 2022
  14. Junio C HamanoSep 26, 2022
  15. 0/3 scalar: make unregister idempotentDerrick Stolee via GitGitGadget, Sep 26, 2022
  16. 1/3 maintenance: add 'unregister --force'Derrick Stolee via GitGitGadget, Sep 26, 2022
  17. Junio C HamanoSep 26, 2022
  18. Derrick StoleeSep 26, 2022
  19. Junio C HamanoSep 26, 2022
  20. Derrick StoleeSep 27, 2022
  21. Derrick StoleeSep 27, 2022
  22. Ævar Arnfjörð BjarmasonSep 27, 2022
  23. Derrick StoleeSep 27, 2022
  24. 2/3 scalar: make 'unregister' idempotentDerrick Stolee via GitGitGadget, Sep 26, 2022
  25. 3/3 gc: replace config subprocesses with API callsDerrick Stolee via GitGitGadget, Sep 26, 2022
  26. Junio C HamanoSep 26, 2022
  27. 0/4 scalar: make unregister idempotentDerrick Stolee via GitGitGadget, Sep 27, 2022
  28. 1/4 maintenance: add 'unregister --force'Derrick Stolee via GitGitGadget, Sep 27, 2022
  29. 2/4 scalar: make 'unregister' idempotentDerrick Stolee via GitGitGadget, Sep 27, 2022
  30. 3/4 gc: replace config subprocesses with API callsDerrick Stolee via GitGitGadget, Sep 27, 2022
  31. 4/4 string-list: document iterator behavior on NULL inputDerrick Stolee via GitGitGadget, Sep 27, 2022
  32. Junio C HamanoSep 27, 2022
  33. Junio C HamanoSep 27, 2022
  34. Derrick StoleeSep 27, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.