Skip to content

Commit b4c476c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c365dbb commit b4c476c

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

builtin/bugreport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ int cmd_bugreport(int argc,
167167
strbuf_addftime(&zip_path, option_suffix, localtime_r(&now, &tm), 0, 0);
168168
strbuf_addstr(&zip_path, ".zip");
169169

170-
if (create_diagnostics_archive(&zip_path, diagnose))
170+
if (create_diagnostics_archive(the_repository, &zip_path, diagnose))
171171
die_errno(_("unable to create diagnostics archive %s"), zip_path.buf);
172172

173173
strbuf_release(&zip_path);

builtin/diagnose.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "builtin.h"
24
#include "abspath.h"
35
#include "gettext.h"
@@ -58,7 +60,7 @@ int cmd_diagnose(int argc,
5860
}
5961

6062
/* Prepare diagnostics */
61-
if (create_diagnostics_archive(&zip_path, mode))
63+
if (create_diagnostics_archive(the_repository, &zip_path, mode))
6264
die_errno(_("unable to create diagnostics archive %s"),
6365
zip_path.buf);
6466

diagnose.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "git-compat-util.h"
42
#include "diagnose.h"
53
#include "compat/disk.h"
@@ -12,6 +10,7 @@
1210
#include "object-store-ll.h"
1311
#include "packfile.h"
1412
#include "parse-options.h"
13+
#include "repository.h"
1514
#include "write-or-die.h"
1615

1716
struct archive_dir {
@@ -179,7 +178,9 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
179178
return res;
180179
}
181180

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)
183184
{
184185
struct strvec archiver_args = STRVEC_INIT;
185186
char **argv_copy = NULL;
@@ -218,7 +219,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
218219
strbuf_addstr(&buf, "Collecting diagnostic info\n\n");
219220
get_version_info(&buf, 1);
220221

221-
strbuf_addf(&buf, "Repository root: %s\n", the_repository->worktree);
222+
strbuf_addf(&buf, "Repository root: %s\n", r->worktree);
222223
get_disk_info(&buf);
223224
write_or_die(stdout_fd, buf.buf, buf.len);
224225
strvec_pushf(&archiver_args,
@@ -227,7 +228,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
227228

228229
strbuf_reset(&buf);
229230
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);
231232
foreach_alt_odb(dir_file_stats, &buf);
232233
strvec_push(&archiver_args, buf.buf);
233234

@@ -250,13 +251,13 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
250251
}
251252

252253
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);
254255

255256
/* `write_archive()` modifies the `argv` passed to it. Let it. */
256257
argv_copy = xmemdupz(archiver_args.v,
257258
sizeof(char *) * archiver_args.nr);
258259
res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL,
259-
the_repository, NULL, 0);
260+
r, NULL, 0);
260261
if (res) {
261262
error(_("failed to write archive"));
262263
goto diagnose_cleanup;

diagnose.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "strbuf.h"
55

66
struct option;
7+
struct repository;
78

89
enum diagnose_mode {
910
DIAGNOSE_NONE,
@@ -13,6 +14,8 @@ enum diagnose_mode {
1314

1415
int option_parse_diagnose(const struct option *opt, const char *arg, int unset);
1516

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);
1720

1821
#endif /* DIAGNOSE_H */

0 commit comments

Comments
 (0)