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

[PATCH v12 1/8] cache: add empty_tree_oid object and helper function

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Aug 31, 2016, 23:27 UTC
Message-ID
<20160831232725.28205-2-jacob.e.keller@intel.com>
In-Reply-To
<20160831232725.28205-1-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>

Similar to is_null_oid(), and is_empty_blob_sha1() add an empty_tree_oid along with helper function is_empty_tree_oid(). For completeness, also add an "is_empty_tree_sha1()", "is_empty_blob_sha1()", "is_empty_tree_oid()" and "is_empty_blob_oid()" helpers.

To ensure we only get one singleton, implement EMPTY_BLOB_SHA1_BIN as simply getting the hash of empty_blob_oid structure.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 cache.h     | 25 +++++++++++++++++++++----
 sha1_file.c |  6 ++++++
 2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/cache.h b/cache.h
index 95a0bd397a98..2ac37ee070c0 100644
--- a/cache.h
+++ b/cache.h
@@ -953,22 +953,39 @@ static inline void oidclr(struct object_id *oid)
 #define EMPTY_TREE_SHA1_BIN_LITERAL \
 	 "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
 	 "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
-#define EMPTY_TREE_SHA1_BIN \
-	 ((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)
+extern const struct object_id empty_tree_oid;
+#define EMPTY_TREE_SHA1_BIN (empty_tree_oid.hash)
 
 #define EMPTY_BLOB_SHA1_HEX \
 	"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
 #define EMPTY_BLOB_SHA1_BIN_LITERAL \
 	"\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
 	"\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
-#define EMPTY_BLOB_SHA1_BIN \
-	((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL)
+extern const struct object_id empty_blob_oid;
+#define EMPTY_BLOB_SHA1_BIN (empty_blob_oid.hash)
+
 
 static inline int is_empty_blob_sha1(const unsigned char *sha1)
 {
 	return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
 }
 
+static inline int is_empty_blob_oid(const struct object_id *oid)
+{
+	return !hashcmp(oid->hash, EMPTY_BLOB_SHA1_BIN);
+}
+
+static inline int is_empty_tree_sha1(const unsigned char *sha1)
+{
+	return !hashcmp(sha1, EMPTY_TREE_SHA1_BIN);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid)
+{
+	return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN);
+}
+
+
 int git_mkstemp(char *path, size_t n, const char *template);
 
 /* set default permissions by passing mode arguments to open(2) */
diff --git a/sha1_file.c b/sha1_file.c
index 02940f192030..5b8553d69e06 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -38,6 +38,12 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }
 
 const unsigned char null_sha1[20];
 const struct object_id null_oid;
+const struct object_id empty_tree_oid = {
+	EMPTY_TREE_SHA1_BIN_LITERAL
+};
+const struct object_id empty_blob_oid = {
+	EMPTY_BLOB_SHA1_BIN_LITERAL
+};
 
 /*
  * This is meant to hold a *small* number of objects that you would
-- 
2.10.0.rc2.311.g2bd286e
Previous: Jacob KellerNext: Jacob Keller
Message 2 of 23 in “submodule inline diff format”
  1. 0/8 submodule inline diff formatJacob Keller, Aug 31, 2016
  2. 1/8 cache: add empty_tree_oid object and helper functionJacob Keller, Aug 31, 2016
  3. 8/8 diff: teach diff to display submodule difference with an inline diffJacob Keller, Aug 31, 2016
  4. 7/8 submodule: refactor show_submodule_summary with helper functionJacob Keller, Aug 31, 2016
  5. 6/8 submodule: convert show_submodule_summary to use struct object_id *Jacob Keller, Aug 31, 2016
  6. 5/8 allow do_submodule_path to work even if submodule isn't checked outJacob Keller, Aug 31, 2016
  7. 4/8 diff: prepare for additional submodule formatsJacob Keller, Aug 31, 2016
  8. 3/8 graph: add support for --line-prefix on all graph-aware outputJacob Keller, Aug 31, 2016
  9. Dennis KaarsemakerOct 19, 2016
  10. rev-list: restore the NUL commit separator in --header modeDennis Kaarsemaker, Oct 19, 2016
  11. Jacob KellerOct 19, 2016
  12. Junio C HamanoOct 19, 2016
  13. Keller, Jacob EOct 20, 2016
  14. Dennis KaarsemakerOct 20, 2016
  15. Junio C HamanoOct 19, 2016
  16. Dennis KaarsemakerOct 20, 2016
  17. Jacob KellerOct 20, 2016
  18. Junio C HamanoOct 20, 2016
  19. Torsten BögershausenOct 20, 2016
  20. Jacob KellerOct 19, 2016
  21. 2/8 diff.c: remove output_prefix_length fieldJacob Keller, Aug 31, 2016
  22. Stefan BellerAug 31, 2016
  23. Junio C HamanoSep 1, 2016

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.