Web lists-archives.com

[PATCH 043/194] object-store: move loose object functions to new loose-object.h




From: Jonathan Nieder <jrnieder@xxxxxxxxx>

This should make these functions easier to find and cache.h less
overwhelming to read.

Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 builtin/cat-file.c      |  1 +
 builtin/count-objects.c |  1 +
 builtin/fsck.c          |  1 +
 builtin/pack-objects.c  |  1 +
 builtin/prune-packed.c  |  1 +
 builtin/prune.c         |  1 +
 cache.h                 | 75 ++--------------------------------------
 http-walker.c           |  1 +
 http.c                  |  1 +
 loose-object.h          | 91 +++++++++++++++++++++++++++++++++++++++++++++++++
 object-store.h          |  7 ----
 reachable.c             |  1 +
 sha1_file.c             |  1 +
 sha1_name.c             |  1 +
 14 files changed, 105 insertions(+), 79 deletions(-)
 create mode 100644 loose-object.h

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9d18efeb7c..fdc70aa419 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -9,6 +9,7 @@
 #include "diff.h"
 #include "parse-options.h"
 #include "userdiff.h"
+#include "loose-object.h"
 #include "streaming.h"
 #include "tree-walk.h"
 #include "sha1-array.h"
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 805803fedd..34f2bfa44e 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -10,6 +10,7 @@
 #include "repository.h"
 #include "alternates.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "quote.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 571aa51579..920cc50923 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -4,6 +4,7 @@
 #include "config.h"
 #include "alternates.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index d42df2a2b9..b998e139d1 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "attr.h"
 #include "object.h"
 #include "blob.h"
diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c
index 419238171d..2da1573359 100644
--- a/builtin/prune-packed.c
+++ b/builtin/prune-packed.c
@@ -2,6 +2,7 @@
 #include "cache.h"
 #include "progress.h"
 #include "parse-options.h"
+#include "loose-object.h"
 #include "packfile.h"
 
 static const char * const prune_packed_usage[] = {
diff --git a/builtin/prune.c b/builtin/prune.c
index d2fdae680a..52091f299e 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -3,6 +3,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "builtin.h"
+#include "loose-object.h"
 #include "reachable.h"
 #include "parse-options.h"
 #include "progress.h"
diff --git a/cache.h b/cache.h
index b002c9a96d..7be9a8ad27 100644
--- a/cache.h
+++ b/cache.h
@@ -1244,19 +1244,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
 
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
-/*
- * Open the loose object at path, check its sha1, and return the contents,
- * type, and size. If the object is a blob, then "contents" may return NULL,
- * to allow streaming of large blobs.
- *
- * Returns 0 on success, negative on error (details may be written to stderr).
- */
-int read_loose_object(const char *path,
-		      const unsigned char *expected_sha1,
-		      enum object_type *type,
-		      unsigned long *size,
-		      void **contents);
-
 /*
  * Convenience for sha1_object_info_extended() with a NULL struct
  * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
@@ -1272,13 +1259,6 @@ static inline int has_sha1_file(const unsigned char *sha1)
 extern int has_object_file(const struct object_id *oid);
 extern int has_object_file_with_flags(const struct object_id *oid, int flags);
 
-/*
- * Return true iff an alternate object database has a loose object
- * with the specified name.  This function does not respect replace
- * references.
- */
-extern int has_loose_object_nonlocal(const unsigned char *sha1);
-
 extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect);
 
 /* Helper to check and "touch" a file */
@@ -1595,60 +1575,11 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern);
 extern int odb_pack_keep(const char *name);
 
 /*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- *  - loose_object is called for each loose object we find.
- *
- *  - loose_cruft is called for any files that do not appear to be
- *    loose objects. Note that we only look in the loose object
- *    directories "objects/[0-9a-f]{2}/", so we will not report
- *    "objects/foobar" as cruft.
- *
- *  - loose_subdir is called for each top-level hashed subdirectory
- *    of the object directory (e.g., "$OBJDIR/f0"). It is called
- *    after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
-				 const char *path,
-				 void *data);
-typedef int each_loose_cruft_fn(const char *basename,
-				const char *path,
-				void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
-				 const char *path,
-				 void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
-				struct strbuf *path,
-				each_loose_object_fn obj_cb,
-				each_loose_cruft_fn cruft_cb,
-				each_loose_subdir_fn subdir_cb,
-				void *data);
-int for_each_loose_file_in_objdir(const char *path,
-				  each_loose_object_fn obj_cb,
-				  each_loose_cruft_fn cruft_cb,
-				  each_loose_subdir_fn subdir_cb,
-				  void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
-				      each_loose_object_fn obj_cb,
-				      each_loose_cruft_fn cruft_cb,
-				      each_loose_subdir_fn subdir_cb,
-				      void *data);
-
-/*
- * Iterate over loose objects in both the local
- * repository and any alternates repositories (unless the
- * LOCAL_ONLY flag is set).
+ * Flag for for_each_packed_object and for_each_loose_object to only iterate
+ * over objects in the local repository, and not any alternates (see
+ * alternates.h).
  */
 #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
-extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
 
 struct object_info {
 	/* Request */
diff --git a/http-walker.c b/http-walker.c
index 96873bdfed..34594165b1 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -6,6 +6,7 @@
 #include "list.h"
 #include "transport.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "packfile.h"
 
 struct alt_base {
diff --git a/http.c b/http.c
index ad57476635..e04eca601b 100644
--- a/http.c
+++ b/http.c
@@ -3,6 +3,7 @@
 #include "repository.h"
 #include "config.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/loose-object.h b/loose-object.h
new file mode 100644
index 0000000000..7d721ae4f0
--- /dev/null
+++ b/loose-object.h
@@ -0,0 +1,91 @@
+#ifndef LOOSE_OBJECT_H
+#define LOOSE_OBJECT_H
+
+#include "cache.h"
+#include "strbuf.h"
+#include "repository.h"
+
+/*
+ * Open the loose object at path, check its sha1, and return the contents,
+ * type, and size. If the object is a blob, then "contents" may return NULL,
+ * to allow streaming of large blobs.
+ *
+ * Returns 0 on success, negative on error (details may be written to stderr).
+ */
+int read_loose_object(const char *path,
+		      const unsigned char *expected_sha1,
+		      enum object_type *type,
+		      unsigned long *size,
+		      void **contents);
+
+/*
+ * Return true iff an alternate object database has a loose object
+ * with the specified name.  This function does not respect replace
+ * references.
+ */
+extern int has_loose_object_nonlocal(const unsigned char *sha1);
+
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ *  - loose_object is called for each loose object we find.
+ *
+ *  - loose_cruft is called for any files that do not appear to be
+ *    loose objects. Note that we only look in the loose object
+ *    directories "objects/[0-9a-f]{2}/", so we will not report
+ *    "objects/foobar" as cruft.
+ *
+ *  - loose_subdir is called for each top-level hashed subdirectory
+ *    of the object directory (e.g., "$OBJDIR/f0"). It is called
+ *    after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+				 const char *path,
+				 void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+				const char *path,
+				void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+				 const char *path,
+				 void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+				struct strbuf *path,
+				each_loose_object_fn obj_cb,
+				each_loose_cruft_fn cruft_cb,
+				each_loose_subdir_fn subdir_cb,
+				void *data);
+int for_each_loose_file_in_objdir(const char *path,
+				  each_loose_object_fn obj_cb,
+				  each_loose_cruft_fn cruft_cb,
+				  each_loose_subdir_fn subdir_cb,
+				  void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+				      each_loose_object_fn obj_cb,
+				      each_loose_cruft_fn cruft_cb,
+				      each_loose_subdir_fn subdir_cb,
+				      void *data);
+
+/*
+ * Iterate over loose objects in both the local
+ * repository and any alternates repositories (unless the
+ * FOR_EACH_OBJECT_LOCAL_ONLY flag, defined in cache.h, is set).
+ */
+extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
+
+/*
+ * Return the name of the file in a repository's local object database
+ * that would be used to store a loose object with the specified sha1.
+ * The return value is a pointer to a statically allocated buffer that
+ * is overwritten each time the function is called.
+ */
+extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);
+
+#endif
diff --git a/object-store.h b/object-store.h
index 967dd8af26..7a372baa79 100644
--- a/object-store.h
+++ b/object-store.h
@@ -66,13 +66,6 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
-/*
- * Return the name of the file in a repository's local object database
- * that would be used to store a loose object with the specified sha1.
- * The return value is a pointer to a statically allocated buffer that
- * is overwritten each time the function is called.
- */
-extern const char *sha1_file_name(struct repository *r, const unsigned char *sha1);
 extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
 
 #endif /* OBJECT_STORE_H */
diff --git a/reachable.c b/reachable.c
index 59ed16ba76..ac5224b9a5 100644
--- a/reachable.c
+++ b/reachable.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "tag.h"
 #include "commit.h"
 #include "blob.h"
diff --git a/sha1_file.c b/sha1_file.c
index 84501d66e9..2584465e9c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -25,6 +25,7 @@
 #include "bulk-checkin.h"
 #include "repository.h"
 #include "object-store.h"
+#include "loose-object.h"
 #include "streaming.h"
 #include "path.h"
 #include "dir.h"
diff --git a/sha1_name.c b/sha1_name.c
index 363f7e1d4d..03ce2ff7f2 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "alternates.h"
+#include "loose-object.h"
 #include "tag.h"
 #include "commit.h"
 #include "tree.h"
-- 
2.15.1.433.g936d1b9894.dirty