Git fork

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>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
b4c476c4 c365dbb4

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