diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-10-27 14:58:47 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-27 14:58:47 -0700 |
commit | d7ae013a3173c621a3556be6834d459ece60e130 (patch) | |
tree | 3fc7d1145c484923f1a006a94029d67ffc56a685 /sha1_file.c | |
parent | 580d820ece78100c5e2b8b5874d7aed5d76715f2 (diff) | |
parent | 8e3f52d77854a19cb3fd2adee40be84c8a8bdacc (diff) | |
download | git-d7ae013a3173c621a3556be6834d459ece60e130.tar.gz |
Merge branch 'jk/abbrev-auto'
Updates the way approximate count of total objects is computed
while attempting to come up with a unique abbreviated object name,
which in turn needs to estimate how many hexdigits are necessary to
ensure uniqueness.
* jk/abbrev-auto:
find_unique_abbrev: move logic out of get_short_sha1()
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 2eda9291ee..1e41954a84 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1410,6 +1410,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; @@ -1481,6 +1507,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(); } |