git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/7] for_each_*_object: store flag definitions in a single location

From
Jeff King <peff@peff.net>
Date
Aug 10, 2018, 23:09 UTC
Message-ID
<20180810230906.GA19875@sigill.intra.peff.net>
In-Reply-To
<20180810230729.GA19090@sigill.intra.peff.net>

These flags were split between cache.h and packfile.h, because some of the flags apply only to packs. However, they share a single numeric namespace, since both are respected for the packed variant. Let's make sure they're defined together so that nobody accidentally adds a new flag in one location that duplicates the other.

While we're here, let's also put them in an enum (which helps debugger visibility) and use "(1<<n)" rather than counting powers of 2 manually.

Signed-off-by: Jeff King <peff@peff.net>
---
Arguably, all of these for_each_*_object() functions should stay
together. Even though some are related to packfiles and some to loose,
they are meant to be a unified API. So I'd be fine to do that on top,
but this at least reduces the chance of a mistake in the meantime.
 cache.h    | 13 ++++++++++++-
 packfile.h |  8 ++------
 2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/cache.h b/cache.h
index 8dc7134f00..4187238ecf 100644
--- a/cache.h
+++ b/cache.h
@@ -1623,12 +1623,23 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
 				      each_loose_subdir_fn subdir_cb,
 				      void *data);
 
+/*
+ * Flags for for_each_*_object(), including for_each_loose below and
+ * for_each_packed in packfile.h.
+ */
+enum for_each_object_flags {
+	/* Iterate only over local objects, not alternates. */
+	FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
+
+	/* Only iterate over packs obtained from the promisor remote. */
+	FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
+};
+
 /*
  * 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
 extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags);
 
 /*
diff --git a/packfile.h b/packfile.h
index cc7eaffe1b..6ddc6a2e91 100644
--- a/packfile.h
+++ b/packfile.h
@@ -148,15 +148,11 @@ extern int has_object_pack(const struct object_id *oid);
 
 extern int has_pack_index(const unsigned char *sha1);
 
-/*
- * Only iterate over packs obtained from the promisor remote.
- */
-#define FOR_EACH_OBJECT_PROMISOR_ONLY 2
-
 /*
  * 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).
+ * FOR_EACH_OBJECT_LOCAL_ONLY flag is set). See cache.h for the complete list
+ * of flags.
  */
 typedef int each_packed_object_fn(const struct object_id *oid,
 				  struct packed_git *pack,
-- 
2.18.0.1058.g7433f71063
Previous: Jeff KingNext: Stefan Beller
Message 2 of 27 in “speeding up cat-file by reordering object access”
  1. 0/7 speeding up cat-file by reordering object accessJeff King, Aug 10, 2018
  2. 1/7 for_each_*_object: store flag definitions in a single locationJeff King, Aug 10, 2018
  3. Stefan BellerAug 10, 2018
  4. Jeff KingAug 10, 2018
  5. Jeff KingAug 10, 2018
  6. Stefan BellerAug 10, 2018
  7. Jeff KingAug 11, 2018
  8. 2/7 for_each_*_object: take flag arguments as enumJeff King, Aug 10, 2018
  9. 3/7 for_each_*_object: give more comprehensive docstringsJeff King, Aug 10, 2018
  10. 4/7 for_each_packed_object: support iterating in pack-orderJeff King, Aug 10, 2018
  11. Derrick StoleeAug 15, 2018
  12. Jeff KingAug 16, 2018
  13. 5/7 t1006: test cat-file --batch-all-objects with duplicatesJeff King, Aug 10, 2018
  14. 6/7 cat-file: rename batch_{loose,packed}_object callbacksJeff King, Aug 10, 2018
  15. 7/7 cat-file: support "unordered" output for --batch-all-objectsJeff King, Aug 10, 2018
  16. Jonathan TanAug 13, 2018
  17. 0/4 finishing touches on jk/for-each-object-iterationJeff King, Aug 14, 2018
  18. 1/4 cat-file: use oidset check-and-insertJeff King, Aug 14, 2018
  19. 2/4 cat-file: split batch "buf" into two variablesJeff King, Aug 14, 2018
  20. 3/4 cat-file: use a single strbuf for all outputJeff King, Aug 14, 2018
  21. René ScharfeAug 14, 2018
  22. Jeff KingAug 14, 2018
  23. 4/4 for_each_*_object: move declarations to object-store.hJeff King, Aug 14, 2018
  24. Derrick StoleeAug 15, 2018
  25. Jeff KingAug 16, 2018
  26. Junio C HamanoAug 16, 2018
  27. Jeff KingAug 16, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.