Skip to content

Commit 2af8ead

Browse files
peffgitster
authored andcommitted
object-file: inline empty tree and blob literals
We define macros with the bytes of the empty trees and blobs for sha1 and sha256. But since e1ccd7e (sha1_file: only expose empty object constants through git_hash_algo, 2018-05-02), those are used only for initializing the git_hash_algo entries. Any other code using the macros directly would be suspicious, since a hash_algo pointer is the level of indirection we use to make everything work with both sha1 and sha256. So let's future proof against code doing the wrong thing by dropping the macros entirely and just initializing the structs directly. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e37feea commit 2af8ead

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

object-file.c

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,40 @@
4444
/* The maximum size for an object header. */
4545
#define MAX_HEADER_LEN 32
4646

47-
48-
#define EMPTY_TREE_SHA1_BIN_LITERAL { \
49-
0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, \
50-
0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 \
51-
}
52-
#define EMPTY_TREE_SHA256_BIN_LITERAL { \
53-
0x6e, 0xf1, 0x9b, 0x41, 0x22, 0x5c, 0x53, 0x69, 0xf1, 0xc1, \
54-
0x04, 0xd4, 0x5d, 0x8d, 0x85, 0xef, 0xa9, 0xb0, 0x57, 0xb5, \
55-
0x3b, 0x14, 0xb4, 0xb9, 0xb9, 0x39, 0xdd, 0x74, 0xde, 0xcc, \
56-
0x53, 0x21 \
57-
}
58-
59-
#define EMPTY_BLOB_SHA1_BIN_LITERAL { \
60-
0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, \
61-
0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 \
62-
}
63-
#define EMPTY_BLOB_SHA256_BIN_LITERAL { \
64-
0x47, 0x3a, 0x0f, 0x4c, 0x3b, 0xe8, 0xa9, 0x36, 0x81, 0xa2, \
65-
0x67, 0xe3, 0xb1, 0xe9, 0xa7, 0xdc, 0xda, 0x11, 0x85, 0x43, \
66-
0x6f, 0xe1, 0x41, 0xf7, 0x74, 0x91, 0x20, 0xa3, 0x03, 0x72, \
67-
0x18, 0x13 \
68-
}
69-
7047
static const struct object_id empty_tree_oid = {
71-
.hash = EMPTY_TREE_SHA1_BIN_LITERAL,
48+
.hash = {
49+
0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
50+
0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04
51+
},
7252
.algo = GIT_HASH_SHA1,
7353
};
7454
static const struct object_id empty_blob_oid = {
75-
.hash = EMPTY_BLOB_SHA1_BIN_LITERAL,
55+
.hash = {
56+
0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b,
57+
0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91
58+
},
7659
.algo = GIT_HASH_SHA1,
7760
};
7861
static const struct object_id null_oid_sha1 = {
7962
.hash = {0},
8063
.algo = GIT_HASH_SHA1,
8164
};
8265
static const struct object_id empty_tree_oid_sha256 = {
83-
.hash = EMPTY_TREE_SHA256_BIN_LITERAL,
66+
.hash = {
67+
0x6e, 0xf1, 0x9b, 0x41, 0x22, 0x5c, 0x53, 0x69, 0xf1, 0xc1,
68+
0x04, 0xd4, 0x5d, 0x8d, 0x85, 0xef, 0xa9, 0xb0, 0x57, 0xb5,
69+
0x3b, 0x14, 0xb4, 0xb9, 0xb9, 0x39, 0xdd, 0x74, 0xde, 0xcc,
70+
0x53, 0x21
71+
},
8472
.algo = GIT_HASH_SHA256,
8573
};
8674
static const struct object_id empty_blob_oid_sha256 = {
87-
.hash = EMPTY_BLOB_SHA256_BIN_LITERAL,
75+
.hash = {
76+
0x47, 0x3a, 0x0f, 0x4c, 0x3b, 0xe8, 0xa9, 0x36, 0x81, 0xa2,
77+
0x67, 0xe3, 0xb1, 0xe9, 0xa7, 0xdc, 0xda, 0x11, 0x85, 0x43,
78+
0x6f, 0xe1, 0x41, 0xf7, 0x74, 0x91, 0x20, 0xa3, 0x03, 0x72,
79+
0x18, 0x13
80+
},
8881
.algo = GIT_HASH_SHA256,
8982
};
9083
static const struct object_id null_oid_sha256 = {

0 commit comments

Comments
 (0)