@@ -223,8 +223,8 @@ struct patch {
223
223
struct fragment * fragments ;
224
224
char * result ;
225
225
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 ];
228
228
struct patch * next ;
229
229
230
230
/* three-way fallback result */
@@ -1093,13 +1093,14 @@ static int gitdiff_index(struct apply_state *state,
1093
1093
*/
1094
1094
const char * ptr , * eol ;
1095
1095
int len ;
1096
+ const unsigned hexsz = the_hash_algo -> hexsz ;
1096
1097
1097
1098
ptr = strchr (line , '.' );
1098
- if (!ptr || ptr [1 ] != '.' || 40 < ptr - line )
1099
+ if (!ptr || ptr [1 ] != '.' || hexsz < ptr - line )
1099
1100
return 0 ;
1100
1101
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 ;
1103
1104
1104
1105
line = ptr + 2 ;
1105
1106
ptr = strchr (line , ' ' );
@@ -1109,10 +1110,10 @@ static int gitdiff_index(struct apply_state *state,
1109
1110
ptr = eol ;
1110
1111
len = ptr - line ;
1111
1112
1112
- if (40 < len )
1113
+ if (hexsz < len )
1113
1114
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 ;
1116
1117
if (* ptr == ' ' )
1117
1118
return gitdiff_oldmode (state , ptr + 1 , patch );
1118
1119
return 0 ;
@@ -2206,7 +2207,7 @@ static void reverse_patches(struct patch *p)
2206
2207
SWAP (p -> new_mode , p -> old_mode );
2207
2208
SWAP (p -> is_new , p -> is_delete );
2208
2209
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 );
2210
2211
2211
2212
for (; frag ; frag = frag -> next ) {
2212
2213
SWAP (frag -> newpos , frag -> oldpos );
@@ -3144,15 +3145,16 @@ static int apply_binary(struct apply_state *state,
3144
3145
{
3145
3146
const char * name = patch -> old_name ? patch -> old_name : patch -> new_name ;
3146
3147
struct object_id oid ;
3148
+ const unsigned hexsz = the_hash_algo -> hexsz ;
3147
3149
3148
3150
/*
3149
3151
* 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.
3151
3153
*/
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 ))
3156
3158
return error (_ ("cannot apply binary patch to '%s' "
3157
3159
"without full index line" ), name );
3158
3160
@@ -3162,7 +3164,7 @@ static int apply_binary(struct apply_state *state,
3162
3164
* applies to.
3163
3165
*/
3164
3166
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 ))
3166
3168
return error (_ ("the patch applies to '%s' (%s), "
3167
3169
"which does not match the "
3168
3170
"current contents." ),
@@ -3175,7 +3177,7 @@ static int apply_binary(struct apply_state *state,
3175
3177
"'%s' but it is not empty" ), name );
3176
3178
}
3177
3179
3178
- get_oid_hex (patch -> new_sha1_prefix , & oid );
3180
+ get_oid_hex (patch -> new_oid_prefix , & oid );
3179
3181
if (is_null_oid (& oid )) {
3180
3182
clear_image (img );
3181
3183
return 0 ; /* deletion patch */
@@ -3191,7 +3193,7 @@ static int apply_binary(struct apply_state *state,
3191
3193
if (!result )
3192
3194
return error (_ ("the necessary postimage %s for "
3193
3195
"'%s' cannot be read" ),
3194
- patch -> new_sha1_prefix , name );
3196
+ patch -> new_oid_prefix , name );
3195
3197
clear_image (img );
3196
3198
img -> buf = result ;
3197
3199
img -> len = size ;
@@ -3207,9 +3209,9 @@ static int apply_binary(struct apply_state *state,
3207
3209
3208
3210
/* verify that the result matches */
3209
3211
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 ))
3211
3213
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 ));
3213
3215
}
3214
3216
3215
3217
return 0 ;
@@ -3568,7 +3570,7 @@ static int try_threeway(struct apply_state *state,
3568
3570
/* Preimage the patch was prepared for */
3569
3571
if (patch -> is_new )
3570
3572
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 ) ||
3572
3574
read_blob_object (& buf , & pre_oid , patch -> old_mode ))
3573
3575
return error (_ ("repository lacks the necessary blob to fall back on 3-way merge." ));
3574
3576
@@ -4060,13 +4062,13 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)
4060
4062
starts_with (++ preimage , heading ) &&
4061
4063
/* does it record full SHA-1? */
4062
4064
!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' &&
4064
4066
/* 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 ))
4066
4068
return 0 ; /* it all looks fine */
4067
4069
4068
4070
/* 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 );
4070
4072
}
4071
4073
4072
4074
/* 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)
4095
4097
else
4096
4098
return error (_ ("sha1 information is lacking or "
4097
4099
"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 )) {
4099
4101
; /* ok */
4100
4102
} else if (!patch -> lines_added && !patch -> lines_deleted ) {
4101
4103
/* mode-only change: update the current */
0 commit comments