diagnose: stop using `the_repository`
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 17, 2024 at 07:43 UTC
b4c476c43a1125300614d2e9ec9dedfa44355515
4 files changed
+16
-10
builtin/bugreport.c
+1
-1
@@ -167,7 +167,7 @@ int cmd_bugreport(int argc,
167
strbuf_addftime(&zip_path, option_suffix, localtime_r(&now, &tm), 0, 0);
168
strbuf_addstr(&zip_path, ".zip");
169
170
- if (create_diagnostics_archive(&zip_path, diagnose))
170
+ if (create_diagnostics_archive(the_repository, &zip_path, diagnose))
171
die_errno(_("unable to create diagnostics archive %s"), zip_path.buf);
172
173
strbuf_release(&zip_path);
builtin/diagnose.c
+3
-1
@@ -1,3 +1,5 @@
1
+#define USE_THE_REPOSITORY_VARIABLE
2
+
3
#include "builtin.h"
4
#include "abspath.h"
5
#include "gettext.h"
@@ -58,7 +60,7 @@ int cmd_diagnose(int argc,
60
}
61
62
/* Prepare diagnostics */
61
- if (create_diagnostics_archive(&zip_path, mode))
63
+ if (create_diagnostics_archive(the_repository, &zip_path, mode))
64
die_errno(_("unable to create diagnostics archive %s"),
65
zip_path.buf);
66
diagnose.c
+8
-7
@@ -1,5 +1,3 @@
1
-#define USE_THE_REPOSITORY_VARIABLE
2
-
1
#include "git-compat-util.h"
2
#include "diagnose.h"
3
#include "compat/disk.h"
@@ -12,6 +10,7 @@
10
#include "object-store-ll.h"
11
#include "packfile.h"
12
#include "parse-options.h"
13
+#include "repository.h"
14
#include "write-or-die.h"
15
16
struct archive_dir {
@@ -179,7 +178,9 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
178
return res;
179
}
180
182
-int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
181
+int create_diagnostics_archive(struct repository *r,
182
+ struct strbuf *zip_path,
183
+ enum diagnose_mode mode)
184
{
185
struct strvec archiver_args = STRVEC_INIT;
186
char **argv_copy = NULL;
@@ -218,7 +219,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
219
strbuf_addstr(&buf, "Collecting diagnostic info\n\n");
220
get_version_info(&buf, 1);
221
221
- strbuf_addf(&buf, "Repository root: %s\n", the_repository->worktree);
222
+ strbuf_addf(&buf, "Repository root: %s\n", r->worktree);
223
get_disk_info(&buf);
224
write_or_die(stdout_fd, buf.buf, buf.len);
225
strvec_pushf(&archiver_args,
@@ -227,7 +228,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
228
229
strbuf_reset(&buf);
230
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
230
- dir_file_stats(the_repository->objects->odb, &buf);
231
+ dir_file_stats(r->objects->odb, &buf);
232
foreach_alt_odb(dir_file_stats, &buf);
233
strvec_push(&archiver_args, buf.buf);
234
@@ -250,13 +251,13 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
251
}
252
253
strvec_pushl(&archiver_args, "--prefix=",
253
- oid_to_hex(the_hash_algo->empty_tree), "--", NULL);
254
+ oid_to_hex(r->hash_algo->empty_tree), "--", NULL);
255
256
/* `write_archive()` modifies the `argv` passed to it. Let it. */
257
argv_copy = xmemdupz(archiver_args.v,
258
sizeof(char *) * archiver_args.nr);
259
res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL,
259
- the_repository, NULL, 0);
260
+ r, NULL, 0);
261
if (res) {
262
error(_("failed to write archive"));
263
goto diagnose_cleanup;
diagnose.h
+4
-1
@@ -4,6 +4,7 @@
4
#include "strbuf.h"
5
6
struct option;
7
+struct repository;
8
9
enum diagnose_mode {
10
DIAGNOSE_NONE,
@@ -13,6 +14,8 @@ enum diagnose_mode {
14
15
int option_parse_diagnose(const struct option *opt, const char *arg, int unset);
16
16
-int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode);
17
+int create_diagnostics_archive(struct repository *r,
18
+ struct strbuf *zip_path,
19
+ enum diagnose_mode mode);
20
21
#endif /* DIAGNOSE_H */