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

[PATCH 07/14] diagnose: stop using `the_repository`

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 17, 2024, 06:43 UTC
Message-ID
<20241217-pks-use-the-repository-conversion-v1-7-0dba48bcc239@pks.im>
In-Reply-To
<20241217-pks-use-the-repository-conversion-v1-0-0dba48bcc239@pks.im>

Stop using `the_repository` in the "diagnose" subsystem by passing in a repository when generating a diagnostics archive.

Adjust callers accordingly by using `the_repository`. While there may be some callers that have a repository available in their context, this trivial conversion allows for easier verification and bubbles up the use of `the_repository` by one level.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/bugreport.c |  2 +-
 builtin/diagnose.c  |  4 +++-
 diagnose.c          | 15 ++++++++-------
 diagnose.h          |  5 ++++-
 4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 7c2df035c9cff06f649c2b35394ea3db3d39f469..0ac59cc8dc5824fbc155674e9107bb845d8e054c 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -167,7 +167,7 @@ int cmd_bugreport(int argc,
 		strbuf_addftime(&zip_path, option_suffix, localtime_r(&now, &tm), 0, 0);
 		strbuf_addstr(&zip_path, ".zip");
 
-		if (create_diagnostics_archive(&zip_path, diagnose))
+		if (create_diagnostics_archive(the_repository, &zip_path, diagnose))
 			die_errno(_("unable to create diagnostics archive %s"), zip_path.buf);
 
 		strbuf_release(&zip_path);
diff --git a/builtin/diagnose.c b/builtin/diagnose.c
index 66a22d918e68a48a7c31ef3b75335f9a2bad7ab1..33c39bd5981f22d96b1b19e19ff83dec1c2873a6 100644
--- a/builtin/diagnose.c
+++ b/builtin/diagnose.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
 #include "abspath.h"
 #include "gettext.h"
@@ -58,7 +60,7 @@ int cmd_diagnose(int argc,
 	}
 
 	/* Prepare diagnostics */
-	if (create_diagnostics_archive(&zip_path, mode))
+	if (create_diagnostics_archive(the_repository, &zip_path, mode))
 		die_errno(_("unable to create diagnostics archive %s"),
 			  zip_path.buf);
 
diff --git a/diagnose.c b/diagnose.c
index b11931df86c4ba84f7aec77cb7965083f5aa31fa..bd485effea22ce400c4300a1e085b45204a3b42e 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "diagnose.h"
 #include "compat/disk.h"
@@ -12,6 +10,7 @@
 #include "object-store-ll.h"
 #include "packfile.h"
 #include "parse-options.h"
+#include "repository.h"
 #include "write-or-die.h"
 
 struct archive_dir {
@@ -179,7 +178,9 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
 	return res;
 }
 
-int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
+int create_diagnostics_archive(struct repository *r,
+			       struct strbuf *zip_path,
+			       enum diagnose_mode mode)
 {
 	struct strvec archiver_args = STRVEC_INIT;
 	char **argv_copy = NULL;
@@ -218,7 +219,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
 	strbuf_addstr(&buf, "Collecting diagnostic info\n\n");
 	get_version_info(&buf, 1);
 
-	strbuf_addf(&buf, "Repository root: %s\n", the_repository->worktree);
+	strbuf_addf(&buf, "Repository root: %s\n", r->worktree);
 	get_disk_info(&buf);
 	write_or_die(stdout_fd, buf.buf, buf.len);
 	strvec_pushf(&archiver_args,
@@ -227,7 +228,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
 
 	strbuf_reset(&buf);
 	strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
-	dir_file_stats(the_repository->objects->odb, &buf);
+	dir_file_stats(r->objects->odb, &buf);
 	foreach_alt_odb(dir_file_stats, &buf);
 	strvec_push(&archiver_args, buf.buf);
 
@@ -250,13 +251,13 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
 	}
 
 	strvec_pushl(&archiver_args, "--prefix=",
-		     oid_to_hex(the_hash_algo->empty_tree), "--", NULL);
+		     oid_to_hex(r->hash_algo->empty_tree), "--", NULL);
 
 	/* `write_archive()` modifies the `argv` passed to it. Let it. */
 	argv_copy = xmemdupz(archiver_args.v,
 			     sizeof(char *) * archiver_args.nr);
 	res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL,
-			    the_repository, NULL, 0);
+			    r, NULL, 0);
 	if (res) {
 		error(_("failed to write archive"));
 		goto diagnose_cleanup;
diff --git a/diagnose.h b/diagnose.h
index f525219ab0cf9b36249892c847e731b952b081af..f7b38f49f5271ad00bf17d14e7b2aab3e9e174d5 100644
--- a/diagnose.h
+++ b/diagnose.h
@@ -4,6 +4,7 @@
 #include "strbuf.h"
 
 struct option;
+struct repository;
 
 enum diagnose_mode {
 	DIAGNOSE_NONE,
@@ -13,6 +14,8 @@ enum diagnose_mode {
 
 int option_parse_diagnose(const struct option *opt, const char *arg, int unset);
 
-int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode);
+int create_diagnostics_archive(struct repository *r,
+			       struct strbuf *zip_path,
+			       enum diagnose_mode mode);
 
 #endif /* DIAGNOSE_H */
-- 
2.48.0.rc0.184.g0fc57dec57.dirty
Previous: shejialuoNext: Patrick Steinhardt
Message 14 of 26 in “Stop using `the_repository` in some trivial cases”
  1. 00/14 Stop using `the_repository` in some trivial casesPatrick Steinhardt, Dec 17, 2024
  2. 01/14 progress: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  3. Karthik NayakDec 31, 2024
  4. Toon ClaesJan 6, 2025
  5. Patrick SteinhardtJan 7, 2025
  6. 02/14 pager: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  7. shejialuoDec 17, 2024
  8. Karthik NayakDec 31, 2024
  9. 03/14 trace: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  10. 04/14 serve: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  11. 05/14 send-pack: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  12. 06/14 server-info: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  13. shejialuoDec 17, 2024
  14. 07/14 diagnose: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  15. 08/14 mailinfo: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  16. 09/14 credential: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  17. 10/14 resolve-undo: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  18. 11/14 tmp-objdir: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  19. 12/14 add-interactive: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  20. 13/14 graph: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  21. 14/14 match-trees: stop using `the_repository`Patrick Steinhardt, Dec 17, 2024
  22. shejialuoDec 17, 2024
  23. Patrick SteinhardtDec 27, 2024
  24. Karthik NayakJan 7, 2025
  25. Toon ClaesJan 7, 2025
  26. Junio C HamanoJan 7, 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.