]> git.ipfire.org Git - thirdparty/git.git/commitdiff
define a structure for object IDs
authorbrian m. carlson <sandals@crustytoothpaste.net>
Fri, 13 Mar 2015 23:39:27 +0000 (23:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 14 Mar 2015 05:43:11 +0000 (22:43 -0700)
Many places throughout the code use "unsigned char [20]" to store object IDs
(SHA-1 values).  This leads to lots of hardcoded numbers throughout the
codebase.  It also leads to confusion about the purposes of a buffer.

Introduce a structure for object IDs.  This allows us to obtain the benefits
of compile-time checking for misuse.  The structure is expected to remain
the same size and have the same alignment requirements on all known
platforms, compared to the array of unsigned char, although this is not
required for correctness.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h

diff --git a/cache.h b/cache.h
index 4d02efc905456e61ce841ec1db2cc19491346257..40d06fde03bb40dda0466cc3b36e68b1e025cbe5 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -43,6 +43,14 @@ int git_deflate_end_gently(git_zstream *);
 int git_deflate(git_zstream *, int flush);
 unsigned long git_deflate_bound(git_zstream *, unsigned long);
 
+/* The length in bytes and in hex digits of an object name (SHA-1 value). */
+#define GIT_SHA1_RAWSZ 20
+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
+
+struct object_id {
+       unsigned char hash[GIT_SHA1_RAWSZ];
+};
+
 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
 #define DTYPE(de)      ((de)->d_type)
 #else