summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reachable.c42
-rwxr-xr-xt/perf/p5304-prune.sh11
2 files changed, 53 insertions, 0 deletions
diff --git a/reachable.c b/reachable.c
index 6e9b810d2a..0d00a91de4 100644
--- a/reachable.c
+++ b/reachable.c
@@ -12,6 +12,7 @@
#include "packfile.h"
#include "worktree.h"
#include "object-store.h"
+#include "pack-bitmap.h"
struct connectivity_progress {
struct progress *progress;
@@ -158,10 +159,44 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
FOR_EACH_OBJECT_LOCAL_ONLY);
}
+static void *lookup_object_by_type(struct repository *r,
+ const struct object_id *oid,
+ enum object_type type)
+{
+ switch (type) {
+ case OBJ_COMMIT:
+ return lookup_commit(r, oid);
+ case OBJ_TREE:
+ return lookup_tree(r, oid);
+ case OBJ_TAG:
+ return lookup_tag(r, oid);
+ case OBJ_BLOB:
+ return lookup_blob(r, oid);
+ default:
+ die("BUG: unknown object type %d", type);
+ }
+}
+
+static int mark_object_seen(const struct object_id *oid,
+ enum object_type type,
+ int exclude,
+ uint32_t name_hash,
+ struct packed_git *found_pack,
+ off_t found_offset)
+{
+ struct object *obj = lookup_object_by_type(the_repository, oid, type);
+ if (!obj)
+ die("unable to create object '%s'", oid_to_hex(oid));
+
+ obj->flags |= SEEN;
+ return 0;
+}
+
void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
timestamp_t mark_recent, struct progress *progress)
{
struct connectivity_progress cp;
+ struct bitmap_index *bitmap_git;
/*
* Set up revision parsing, and mark us as being interested
@@ -188,6 +223,13 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
cp.progress = progress;
cp.count = 0;
+ bitmap_git = prepare_bitmap_walk(revs);
+ if (bitmap_git) {
+ traverse_bitmap_commit_list(bitmap_git, mark_object_seen);
+ free_bitmap_index(bitmap_git);
+ return;
+ }
+
/*
* Set up the revision walk - this will move all commits
* from the pending list to the commit walking list.
diff --git a/t/perf/p5304-prune.sh b/t/perf/p5304-prune.sh
index 3c852084eb..83baedb8a4 100755
--- a/t/perf/p5304-prune.sh
+++ b/t/perf/p5304-prune.sh
@@ -21,4 +21,15 @@ test_perf 'prune with no objects' '
git prune
'
+test_expect_success 'repack with bitmaps' '
+ git repack -adb
+'
+
+# We have to create the object in each trial run, since otherwise
+# runs after the first see no object and just skip the traversal entirely!
+test_perf 'prune with bitmaps' '
+ echo "probably not present in repo" | git hash-object -w --stdin &&
+ git prune
+'
+
test_done