OSDN Git Service

count-objects: report alternates via verbose mode
authorJeff King <peff@peff.net>
Mon, 3 Oct 2016 20:36:18 +0000 (16:36 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2016 20:52:37 +0000 (13:52 -0700)
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>
Documentation/git-count-objects.txt
builtin/count-objects.c
t/t5613-info-alternate.sh

index 2ff3568..cb9b4d2 100644 (file)
@@ -38,6 +38,11 @@ objects nor valid packs
 +
 size-garbage: disk space consumed by garbage files, in KiB (unless -H is
 specified)
++
+alternate: absolute path of alternate object databases; may appear
+multiple times, one line per path. Note that if the path contains
+non-printable characters, it may be surrounded by double-quotes and
+contain C-style backslashed escape sequences.
 
 -H::
 --human-readable::
index ba92919..a700409 100644 (file)
@@ -8,6 +8,7 @@
 #include "dir.h"
 #include "builtin.h"
 #include "parse-options.h"
+#include "quote.h"
 
 static unsigned long garbage;
 static off_t size_garbage;
@@ -73,6 +74,14 @@ static int count_cruft(const char *basename, const char *path, void *data)
        return 0;
 }
 
+static int print_alternate(struct alternate_object_database *alt, void *data)
+{
+       printf("alternate: ");
+       quote_c_style(alt->path, NULL, stdout, 0);
+       putchar('\n');
+       return 0;
+}
+
 static char const * const count_objects_usage[] = {
        N_("git count-objects [-v] [-H | --human-readable]"),
        NULL
@@ -140,6 +149,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
                printf("prune-packable: %lu\n", packed_loose);
                printf("garbage: %lu\n", garbage);
                printf("size-garbage: %s\n", garbage_buf.buf);
+               foreach_alt_odb(print_alternate, NULL);
                strbuf_release(&loose_buf);
                strbuf_release(&pack_buf);
                strbuf_release(&garbage_buf);
index 62170b7..e146a8d 100755 (executable)
@@ -39,6 +39,16 @@ test_expect_success 'preparing third repository' '
        )
 '
 
+test_expect_success 'count-objects shows the alternates' '
+       cat >expect <<-EOF &&
+       alternate: $(pwd)/B/.git/objects
+       alternate: $(pwd)/A/.git/objects
+       EOF
+       git -C C count-objects -v >actual &&
+       grep ^alternate: actual >actual.alternates &&
+       test_cmp expect actual.alternates
+'
+
 # Note: These tests depend on the hard-coded value of 5 as the maximum depth
 # we will follow recursion. We start the depth at 0 and count links, not
 # repositories. This means that in a chain like: