@@ -55,12 +55,12 @@ struct commit *lookup_commit(const unsigned char *sha1)
5555
5656struct commit * lookup_commit_reference_by_name (const char * name )
5757{
58- unsigned char sha1 [ 20 ] ;
58+ struct object_id oid ;
5959 struct commit * commit ;
6060
61- if (get_sha1_committish (name , sha1 ))
61+ if (get_sha1_committish (name , oid . hash ))
6262 return NULL ;
63- commit = lookup_commit_reference (sha1 );
63+ commit = lookup_commit_reference (oid . hash );
6464 if (parse_commit (commit ))
6565 return NULL ;
6666 return commit ;
@@ -99,7 +99,7 @@ static int commit_graft_alloc, commit_graft_nr;
9999static const unsigned char * commit_graft_sha1_access (size_t index , void * table )
100100{
101101 struct commit_graft * * commit_graft_table = table ;
102- return commit_graft_table [index ]-> sha1 ;
102+ return commit_graft_table [index ]-> oid . hash ;
103103}
104104
105105static int commit_graft_pos (const unsigned char * sha1 )
@@ -110,7 +110,7 @@ static int commit_graft_pos(const unsigned char *sha1)
110110
111111int register_commit_graft (struct commit_graft * graft , int ignore_dups )
112112{
113- int pos = commit_graft_pos (graft -> sha1 );
113+ int pos = commit_graft_pos (graft -> oid . hash );
114114
115115 if (0 <= pos ) {
116116 if (ignore_dups )
@@ -138,22 +138,23 @@ struct commit_graft *read_graft_line(char *buf, int len)
138138 /* The format is just "Commit Parent1 Parent2 ...\n" */
139139 int i ;
140140 struct commit_graft * graft = NULL ;
141+ const int entry_size = GIT_SHA1_HEXSZ + 1 ;
141142
142143 while (len && isspace (buf [len - 1 ]))
143144 buf [-- len ] = '\0' ;
144145 if (buf [0 ] == '#' || buf [0 ] == '\0' )
145146 return NULL ;
146- if ((len + 1 ) % 41 )
147+ if ((len + 1 ) % entry_size )
147148 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 );
150151 graft -> nr_parent = i ;
151- if (get_sha1_hex (buf , graft -> sha1 ))
152+ if (get_oid_hex (buf , & graft -> oid ))
152153 goto bad_graft_data ;
153- for (i = 40 ; i < len ; i += 41 ) {
154+ for (i = GIT_SHA1_HEXSZ ; i < len ; i += entry_size ) {
154155 if (buf [i ] != ' ' )
155156 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 ))
157158 goto bad_graft_data ;
158159 }
159160 return graft ;
@@ -302,47 +303,50 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
302303{
303304 const char * tail = buffer ;
304305 const char * bufptr = buffer ;
305- unsigned char parent [ 20 ] ;
306+ struct object_id parent ;
306307 struct commit_list * * pptr ;
307308 struct commit_graft * graft ;
309+ const int tree_entry_len = GIT_SHA1_HEXSZ + 5 ;
310+ const int parent_entry_len = GIT_SHA1_HEXSZ + 7 ;
308311
309312 if (item -> object .parsed )
310313 return 0 ;
311314 item -> object .parsed = 1 ;
312315 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' )
314318 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 )
316320 return error ("bad tree pointer in commit %s" ,
317321 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" */
320324 pptr = & item -> parents ;
321325
322326 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 )) {
324328 struct commit * new_parent ;
325329
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' )
329333 return error ("bad parents in commit %s" , sha1_to_hex (item -> object .sha1 ));
330- bufptr += 48 ;
334+ bufptr += parent_entry_len + 1 ;
331335 /*
332336 * The clone is shallow if nr_parent < 0, and we must
333337 * not traverse its real parents even when we unhide them.
334338 */
335339 if (graft && (graft -> nr_parent < 0 || grafts_replace_parents ))
336340 continue ;
337- new_parent = lookup_commit (parent );
341+ new_parent = lookup_commit (parent . hash );
338342 if (new_parent )
339343 pptr = & commit_list_insert (new_parent , pptr )-> next ;
340344 }
341345 if (graft ) {
342346 int i ;
343347 struct commit * new_parent ;
344348 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 );
346350 if (!new_parent )
347351 continue ;
348352 pptr = & commit_list_insert (new_parent , pptr )-> next ;
@@ -1580,10 +1584,10 @@ struct commit *get_merge_parent(const char *name)
15801584{
15811585 struct object * obj ;
15821586 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 ))
15851589 return NULL ;
1586- obj = parse_object (sha1 );
1590+ obj = parse_object (oid . hash );
15871591 commit = (struct commit * )peel_to_type (name , 0 , obj , OBJ_COMMIT );
15881592 if (commit && !commit -> util ) {
15891593 struct merge_remote_desc * desc ;
0 commit comments