path: root/builtin-count-objects.c
diff options
authorShawn O. Pearce <>2007-05-26 05:24:19 (GMT)
committerJunio C Hamano <>2007-05-27 03:28:08 (GMT)
commitd079837eeeadc37d266113a1fd2deb0a01aaee91 (patch)
tree96af52e5f25b1152674763a1c819d892bd75f9bb /builtin-count-objects.c
parent99b5a79e1329468bee26ae3bd9070c47418279d0 (diff)
Lazily open pack index files on demand
In some repository configurations the user may have many packfiles, but all of the recent commits/trees/tags/blobs are likely to be in the most recent packfile (the one with the newest mtime). It is therefore common to be able to complete an entire operation by accessing only one packfile, even if there are 25 packfiles available to the repository. Rather than opening and mmaping the corresponding .idx file for every pack found, we now only open and map the .idx when we suspect there might be an object of interest in there. Of course we cannot known in advance which packfile contains an object, so we still need to scan the entire packed_git list to locate anything. But odds are users want to access objects in the most recently created packfiles first, and that may be all they ever need for the current operation. Junio observed in b867092f that placing recent packfiles before older ones can slightly improve access times for recent objects, without degrading it for historical object access. This change improves upon Junio's observations by trying even harder to avoid the .idx files that we won't need. Signed-off-by: Shawn O. Pearce <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin-count-objects.c')
1 files changed, 2 insertions, 0 deletions
diff --git a/builtin-count-objects.c b/builtin-count-objects.c
index ff90ebd..ac65e03 100644
--- a/builtin-count-objects.c
+++ b/builtin-count-objects.c
@@ -111,6 +111,8 @@ int cmd_count_objects(int ac, const char **av, const char *prefix)
for (p = packed_git; p; p = p->next) {
if (!p->pack_local)
+ if (!p->index_data && open_pack_index(p))
+ continue;
packed += p->num_objects;