|
8 | 8 | #include "object-store.h"
|
9 | 9 | #include "packfile.h"
|
10 | 10 |
|
| 11 | +struct archive_dir { |
| 12 | + const char *path; |
| 13 | + int recursive; |
| 14 | +}; |
| 15 | + |
11 | 16 | static void dir_file_stats_objects(const char *full_path, size_t full_path_len,
|
12 | 17 | const char *file_name, void *data)
|
13 | 18 | {
|
@@ -132,13 +137,25 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
|
132 | 137 | return res;
|
133 | 138 | }
|
134 | 139 |
|
135 |
| -int create_diagnostics_archive(struct strbuf *zip_path) |
| 140 | +int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode) |
136 | 141 | {
|
137 | 142 | struct strvec archiver_args = STRVEC_INIT;
|
138 | 143 | char **argv_copy = NULL;
|
139 | 144 | int stdout_fd = -1, archiver_fd = -1;
|
140 | 145 | struct strbuf buf = STRBUF_INIT;
|
141 |
| - int res; |
| 146 | + int res, i; |
| 147 | + struct archive_dir archive_dirs[] = { |
| 148 | + { ".git", 0 }, |
| 149 | + { ".git/hooks", 0 }, |
| 150 | + { ".git/info", 0 }, |
| 151 | + { ".git/logs", 1 }, |
| 152 | + { ".git/objects/info", 0 } |
| 153 | + }; |
| 154 | + |
| 155 | + if (mode == DIAGNOSE_NONE) { |
| 156 | + res = 0; |
| 157 | + goto diagnose_cleanup; |
| 158 | + } |
142 | 159 |
|
143 | 160 | stdout_fd = dup(STDOUT_FILENO);
|
144 | 161 | if (stdout_fd < 0) {
|
@@ -177,12 +194,18 @@ int create_diagnostics_archive(struct strbuf *zip_path)
|
177 | 194 | loose_objs_stats(&buf, ".git/objects");
|
178 | 195 | strvec_push(&archiver_args, buf.buf);
|
179 | 196 |
|
180 |
| - if ((res = add_directory_to_archiver(&archiver_args, ".git", 0)) || |
181 |
| - (res = add_directory_to_archiver(&archiver_args, ".git/hooks", 0)) || |
182 |
| - (res = add_directory_to_archiver(&archiver_args, ".git/info", 0)) || |
183 |
| - (res = add_directory_to_archiver(&archiver_args, ".git/logs", 1)) || |
184 |
| - (res = add_directory_to_archiver(&archiver_args, ".git/objects/info", 0))) |
185 |
| - goto diagnose_cleanup; |
| 197 | + /* Only include this if explicitly requested */ |
| 198 | + if (mode == DIAGNOSE_ALL) { |
| 199 | + for (i = 0; i < ARRAY_SIZE(archive_dirs); i++) { |
| 200 | + if (add_directory_to_archiver(&archiver_args, |
| 201 | + archive_dirs[i].path, |
| 202 | + archive_dirs[i].recursive)) { |
| 203 | + res = error_errno(_("could not add directory '%s' to archiver"), |
| 204 | + archive_dirs[i].path); |
| 205 | + goto diagnose_cleanup; |
| 206 | + } |
| 207 | + } |
| 208 | + } |
186 | 209 |
|
187 | 210 | strvec_pushl(&archiver_args, "--prefix=",
|
188 | 211 | oid_to_hex(the_hash_algo->empty_tree), "--", NULL);
|
|
0 commit comments