diff mbox series

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

Message ID 20241217-pks-use-the-repository-conversion-v1-7-0dba48bcc239@pks.im (mailing list archive)
State New
Headers show
Series [01/14] progress: stop using `the_repository` | expand

Commit Message

Patrick Steinhardt Dec. 17, 2024, 6:43 a.m. UTC
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 mbox series

Patch

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 */