Skip to content

Commit 5fe849d

Browse files
peffgitster
authored andcommitted
count-objects: report alternates via verbose mode
There's no way to get the list of alternates that git computes internally; our tests only infer it based on which objects are available. In addition to testing, knowing this list may be helpful for somebody debugging their alternates setup. Let's add it to the "count-objects -v" output. We could give it a separate flag, but there's not really any need. "count-objects -v" is already a debugging catch-all for the object database, its output is easily extensible to new data items, and printing the alternates is not expensive (we already had to find them to count the objects). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7b7774 commit 5fe849d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Documentation/git-count-objects.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ objects nor valid packs
3838
+
3939
size-garbage: disk space consumed by garbage files, in KiB (unless -H is
4040
specified)
41+
+
42+
alternate: absolute path of alternate object databases; may appear
43+
multiple times, one line per path. Note that if the path contains
44+
non-printable characters, it may be surrounded by double-quotes and
45+
contain C-style backslashed escape sequences.
4146

4247
-H::
4348
--human-readable::

builtin/count-objects.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "dir.h"
99
#include "builtin.h"
1010
#include "parse-options.h"
11+
#include "quote.h"
1112

1213
static unsigned long garbage;
1314
static off_t size_garbage;
@@ -73,6 +74,14 @@ static int count_cruft(const char *basename, const char *path, void *data)
7374
return 0;
7475
}
7576

77+
static int print_alternate(struct alternate_object_database *alt, void *data)
78+
{
79+
printf("alternate: ");
80+
quote_c_style(alt->path, NULL, stdout, 0);
81+
putchar('\n');
82+
return 0;
83+
}
84+
7685
static char const * const count_objects_usage[] = {
7786
N_("git count-objects [-v] [-H | --human-readable]"),
7887
NULL
@@ -140,6 +149,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
140149
printf("prune-packable: %lu\n", packed_loose);
141150
printf("garbage: %lu\n", garbage);
142151
printf("size-garbage: %s\n", garbage_buf.buf);
152+
foreach_alt_odb(print_alternate, NULL);
143153
strbuf_release(&loose_buf);
144154
strbuf_release(&pack_buf);
145155
strbuf_release(&garbage_buf);

t/t5613-info-alternate.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ test_expect_success 'preparing third repository' '
3939
)
4040
'
4141

42+
test_expect_success 'count-objects shows the alternates' '
43+
cat >expect <<-EOF &&
44+
alternate: $(pwd)/B/.git/objects
45+
alternate: $(pwd)/A/.git/objects
46+
EOF
47+
git -C C count-objects -v >actual &&
48+
grep ^alternate: actual >actual.alternates &&
49+
test_cmp expect actual.alternates
50+
'
51+
4252
# Note: These tests depend on the hard-coded value of 5 as the maximum depth
4353
# we will follow recursion. We start the depth at 0 and count links, not
4454
# repositories. This means that in a chain like:

0 commit comments

Comments
 (0)