44
44
/* The maximum size for an object header. */
45
45
#define MAX_HEADER_LEN 32
46
46
47
-
48
- #define EMPTY_TREE_SHA1_BIN_LITERAL \
49
- "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
50
- "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
51
- #define EMPTY_TREE_SHA256_BIN_LITERAL \
52
- "\x6e\xf1\x9b\x41\x22\x5c\x53\x69\xf1\xc1" \
53
- "\x04\xd4\x5d\x8d\x85\xef\xa9\xb0\x57\xb5" \
54
- "\x3b\x14\xb4\xb9\xb9\x39\xdd\x74\xde\xcc" \
55
- "\x53\x21"
56
-
57
- #define EMPTY_BLOB_SHA1_BIN_LITERAL \
58
- "\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
59
- "\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
60
- #define EMPTY_BLOB_SHA256_BIN_LITERAL \
61
- "\x47\x3a\x0f\x4c\x3b\xe8\xa9\x36\x81\xa2" \
62
- "\x67\xe3\xb1\xe9\xa7\xdc\xda\x11\x85\x43" \
63
- "\x6f\xe1\x41\xf7\x74\x91\x20\xa3\x03\x72" \
64
- "\x18\x13"
65
-
66
47
static const struct object_id empty_tree_oid = {
67
- .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
+ },
68
52
.algo = GIT_HASH_SHA1 ,
69
53
};
70
54
static const struct object_id empty_blob_oid = {
71
- .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
+ },
72
59
.algo = GIT_HASH_SHA1 ,
73
60
};
74
61
static const struct object_id null_oid_sha1 = {
75
62
.hash = {0 },
76
63
.algo = GIT_HASH_SHA1 ,
77
64
};
78
65
static const struct object_id empty_tree_oid_sha256 = {
79
- .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
+ },
80
72
.algo = GIT_HASH_SHA256 ,
81
73
};
82
74
static const struct object_id empty_blob_oid_sha256 = {
83
- .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
+ },
84
81
.algo = GIT_HASH_SHA256 ,
85
82
};
86
83
static const struct object_id null_oid_sha256 = {
@@ -313,30 +310,28 @@ int hash_algo_by_length(int len)
313
310
* to write them into the object store (e.g. a browse-only
314
311
* application).
315
312
*/
316
- static struct cached_object {
313
+ static struct cached_object_entry {
317
314
struct object_id oid ;
318
- enum object_type type ;
319
- const void * buf ;
320
- unsigned long size ;
315
+ struct cached_object {
316
+ enum object_type type ;
317
+ const void * buf ;
318
+ unsigned long size ;
319
+ } value ;
321
320
} * cached_objects ;
322
321
static int cached_object_nr , cached_object_alloc ;
323
322
324
- static struct cached_object empty_tree = {
325
- .oid = {
326
- .hash = EMPTY_TREE_SHA1_BIN_LITERAL ,
327
- },
328
- .type = OBJ_TREE ,
329
- .buf = "" ,
330
- };
331
-
332
- static struct cached_object * find_cached_object (const struct object_id * oid )
323
+ static const struct cached_object * find_cached_object (const struct object_id * oid )
333
324
{
325
+ static const struct cached_object empty_tree = {
326
+ .type = OBJ_TREE ,
327
+ .buf = "" ,
328
+ };
334
329
int i ;
335
- struct cached_object * co = cached_objects ;
330
+ const struct cached_object_entry * co = cached_objects ;
336
331
337
332
for (i = 0 ; i < cached_object_nr ; i ++ , co ++ ) {
338
333
if (oideq (& co -> oid , oid ))
339
- return co ;
334
+ return & co -> value ;
340
335
}
341
336
if (oideq (oid , the_hash_algo -> empty_tree ))
342
337
return & empty_tree ;
@@ -1627,7 +1622,7 @@ static int do_oid_object_info_extended(struct repository *r,
1627
1622
struct object_info * oi , unsigned flags )
1628
1623
{
1629
1624
static struct object_info blank_oi = OBJECT_INFO_INIT ;
1630
- struct cached_object * co ;
1625
+ const struct cached_object * co ;
1631
1626
struct pack_entry e ;
1632
1627
int rtype ;
1633
1628
const struct object_id * real = oid ;
@@ -1849,7 +1844,7 @@ int oid_object_info(struct repository *r,
1849
1844
int pretend_object_file (void * buf , unsigned long len , enum object_type type ,
1850
1845
struct object_id * oid )
1851
1846
{
1852
- struct cached_object * co ;
1847
+ struct cached_object_entry * co ;
1853
1848
char * co_buf ;
1854
1849
1855
1850
hash_object_file (the_hash_algo , buf , len , type , oid );
@@ -1858,11 +1853,11 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1858
1853
return 0 ;
1859
1854
ALLOC_GROW (cached_objects , cached_object_nr + 1 , cached_object_alloc );
1860
1855
co = & cached_objects [cached_object_nr ++ ];
1861
- co -> size = len ;
1862
- co -> type = type ;
1856
+ co -> value . size = len ;
1857
+ co -> value . type = type ;
1863
1858
co_buf = xmalloc (len );
1864
1859
memcpy (co_buf , buf , len );
1865
- co -> buf = co_buf ;
1860
+ co -> value . buf = co_buf ;
1866
1861
oidcpy (& co -> oid , oid );
1867
1862
return 0 ;
1868
1863
}
0 commit comments