Skip to content

Commit 5f7817c

Browse files
bk2204gitster
authored andcommitted
define a structure for object IDs
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1165ae6 commit 5f7817c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cache.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ int git_deflate_end_gently(git_zstream *);
4343
int git_deflate(git_zstream *, int flush);
4444
unsigned long git_deflate_bound(git_zstream *, unsigned long);
4545

46+
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
47+
#define GIT_SHA1_RAWSZ 20
48+
#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
49+
50+
struct object_id {
51+
unsigned char hash[GIT_SHA1_RAWSZ];
52+
};
53+
4654
#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
4755
#define DTYPE(de) ((de)->d_type)
4856
#else

0 commit comments

Comments
 (0)