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