@@ -55,12 +55,12 @@ struct commit *lookup_commit(const unsigned char *sha1)
55
55
56
56
struct commit * lookup_commit_reference_by_name (const char * name )
57
57
{
58
- unsigned char sha1 [ 20 ] ;
58
+ struct object_id oid ;
59
59
struct commit * commit ;
60
60
61
- if (get_sha1_committish (name , sha1 ))
61
+ if (get_sha1_committish (name , oid . hash ))
62
62
return NULL ;
63
- commit = lookup_commit_reference (sha1 );
63
+ commit = lookup_commit_reference (oid . hash );
64
64
if (parse_commit (commit ))
65
65
return NULL ;
66
66
return commit ;
@@ -99,7 +99,7 @@ static int commit_graft_alloc, commit_graft_nr;
99
99
static const unsigned char * commit_graft_sha1_access (size_t index , void * table )
100
100
{
101
101
struct commit_graft * * commit_graft_table = table ;
102
- return commit_graft_table [index ]-> sha1 ;
102
+ return commit_graft_table [index ]-> oid . hash ;
103
103
}
104
104
105
105
static int commit_graft_pos (const unsigned char * sha1 )
@@ -110,7 +110,7 @@ static int commit_graft_pos(const unsigned char *sha1)
110
110
111
111
int register_commit_graft (struct commit_graft * graft , int ignore_dups )
112
112
{
113
- int pos = commit_graft_pos (graft -> sha1 );
113
+ int pos = commit_graft_pos (graft -> oid . hash );
114
114
115
115
if (0 <= pos ) {
116
116
if (ignore_dups )
@@ -138,22 +138,23 @@ struct commit_graft *read_graft_line(char *buf, int len)
138
138
/* The format is just "Commit Parent1 Parent2 ...\n" */
139
139
int i ;
140
140
struct commit_graft * graft = NULL ;
141
+ const int entry_size = GIT_SHA1_HEXSZ + 1 ;
141
142
142
143
while (len && isspace (buf [len - 1 ]))
143
144
buf [-- len ] = '\0' ;
144
145
if (buf [0 ] == '#' || buf [0 ] == '\0' )
145
146
return NULL ;
146
- if ((len + 1 ) % 41 )
147
+ if ((len + 1 ) % entry_size )
147
148
goto bad_graft_data ;
148
- i = (len + 1 ) / 41 - 1 ;
149
- graft = xmalloc (sizeof (* graft ) + 20 * i );
149
+ i = (len + 1 ) / entry_size - 1 ;
150
+ graft = xmalloc (sizeof (* graft ) + GIT_SHA1_RAWSZ * i );
150
151
graft -> nr_parent = i ;
151
- if (get_sha1_hex (buf , graft -> sha1 ))
152
+ if (get_oid_hex (buf , & graft -> oid ))
152
153
goto bad_graft_data ;
153
- for (i = 40 ; i < len ; i += 41 ) {
154
+ for (i = GIT_SHA1_HEXSZ ; i < len ; i += entry_size ) {
154
155
if (buf [i ] != ' ' )
155
156
goto bad_graft_data ;
156
- if (get_sha1_hex (buf + i + 1 , graft -> parent [i /41 ] ))
157
+ if (get_sha1_hex (buf + i + 1 , graft -> parent [i /entry_size ]. hash ))
157
158
goto bad_graft_data ;
158
159
}
159
160
return graft ;
@@ -302,47 +303,50 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
302
303
{
303
304
const char * tail = buffer ;
304
305
const char * bufptr = buffer ;
305
- unsigned char parent [ 20 ] ;
306
+ struct object_id parent ;
306
307
struct commit_list * * pptr ;
307
308
struct commit_graft * graft ;
309
+ const int tree_entry_len = GIT_SHA1_HEXSZ + 5 ;
310
+ const int parent_entry_len = GIT_SHA1_HEXSZ + 7 ;
308
311
309
312
if (item -> object .parsed )
310
313
return 0 ;
311
314
item -> object .parsed = 1 ;
312
315
tail += size ;
313
- if (tail <= bufptr + 46 || memcmp (bufptr , "tree " , 5 ) || bufptr [45 ] != '\n' )
316
+ if (tail <= bufptr + tree_entry_len + 1 || memcmp (bufptr , "tree " , 5 ) ||
317
+ bufptr [tree_entry_len ] != '\n' )
314
318
return error ("bogus commit object %s" , sha1_to_hex (item -> object .sha1 ));
315
- if (get_sha1_hex (bufptr + 5 , parent ) < 0 )
319
+ if (get_sha1_hex (bufptr + 5 , parent . hash ) < 0 )
316
320
return error ("bad tree pointer in commit %s" ,
317
321
sha1_to_hex (item -> object .sha1 ));
318
- item -> tree = lookup_tree (parent );
319
- bufptr += 46 ; /* "tree " + "hex sha1" + "\n" */
322
+ item -> tree = lookup_tree (parent . hash );
323
+ bufptr += tree_entry_len + 1 ; /* "tree " + "hex sha1" + "\n" */
320
324
pptr = & item -> parents ;
321
325
322
326
graft = lookup_commit_graft (item -> object .sha1 );
323
- while (bufptr + 48 < tail && !memcmp (bufptr , "parent " , 7 )) {
327
+ while (bufptr + parent_entry_len < tail && !memcmp (bufptr , "parent " , 7 )) {
324
328
struct commit * new_parent ;
325
329
326
- if (tail <= bufptr + 48 ||
327
- get_sha1_hex (bufptr + 7 , parent ) ||
328
- bufptr [47 ] != '\n' )
330
+ if (tail <= bufptr + parent_entry_len + 1 ||
331
+ get_sha1_hex (bufptr + 7 , parent . hash ) ||
332
+ bufptr [parent_entry_len ] != '\n' )
329
333
return error ("bad parents in commit %s" , sha1_to_hex (item -> object .sha1 ));
330
- bufptr += 48 ;
334
+ bufptr += parent_entry_len + 1 ;
331
335
/*
332
336
* The clone is shallow if nr_parent < 0, and we must
333
337
* not traverse its real parents even when we unhide them.
334
338
*/
335
339
if (graft && (graft -> nr_parent < 0 || grafts_replace_parents ))
336
340
continue ;
337
- new_parent = lookup_commit (parent );
341
+ new_parent = lookup_commit (parent . hash );
338
342
if (new_parent )
339
343
pptr = & commit_list_insert (new_parent , pptr )-> next ;
340
344
}
341
345
if (graft ) {
342
346
int i ;
343
347
struct commit * new_parent ;
344
348
for (i = 0 ; i < graft -> nr_parent ; i ++ ) {
345
- new_parent = lookup_commit (graft -> parent [i ]);
349
+ new_parent = lookup_commit (graft -> parent [i ]. hash );
346
350
if (!new_parent )
347
351
continue ;
348
352
pptr = & commit_list_insert (new_parent , pptr )-> next ;
@@ -1580,10 +1584,10 @@ struct commit *get_merge_parent(const char *name)
1580
1584
{
1581
1585
struct object * obj ;
1582
1586
struct commit * commit ;
1583
- unsigned char sha1 [ 20 ] ;
1584
- if (get_sha1 (name , sha1 ))
1587
+ struct object_id oid ;
1588
+ if (get_sha1 (name , oid . hash ))
1585
1589
return NULL ;
1586
- obj = parse_object (sha1 );
1590
+ obj = parse_object (oid . hash );
1587
1591
commit = (struct commit * )peel_to_type (name , 0 , obj , OBJ_COMMIT );
1588
1592
if (commit && !commit -> util ) {
1589
1593
struct merge_remote_desc * desc ;
0 commit comments