Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-08-19 01:20:38 +0300
committerJunio C Hamano <gitster@pobox.com>2017-08-24 01:12:07 +0300
commit7709f468fdeece2a99d60a581a4ced65cd2844df (patch)
tree37a26e9a350ec173d24f5578004e0000d3c6170e /packfile.c
parentf9a8672a81277b83cabd59c6705089351c4f3ec4 (diff)
pack: move for_each_packed_object()
Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/packfile.c b/packfile.c
index 84d16bf7e0..f86fa051c9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1854,3 +1854,43 @@ int has_pack_index(const unsigned char *sha1)
return 0;
return 1;
}
+
+static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn cb, void *data)
+{
+ uint32_t i;
+ int r = 0;
+
+ for (i = 0; i < p->num_objects; i++) {
+ struct object_id oid;
+
+ if (!nth_packed_object_oid(&oid, p, i))
+ return error("unable to get sha1 of object %u in %s",
+ i, p->pack_name);
+
+ r = cb(&oid, p, i, data);
+ if (r)
+ break;
+ }
+ return r;
+}
+
+int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
+{
+ struct packed_git *p;
+ int r = 0;
+ int pack_errors = 0;
+
+ prepare_packed_git();
+ for (p = packed_git; p; p = p->next) {
+ if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
+ continue;
+ if (open_pack_index(p)) {
+ pack_errors = 1;
+ continue;
+ }
+ r = for_each_object_in_pack(p, cb, data);
+ if (r)
+ break;
+ }
+ return r ? r : pack_errors;
+}