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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 3, 2016 at 16:36 UTC
5fe849d651e259af58f29f9cfb1b1405154ffacc
3 files changed
+25
Documentation/git-count-objects.txt
+5
@@ -38,6 +38,11 @@ objects nor valid packs
38
+
39
size-garbage: disk space consumed by garbage files, in KiB (unless -H is
40
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.
46
47
-H::
48
--human-readable::
builtin/count-objects.c
+10
@@ -8,6 +8,7 @@
8
#include "dir.h"
9
#include "builtin.h"
10
#include "parse-options.h"
11
+#include "quote.h"
12
13
static unsigned long garbage;
14
static off_t size_garbage;
@@ -73,6 +74,14 @@ static int count_cruft(const char *basename, const char *path, void *data)
74
return 0;
75
}
76
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
+
85
static char const * const count_objects_usage[] = {
86
N_("git count-objects [-v] [-H | --human-readable]"),
87
NULL
@@ -140,6 +149,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
149
printf("prune-packable: %lu\n", packed_loose);
150
printf("garbage: %lu\n", garbage);
151
printf("size-garbage: %s\n", garbage_buf.buf);
152
+ foreach_alt_odb(print_alternate, NULL);
153
strbuf_release(&loose_buf);
154
strbuf_release(&pack_buf);
155
strbuf_release(&garbage_buf);
t/t5613-info-alternate.sh
+10
@@ -39,6 +39,16 @@ test_expect_success 'preparing third repository' '
39
)
40
'
41
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
+
52
# Note: These tests depend on the hard-coded value of 5 as the maximum depth
53
# we will follow recursion. We start the depth at 0 and count links, not
54
# repositories. This means that in a chain like: