@@ -29,7 +29,7 @@ static int rerere_dir_alloc;
29
29
#define RR_HAS_POSTIMAGE 1
30
30
#define RR_HAS_PREIMAGE 2
31
31
static struct rerere_dir {
32
- unsigned char sha1 [ 20 ];
32
+ unsigned char hash [ GIT_MAX_HEXSZ ];
33
33
int status_alloc , status_nr ;
34
34
unsigned char * status ;
35
35
} * * rerere_dir ;
@@ -52,7 +52,7 @@ static void free_rerere_id(struct string_list_item *item)
52
52
53
53
static const char * rerere_id_hex (const struct rerere_id * id )
54
54
{
55
- return sha1_to_hex (id -> collection -> sha1 );
55
+ return sha1_to_hex (id -> collection -> hash );
56
56
}
57
57
58
58
static void fit_variant (struct rerere_dir * rr_dir , int variant )
@@ -115,7 +115,7 @@ static int is_rr_file(const char *name, const char *filename, int *variant)
115
115
static void scan_rerere_dir (struct rerere_dir * rr_dir )
116
116
{
117
117
struct dirent * de ;
118
- DIR * dir = opendir (git_path ("rr-cache/%s" , sha1_to_hex (rr_dir -> sha1 )));
118
+ DIR * dir = opendir (git_path ("rr-cache/%s" , sha1_to_hex (rr_dir -> hash )));
119
119
120
120
if (!dir )
121
121
return ;
@@ -133,24 +133,24 @@ static void scan_rerere_dir(struct rerere_dir *rr_dir)
133
133
closedir (dir );
134
134
}
135
135
136
- static const unsigned char * rerere_dir_sha1 (size_t i , void * table )
136
+ static const unsigned char * rerere_dir_hash (size_t i , void * table )
137
137
{
138
138
struct rerere_dir * * rr_dir = table ;
139
- return rr_dir [i ]-> sha1 ;
139
+ return rr_dir [i ]-> hash ;
140
140
}
141
141
142
142
static struct rerere_dir * find_rerere_dir (const char * hex )
143
143
{
144
- unsigned char sha1 [ 20 ];
144
+ unsigned char hash [ GIT_MAX_RAWSZ ];
145
145
struct rerere_dir * rr_dir ;
146
146
int pos ;
147
147
148
- if (get_sha1_hex (hex , sha1 ))
148
+ if (get_sha1_hex (hex , hash ))
149
149
return NULL ; /* BUG */
150
- pos = sha1_pos (sha1 , rerere_dir , rerere_dir_nr , rerere_dir_sha1 );
150
+ pos = sha1_pos (hash , rerere_dir , rerere_dir_nr , rerere_dir_hash );
151
151
if (pos < 0 ) {
152
152
rr_dir = xmalloc (sizeof (* rr_dir ));
153
- hashcpy (rr_dir -> sha1 , sha1 );
153
+ hashcpy (rr_dir -> hash , hash );
154
154
rr_dir -> status = NULL ;
155
155
rr_dir -> status_nr = 0 ;
156
156
rr_dir -> status_alloc = 0 ;
@@ -207,26 +207,27 @@ static void read_rr(struct string_list *rr)
207
207
return ;
208
208
while (!strbuf_getwholeline (& buf , in , '\0' )) {
209
209
char * path ;
210
- unsigned char sha1 [ 20 ];
210
+ unsigned char hash [ GIT_MAX_RAWSZ ];
211
211
struct rerere_id * id ;
212
212
int variant ;
213
+ const unsigned hexsz = the_hash_algo -> hexsz ;
213
214
214
215
/* There has to be the hash, tab, path and then NUL */
215
- if (buf .len < 42 || get_sha1_hex (buf .buf , sha1 ))
216
+ if (buf .len < hexsz + 2 || get_sha1_hex (buf .buf , hash ))
216
217
die (_ ("corrupt MERGE_RR" ));
217
218
218
- if (buf .buf [40 ] != '.' ) {
219
+ if (buf .buf [hexsz ] != '.' ) {
219
220
variant = 0 ;
220
- path = buf .buf + 40 ;
221
+ path = buf .buf + hexsz ;
221
222
} else {
222
223
errno = 0 ;
223
- variant = strtol (buf .buf + 41 , & path , 10 );
224
+ variant = strtol (buf .buf + hexsz + 1 , & path , 10 );
224
225
if (errno )
225
226
die (_ ("corrupt MERGE_RR" ));
226
227
}
227
228
if (* (path ++ ) != '\t' )
228
229
die (_ ("corrupt MERGE_RR" ));
229
- buf .buf [40 ] = '\0' ;
230
+ buf .buf [hexsz ] = '\0' ;
230
231
id = new_rerere_id_hex (buf .buf );
231
232
id -> variant = variant ;
232
233
string_list_insert (rr , path )-> util = id ;
@@ -360,7 +361,7 @@ static void rerere_strbuf_putconflict(struct strbuf *buf, int ch, size_t size)
360
361
}
361
362
362
363
static int handle_conflict (struct strbuf * out , struct rerere_io * io ,
363
- int marker_size , git_SHA_CTX * ctx )
364
+ int marker_size , git_hash_ctx * ctx )
364
365
{
365
366
enum {
366
367
RR_SIDE_1 = 0 , RR_SIDE_2 , RR_ORIGINAL
@@ -398,10 +399,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,
398
399
strbuf_addbuf (out , & two );
399
400
rerere_strbuf_putconflict (out , '>' , marker_size );
400
401
if (ctx ) {
401
- git_SHA1_Update (ctx , one .buf ? one .buf : "" ,
402
- one .len + 1 );
403
- git_SHA1_Update (ctx , two .buf ? two .buf : "" ,
404
- two .len + 1 );
402
+ the_hash_algo -> update_fn (ctx , one .buf ?
403
+ one .buf : "" ,
404
+ one .len + 1 );
405
+ the_hash_algo -> update_fn (ctx , two .buf ?
406
+ two .buf : "" ,
407
+ two .len + 1 );
405
408
}
406
409
break ;
407
410
} else if (hunk == RR_SIDE_1 )
@@ -430,18 +433,18 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,
430
433
* Return 1 if conflict hunks are found, 0 if there are no conflict
431
434
* hunks and -1 if an error occured.
432
435
*/
433
- static int handle_path (unsigned char * sha1 , struct rerere_io * io , int marker_size )
436
+ static int handle_path (unsigned char * hash , struct rerere_io * io , int marker_size )
434
437
{
435
- git_SHA_CTX ctx ;
438
+ git_hash_ctx ctx ;
436
439
struct strbuf buf = STRBUF_INIT , out = STRBUF_INIT ;
437
440
int has_conflicts = 0 ;
438
- if (sha1 )
439
- git_SHA1_Init (& ctx );
441
+ if (hash )
442
+ the_hash_algo -> init_fn (& ctx );
440
443
441
444
while (!io -> getline (& buf , io )) {
442
445
if (is_cmarker (buf .buf , '<' , marker_size )) {
443
446
has_conflicts = handle_conflict (& out , io , marker_size ,
444
- sha1 ? & ctx : NULL );
447
+ hash ? & ctx : NULL );
445
448
if (has_conflicts < 0 )
446
449
break ;
447
450
rerere_io_putmem (out .buf , out .len , io );
@@ -452,8 +455,8 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
452
455
strbuf_release (& buf );
453
456
strbuf_release (& out );
454
457
455
- if (sha1 )
456
- git_SHA1_Final ( sha1 , & ctx );
458
+ if (hash )
459
+ the_hash_algo -> final_fn ( hash , & ctx );
457
460
458
461
return has_conflicts ;
459
462
}
@@ -462,7 +465,7 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
462
465
* Scan the path for conflicts, do the "handle_path()" thing above, and
463
466
* return the number of conflict hunks found.
464
467
*/
465
- static int handle_file (const char * path , unsigned char * sha1 , const char * output )
468
+ static int handle_file (const char * path , unsigned char * hash , const char * output )
466
469
{
467
470
int has_conflicts = 0 ;
468
471
struct rerere_io_file io ;
@@ -484,7 +487,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
484
487
}
485
488
}
486
489
487
- has_conflicts = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
490
+ has_conflicts = handle_path (hash , (struct rerere_io * )& io , marker_size );
488
491
489
492
fclose (io .input );
490
493
if (io .io .wrerror )
@@ -814,7 +817,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
814
817
*/
815
818
for (i = 0 ; i < conflict .nr ; i ++ ) {
816
819
struct rerere_id * id ;
817
- unsigned char sha1 [ 20 ];
820
+ unsigned char hash [ GIT_MAX_RAWSZ ];
818
821
const char * path = conflict .items [i ].string ;
819
822
int ret ;
820
823
@@ -823,15 +826,15 @@ static int do_plain_rerere(struct string_list *rr, int fd)
823
826
* conflict ID. No need to write anything out
824
827
* yet.
825
828
*/
826
- ret = handle_file (path , sha1 , NULL );
829
+ ret = handle_file (path , hash , NULL );
827
830
if (ret != 0 && string_list_has_string (rr , path )) {
828
831
remove_variant (string_list_lookup (rr , path )-> util );
829
832
string_list_remove (rr , path , 1 );
830
833
}
831
834
if (ret < 1 )
832
835
continue ;
833
836
834
- id = new_rerere_id (sha1 );
837
+ id = new_rerere_id (hash );
835
838
string_list_insert (rr , path )-> util = id ;
836
839
837
840
/* Ensure that the directory exists. */
@@ -942,7 +945,7 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
942
945
return 0 ;
943
946
}
944
947
945
- static int handle_cache (const char * path , unsigned char * sha1 , const char * output )
948
+ static int handle_cache (const char * path , unsigned char * hash , const char * output )
946
949
{
947
950
mmfile_t mmfile [3 ] = {{NULL }};
948
951
mmbuffer_t result = {NULL , 0 };
@@ -1001,7 +1004,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
1001
1004
* Grab the conflict ID and optionally write the original
1002
1005
* contents with conflict markers out.
1003
1006
*/
1004
- has_conflicts = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
1007
+ has_conflicts = handle_path (hash , (struct rerere_io * )& io , marker_size );
1005
1008
strbuf_release (& io .input );
1006
1009
if (io .io .output )
1007
1010
fclose (io .io .output );
@@ -1012,20 +1015,20 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
1012
1015
{
1013
1016
const char * filename ;
1014
1017
struct rerere_id * id ;
1015
- unsigned char sha1 [ 20 ];
1018
+ unsigned char hash [ GIT_MAX_RAWSZ ];
1016
1019
int ret ;
1017
1020
struct string_list_item * item ;
1018
1021
1019
1022
/*
1020
1023
* Recreate the original conflict from the stages in the
1021
1024
* index and compute the conflict ID
1022
1025
*/
1023
- ret = handle_cache (path , sha1 , NULL );
1026
+ ret = handle_cache (path , hash , NULL );
1024
1027
if (ret < 1 )
1025
1028
return error (_ ("could not parse conflict hunks in '%s'" ), path );
1026
1029
1027
1030
/* Nuke the recorded resolution for the conflict */
1028
- id = new_rerere_id (sha1 );
1031
+ id = new_rerere_id (hash );
1029
1032
1030
1033
for (id -> variant = 0 ;
1031
1034
id -> variant < id -> collection -> status_nr ;
@@ -1037,7 +1040,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
1037
1040
if (!has_rerere_resolution (id ))
1038
1041
continue ;
1039
1042
1040
- handle_cache (path , sha1 , rerere_path (id , "thisimage" ));
1043
+ handle_cache (path , hash , rerere_path (id , "thisimage" ));
1041
1044
if (read_mmfile (& cur , rerere_path (id , "thisimage" ))) {
1042
1045
free (cur .ptr );
1043
1046
error (_ ("failed to update conflicted state in '%s'" ), path );
@@ -1069,7 +1072,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
1069
1072
* conflict in the working tree, run us again to record
1070
1073
* the postimage.
1071
1074
*/
1072
- handle_cache (path , sha1 , rerere_path (id , "preimage" ));
1075
+ handle_cache (path , hash , rerere_path (id , "preimage" ));
1073
1076
fprintf_ln (stderr , _ ("Updated preimage for '%s'" ), path );
1074
1077
1075
1078
/*
0 commit comments