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

[PATCH 08/13] t/helper: stop setting up `the_repository` repeatedly

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 19, 2025, 07:50 UTC
Message-ID
<20251119-b4-pks-odb-creation-v1-8-2b2ed2612cb6@pks.im>
In-Reply-To
<20251119-b4-pks-odb-creation-v1-0-2b2ed2612cb6@pks.im>

The "repository" test helper sets up `the_repository` twice. In fact though, we don't even have to set it up even once: all we need is to set up its hash algorithm, because we still depend on some subsystems that aren't free of `the_repository`.

Refactor the code accordingly. This prepares for a subsequent change, where setting up the repository repeatedly will lead to a `BUG()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/helper/test-repository.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index 63c37de33d..9ba94cdffa 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -17,10 +17,6 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
 	struct commit *c;
 	struct commit_list *parent;
 
-	setup_git_env(gitdir);
-
-	repo_clear(the_repository);
-
 	if (repo_init(&r, gitdir, worktree))
 		die("Couldn't init repo");
 
@@ -47,10 +43,6 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
 	struct commit *c;
 	struct tree *tree;
 
-	setup_git_env(gitdir);
-
-	repo_clear(the_repository);
-
 	if (repo_init(&r, gitdir, worktree))
 		die("Couldn't init repo");
 
@@ -75,24 +67,20 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
 
 int cmd__repository(int argc, const char **argv)
 {
-	int nongit_ok = 0;
-
-	setup_git_directory_gently(&nongit_ok);
-
 	if (argc < 2)
 		die("must have at least 2 arguments");
 	if (!strcmp(argv[1], "parse_commit_in_graph")) {
 		struct object_id oid;
 		if (argc < 5)
 			die("not enough arguments");
-		if (parse_oid_hex(argv[4], &oid, &argv[4]))
+		if (parse_oid_hex_any(argv[4], &oid, &argv[4]) == GIT_HASH_UNKNOWN)
 			die("cannot parse oid '%s'", argv[4]);
 		test_parse_commit_in_graph(argv[2], argv[3], &oid);
 	} else if (!strcmp(argv[1], "get_commit_tree_in_graph")) {
 		struct object_id oid;
 		if (argc < 5)
 			die("not enough arguments");
-		if (parse_oid_hex(argv[4], &oid, &argv[4]))
+		if (parse_oid_hex_any(argv[4], &oid, &argv[4]) == GIT_HASH_UNKNOWN)
 			die("cannot parse oid '%s'", argv[4]);
 		test_get_commit_tree_in_graph(argv[2], argv[3], &oid);
 	} else {
-- 
2.52.0.rc2.482.gaa765fefd0.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 14 of 21 in “Centralize management of object database sources”
  1. 00/13 Centralize management of object database sourcesPatrick Steinhardt, Nov 19, 2025
  2. 01/13 path: move `enter_repo()` into "setup.c"Patrick Steinhardt, Nov 19, 2025
  3. 02/13 setup: convert `set_git_dir()` to have file scopePatrick Steinhardt, Nov 19, 2025
  4. 03/13 odb: adopt logic to close object databasesPatrick Steinhardt, Nov 19, 2025
  5. 04/13 odb: refactor `odb_clear()` to `odb_free()`Patrick Steinhardt, Nov 19, 2025
  6. 05/13 odb: move logic to disable ref updates into repoPatrick Steinhardt, Nov 19, 2025
  7. Junio C HamanoNov 19, 2025
  8. Patrick SteinhardtNov 21, 2025
  9. 06/13 oidset: introduce `oidset_equal()`Patrick Steinhardt, Nov 19, 2025
  10. Junio C HamanoNov 19, 2025
  11. 07/13 builtin/index-pack: fix deferred fsck outside reposPatrick Steinhardt, Nov 19, 2025
  12. Junio C HamanoNov 19, 2025
  13. Patrick SteinhardtNov 21, 2025
  14. 08/13 t/helper: stop setting up `the_repository` repeatedlyPatrick Steinhardt, Nov 19, 2025
  15. 09/13 http-push: stop setting up `the_repository` for each referencePatrick Steinhardt, Nov 19, 2025
  16. 10/13 odb: handle initialization of sources in `odb_new()`Patrick Steinhardt, Nov 19, 2025
  17. 11/13 chdir-notify: add function to unregister listenersPatrick Steinhardt, Nov 19, 2025
  18. 12/13 odb: handle changing a repository's commondirPatrick Steinhardt, Nov 19, 2025
  19. Junio C HamanoNov 20, 2025
  20. Patrick SteinhardtNov 21, 2025
  21. 13/13 odb: handle recreation of quarantine directoriesPatrick Steinhardt, Nov 19, 2025

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.