pack: move for_each_packed_object()
authorJonathan Tan <jonathantanmy@google.com>
Fri, 18 Aug 2017 22:20:38 +0000 (15:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 22:12:07 +0000 (15:12 -0700)
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/cat-file.c
cache.h
packfile.c
packfile.h
reachable.c
sha1_file.c
index 62c8cf0ebf3f2ba063945fc44714a9da29b599ef..4ccbfaac3148287535aa8833d0d6cbdacb7c1d3d 100644 (file)
@@ -12,6 +12,7 @@
 #include "streaming.h"
 #include "tree-walk.h"
 #include "sha1-array.h"
 #include "streaming.h"
 #include "tree-walk.h"
 #include "sha1-array.h"
+#include "packfile.h"
 
 struct batch_options {
        int enabled;
 
 struct batch_options {
        int enabled;
diff --git a/cache.h b/cache.h
index c057d3fed3e4ff40f158e511b3c46fdbc3a3ab01..2f09f8814aadc15dbdec58e06da1e109742ffcd6 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1662,17 +1662,12 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
                                      void *data);
 
 /*
                                      void *data);
 
 /*
- * Iterate over loose and packed objects in both the local
+ * Iterate over loose objects in both the local
  * repository and any alternates repositories (unless the
  * LOCAL_ONLY flag is set).
  */
 #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
  * repository and any alternates repositories (unless the
  * LOCAL_ONLY flag is set).
  */
 #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
-typedef int each_packed_object_fn(const struct object_id *oid,
-                                 struct packed_git *pack,
-                                 uint32_t pos,
-                                 void *data);
 extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
 extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
-extern int for_each_packed_object(each_packed_object_fn, void *, unsigned flags);
 
 struct object_info {
        /* Request */
 
 struct object_info {
        /* Request */
index 84d16bf7e05fce0f7e30d20fbdaf5e854d9da5fe..f86fa051c9e67def994b8b487ad34f200967d5e9 100644 (file)
@@ -1854,3 +1854,43 @@ int has_pack_index(const unsigned char *sha1)
                return 0;
        return 1;
 }
                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;
+}
index d7df41a823101d5d1a8d6bce5a953acf0d500f67..0cdeb54dcd97a67c38285e8f81412ec71273fd7f 100644 (file)
@@ -124,4 +124,15 @@ extern int has_sha1_pack(const unsigned char *sha1);
 
 extern int has_pack_index(const unsigned char *sha1);
 
 
 extern int has_pack_index(const unsigned char *sha1);
 
+/*
+ * Iterate over packed objects in both the local
+ * repository and any alternates repositories (unless the
+ * FOR_EACH_OBJECT_LOCAL_ONLY flag, defined in cache.h, is set).
+ */
+typedef int each_packed_object_fn(const struct object_id *oid,
+                                 struct packed_git *pack,
+                                 uint32_t pos,
+                                 void *data);
+extern int for_each_packed_object(each_packed_object_fn, void *, unsigned flags);
+
 #endif
 #endif
index c62efbfd43b9c4ddc25d6768d55bddc745f5c14b..d1ac5d97efdaff5dc971e38da278dcf1d820ef2c 100644 (file)
@@ -9,6 +9,7 @@
 #include "cache-tree.h"
 #include "progress.h"
 #include "list-objects.h"
 #include "cache-tree.h"
 #include "progress.h"
 #include "list-objects.h"
+#include "packfile.h"
 
 struct connectivity_progress {
        struct progress *progress;
 
 struct connectivity_progress {
        struct progress *progress;
index 7c81790759765373b0d0daf0828df5ec63769e0b..bb0831b4c803919e90ce263c4aed31d7fedd4620 100644 (file)
@@ -2015,46 +2015,6 @@ int for_each_loose_object(each_loose_object_fn cb, void *data, unsigned flags)
        return foreach_alt_odb(loose_from_alt_odb, &alt);
 }
 
        return foreach_alt_odb(loose_from_alt_odb, &alt);
 }
 
-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;
-}
-
 static int check_stream_sha1(git_zstream *stream,
                             const char *hdr,
                             unsigned long size,
 static int check_stream_sha1(git_zstream *stream,
                             const char *hdr,
                             unsigned long size,