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

[PATCH] Define constants for lengths of object names

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
May 1, 2014, 11:06 UTC
Message-ID
<1398942410-112069-1-git-send-email-sandals@crustytoothpaste.net>

Using preprocessor constants rather than hardcoded numbers is considered a good programming practice. Provide two constants, GIT_OID_RAWSZ and GIT_OID_HEXSZ, which are the lengths of an SHA-1 object name in bytes and hex digits, respectively. These names are the same as those used by libgit2.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 object.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/object.h b/object.h
index 6e12f2c..f1cff2d 100644
--- a/object.h
+++ b/object.h
@@ -1,6 +1,13 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
+/*
+ * The length in bytes and in hex digits of an object name (SHA-1 value).
+ * These are the same names used by libgit2.
+ */
+#define GIT_OID_RAWSZ 20
+#define GIT_OID_HEXSZ 40
+
 struct object_list {
 	struct object *item;
 	struct object_list *next;
@@ -49,7 +56,7 @@ struct object {
 	unsigned used : 1;
 	unsigned type : TYPE_BITS;
 	unsigned flags : FLAG_BITS;
-	unsigned char sha1[20];
+	unsigned char sha1[GIT_OID_RAWSZ];
 };
 
 extern const char *typename(unsigned int type);
-- 
2.0.0.rc0
Next: Jonathan Nieder
Message 1 of 7 in “Define constants for lengths of object names”
  1. Define constants for lengths of object namesbrian m. carlson, May 1, 2014
  2. Jonathan NiederMay 1, 2014
  3. Jonathan NiederMay 1, 2014
  4. brian m. carlsonMay 1, 2014
  5. Jonathan NiederMay 1, 2014
  6. Duy NguyenMay 2, 2014
  7. brian m. carlsonMay 2, 2014

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.