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>
maint
Patrick Steinhardt 2024-12-17 07:43:54 +01:00 committed by Junio C Hamano
parent c365dbb44e
commit b4c476c43a
4 changed files with 16 additions and 10 deletions

View File

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

View File

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


View File

@ -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;

View File

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