Skip to content

Commit 239faf2

Browse files
committed
bugreport: list contents of $OBJDIR/info
Miscellaneous information used about the object store can end up in .git/objects/info; this can help us understand what may be going on with the object store when the user is reporting a bug. Otherwise, it could be difficult to track down what is going wrong with an object which isn't kept locally to .git/objects/ or .git/objects/pack. Having some understanding of where the user's objects may be kept can save us some hops during the bug reporting process. Signed-off-by: Emily Shaffer <[email protected]>
1 parent 54cb6bb commit 239faf2

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Documentation/git-bugreport.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following information is captured automatically:
3434
- A list of enabled hooks
3535
- The number of loose objects in the repository
3636
- The number of packs and packed objects in the repository
37+
- A list of the contents of .git/objects/info (or equivalent)
3738

3839
This tool is invoked via the typical Git setup process, which means that in some
3940
cases, it might not be able to launch - for example, if a relevant config file

bugreport.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,57 @@ static void get_packed_object_summary(struct strbuf *obj_info, int nongit)
206206

207207
}
208208

209+
static void list_contents_of_dir_recursively(struct strbuf *contents,
210+
struct strbuf *dirpath)
211+
{
212+
struct dirent *d;
213+
DIR *dir;
214+
size_t path_len;
215+
216+
dir = opendir(dirpath->buf);
217+
if (!dir)
218+
return;
219+
220+
strbuf_complete(dirpath, '/');
221+
path_len = dirpath->len;
222+
223+
while ((d = readdir(dir))) {
224+
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
225+
continue;
226+
227+
strbuf_addbuf(contents, dirpath);
228+
strbuf_addstr(contents, d->d_name);
229+
strbuf_complete_line(contents);
230+
231+
if (d->d_type == DT_DIR) {
232+
strbuf_addstr(dirpath, d->d_name);
233+
list_contents_of_dir_recursively(contents, dirpath);
234+
}
235+
strbuf_setlen(dirpath, path_len);
236+
}
237+
238+
closedir(dir);
239+
}
240+
241+
static void get_object_info_summary(struct strbuf *obj_info, int nongit)
242+
{
243+
struct strbuf dirpath = STRBUF_INIT;
244+
245+
if (nongit) {
246+
strbuf_addstr(obj_info,
247+
"not run from a git repository - object info unavailable\n");
248+
return;
249+
}
250+
251+
strbuf_addstr(&dirpath, get_object_directory());
252+
strbuf_complete(&dirpath, '/');
253+
strbuf_addstr(&dirpath, "info/");
254+
255+
list_contents_of_dir_recursively(obj_info, &dirpath);
256+
257+
strbuf_release(&dirpath);
258+
}
259+
209260
static const char * const bugreport_usage[] = {
210261
N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
211262
NULL
@@ -298,6 +349,9 @@ int cmd_main(int argc, const char **argv)
298349
get_header(&buffer, "Packed Object Summary");
299350
get_packed_object_summary(&buffer, nongit_ok);
300351

352+
get_header(&buffer, "Object Info Summary");
353+
get_object_info_summary(&buffer, nongit_ok);
354+
301355
/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
302356
report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);
303357

0 commit comments

Comments
 (0)