Skip to content

Commit b1cdb5e

Browse files
nasamuffingitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a226a6 commit b1cdb5e

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
@@ -204,6 +204,57 @@ static void get_packed_object_summary(struct strbuf *obj_info, int nongit)
204204

205205
}
206206

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

355+
get_header(&buffer, "Object Info Summary");
356+
get_object_info_summary(&buffer, nongit_ok);
357+
304358
report = fopen_for_writing(report_path.buf);
305359

306360
if (report == NULL) {

0 commit comments

Comments
 (0)