diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2017-08-18 15:20:38 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-08-23 15:12:07 -0700 |
commit | 7709f468fdeece2a99d60a581a4ced65cd2844df (patch) | |
tree | 37a26e9a350ec173d24f5578004e0000d3c6170e /packfile.c | |
parent | pack: move has_pack_index() (diff) | |
download | tgif-7709f468fdeece2a99d60a581a4ced65cd2844df.tar.xz |
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.c | 40 |
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; +} |