diff options
author | Jeff King <peff@peff.net> | 2016-10-03 19:47:28 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-03 21:03:14 -0700 |
commit | 8e3f52d77854a19cb3fd2adee40be84c8a8bdacc (patch) | |
tree | d342eca5c1880a5286108a8e12e71eee8ca2b44a /sha1_file.c | |
parent | e6c587c733b4634030b353f4024794b08bc86892 (diff) | |
download | git-8e3f52d77854a19cb3fd2adee40be84c8a8bdacc.tar.gz |
find_unique_abbrev: move logic out of get_short_sha1()jk/abbrev-auto
The get_short_sha1() is only about reading short sha1s; we
do call it in a loop to check "is this long enough" for each
object, but otherwise it should not need to know about
things like our default_abbrev setting.
So instead of asking it to set default_automatic_abbrev as a
side-effect, let's just have find_unique_abbrev() pick the
right place to start its loop. This requires a separate
approximate_object_count() function, but that naturally
belongs with the rest of sha1_file.c.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c index b9c1fa3f1a..48824407aa 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1381,6 +1381,32 @@ static void prepare_packed_git_one(char *objdir, int local) strbuf_release(&path); } +static int approximate_object_count_valid; + +/* + * Give a fast, rough count of the number of objects in the repository. This + * ignores loose objects completely. If you have a lot of them, then either + * you should repack because your performance will be awful, or they are + * all unreachable objects about to be pruned, in which case they're not really + * interesting as a measure of repo size in the first place. + */ +unsigned long approximate_object_count(void) +{ + static unsigned long count; + if (!approximate_object_count_valid) { + struct packed_git *p; + + prepare_packed_git(); + count = 0; + for (p = packed_git; p; p = p->next) { + if (open_pack_index(p)) + continue; + count += p->num_objects; + } + } + return count; +} + static void *get_next_packed_git(const void *p) { return ((const struct packed_git *)p)->next; @@ -1455,6 +1481,7 @@ void prepare_packed_git(void) void reprepare_packed_git(void) { + approximate_object_count_valid = 0; prepare_packed_git_run_once = 0; prepare_packed_git(); } |