@@ -223,8 +223,8 @@ struct patch {
223223 struct fragment * fragments ;
224224 char * result ;
225225 size_t resultsize ;
226- char old_sha1_prefix [ 41 ];
227- char new_sha1_prefix [ 41 ];
226+ char old_oid_prefix [ GIT_MAX_HEXSZ + 1 ];
227+ char new_oid_prefix [ GIT_MAX_HEXSZ + 1 ];
228228 struct patch * next ;
229229
230230 /* three-way fallback result */
@@ -1093,13 +1093,14 @@ static int gitdiff_index(struct apply_state *state,
10931093 */
10941094 const char * ptr , * eol ;
10951095 int len ;
1096+ const unsigned hexsz = the_hash_algo -> hexsz ;
10961097
10971098 ptr = strchr (line , '.' );
1098- if (!ptr || ptr [1 ] != '.' || 40 < ptr - line )
1099+ if (!ptr || ptr [1 ] != '.' || hexsz < ptr - line )
10991100 return 0 ;
11001101 len = ptr - line ;
1101- memcpy (patch -> old_sha1_prefix , line , len );
1102- patch -> old_sha1_prefix [len ] = 0 ;
1102+ memcpy (patch -> old_oid_prefix , line , len );
1103+ patch -> old_oid_prefix [len ] = 0 ;
11031104
11041105 line = ptr + 2 ;
11051106 ptr = strchr (line , ' ' );
@@ -1109,10 +1110,10 @@ static int gitdiff_index(struct apply_state *state,
11091110 ptr = eol ;
11101111 len = ptr - line ;
11111112
1112- if (40 < len )
1113+ if (hexsz < len )
11131114 return 0 ;
1114- memcpy (patch -> new_sha1_prefix , line , len );
1115- patch -> new_sha1_prefix [len ] = 0 ;
1115+ memcpy (patch -> new_oid_prefix , line , len );
1116+ patch -> new_oid_prefix [len ] = 0 ;
11161117 if (* ptr == ' ' )
11171118 return gitdiff_oldmode (state , ptr + 1 , patch );
11181119 return 0 ;
@@ -2206,7 +2207,7 @@ static void reverse_patches(struct patch *p)
22062207 SWAP (p -> new_mode , p -> old_mode );
22072208 SWAP (p -> is_new , p -> is_delete );
22082209 SWAP (p -> lines_added , p -> lines_deleted );
2209- SWAP (p -> old_sha1_prefix , p -> new_sha1_prefix );
2210+ SWAP (p -> old_oid_prefix , p -> new_oid_prefix );
22102211
22112212 for (; frag ; frag = frag -> next ) {
22122213 SWAP (frag -> newpos , frag -> oldpos );
@@ -3144,15 +3145,16 @@ static int apply_binary(struct apply_state *state,
31443145{
31453146 const char * name = patch -> old_name ? patch -> old_name : patch -> new_name ;
31463147 struct object_id oid ;
3148+ const unsigned hexsz = the_hash_algo -> hexsz ;
31473149
31483150 /*
31493151 * For safety, we require patch index line to contain
3150- * full 40-byte textual SHA1 for old and new, at least for now.
3152+ * full hex textual object ID for old and new, at least for now.
31513153 */
3152- if (strlen (patch -> old_sha1_prefix ) != 40 ||
3153- strlen (patch -> new_sha1_prefix ) != 40 ||
3154- get_oid_hex (patch -> old_sha1_prefix , & oid ) ||
3155- get_oid_hex (patch -> new_sha1_prefix , & oid ))
3154+ if (strlen (patch -> old_oid_prefix ) != hexsz ||
3155+ strlen (patch -> new_oid_prefix ) != hexsz ||
3156+ get_oid_hex (patch -> old_oid_prefix , & oid ) ||
3157+ get_oid_hex (patch -> new_oid_prefix , & oid ))
31563158 return error (_ ("cannot apply binary patch to '%s' "
31573159 "without full index line" ), name );
31583160
@@ -3162,7 +3164,7 @@ static int apply_binary(struct apply_state *state,
31623164 * applies to.
31633165 */
31643166 hash_object_file (img -> buf , img -> len , blob_type , & oid );
3165- if (strcmp (oid_to_hex (& oid ), patch -> old_sha1_prefix ))
3167+ if (strcmp (oid_to_hex (& oid ), patch -> old_oid_prefix ))
31663168 return error (_ ("the patch applies to '%s' (%s), "
31673169 "which does not match the "
31683170 "current contents." ),
@@ -3175,7 +3177,7 @@ static int apply_binary(struct apply_state *state,
31753177 "'%s' but it is not empty" ), name );
31763178 }
31773179
3178- get_oid_hex (patch -> new_sha1_prefix , & oid );
3180+ get_oid_hex (patch -> new_oid_prefix , & oid );
31793181 if (is_null_oid (& oid )) {
31803182 clear_image (img );
31813183 return 0 ; /* deletion patch */
@@ -3191,7 +3193,7 @@ static int apply_binary(struct apply_state *state,
31913193 if (!result )
31923194 return error (_ ("the necessary postimage %s for "
31933195 "'%s' cannot be read" ),
3194- patch -> new_sha1_prefix , name );
3196+ patch -> new_oid_prefix , name );
31953197 clear_image (img );
31963198 img -> buf = result ;
31973199 img -> len = size ;
@@ -3207,9 +3209,9 @@ static int apply_binary(struct apply_state *state,
32073209
32083210 /* verify that the result matches */
32093211 hash_object_file (img -> buf , img -> len , blob_type , & oid );
3210- if (strcmp (oid_to_hex (& oid ), patch -> new_sha1_prefix ))
3212+ if (strcmp (oid_to_hex (& oid ), patch -> new_oid_prefix ))
32113213 return error (_ ("binary patch to '%s' creates incorrect result (expecting %s, got %s)" ),
3212- name , patch -> new_sha1_prefix , oid_to_hex (& oid ));
3214+ name , patch -> new_oid_prefix , oid_to_hex (& oid ));
32133215 }
32143216
32153217 return 0 ;
@@ -3568,7 +3570,7 @@ static int try_threeway(struct apply_state *state,
35683570 /* Preimage the patch was prepared for */
35693571 if (patch -> is_new )
35703572 write_object_file ("" , 0 , blob_type , & pre_oid );
3571- else if (get_oid (patch -> old_sha1_prefix , & pre_oid ) ||
3573+ else if (get_oid (patch -> old_oid_prefix , & pre_oid ) ||
35723574 read_blob_object (& buf , & pre_oid , patch -> old_mode ))
35733575 return error (_ ("repository lacks the necessary blob to fall back on 3-way merge." ));
35743576
@@ -4060,13 +4062,13 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)
40604062 starts_with (++ preimage , heading ) &&
40614063 /* does it record full SHA-1? */
40624064 !get_oid_hex (preimage + sizeof (heading ) - 1 , oid ) &&
4063- preimage [sizeof (heading ) + GIT_SHA1_HEXSZ - 1 ] == '\n' &&
4065+ preimage [sizeof (heading ) + the_hash_algo -> hexsz - 1 ] == '\n' &&
40644066 /* does the abbreviated name on the index line agree with it? */
4065- starts_with (preimage + sizeof (heading ) - 1 , p -> old_sha1_prefix ))
4067+ starts_with (preimage + sizeof (heading ) - 1 , p -> old_oid_prefix ))
40664068 return 0 ; /* it all looks fine */
40674069
40684070 /* we may have full object name on the index line */
4069- return get_oid_hex (p -> old_sha1_prefix , oid );
4071+ return get_oid_hex (p -> old_oid_prefix , oid );
40704072}
40714073
40724074/* Build an index that contains just the files needed for a 3way merge */
@@ -4095,7 +4097,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
40954097 else
40964098 return error (_ ("sha1 information is lacking or "
40974099 "useless for submodule %s" ), name );
4098- } else if (!get_oid_blob (patch -> old_sha1_prefix , & oid )) {
4100+ } else if (!get_oid_blob (patch -> old_oid_prefix , & oid )) {
40994101 ; /* ok */
41004102 } else if (!patch -> lines_added && !patch -> lines_deleted ) {
41014103 /* mode-only change: update the current */
0 commit comments