Skip to content

Commit 7f89428

Browse files
bk2204gitster
authored andcommitted
fast-import: switch various uses of SHA-1 to the_hash_algo
Switch various uses of explicit calls to SHA-1 to use the_hash_algo. Convert various uses of 20 and the GIT_SHA1 constants as well. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 18e2588 commit 7f89428

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

fast-import.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,15 +1092,15 @@ static int store_object(
10921092
unsigned char hdr[96];
10931093
struct object_id oid;
10941094
unsigned long hdrlen, deltalen;
1095-
git_SHA_CTX c;
1095+
git_hash_ctx c;
10961096
git_zstream s;
10971097

10981098
hdrlen = xsnprintf((char *)hdr, sizeof(hdr), "%s %lu",
10991099
typename(type), (unsigned long)dat->len) + 1;
1100-
git_SHA1_Init(&c);
1101-
git_SHA1_Update(&c, hdr, hdrlen);
1102-
git_SHA1_Update(&c, dat->buf, dat->len);
1103-
git_SHA1_Final(oid.hash, &c);
1100+
the_hash_algo->init_fn(&c);
1101+
the_hash_algo->update_fn(&c, hdr, hdrlen);
1102+
the_hash_algo->update_fn(&c, dat->buf, dat->len);
1103+
the_hash_algo->final_fn(oid.hash, &c);
11041104
if (oidout)
11051105
oidcpy(oidout, &oid);
11061106

@@ -1118,11 +1118,13 @@ static int store_object(
11181118
return 1;
11191119
}
11201120

1121-
if (last && last->data.buf && last->depth < max_depth && dat->len > 20) {
1121+
if (last && last->data.buf && last->depth < max_depth
1122+
&& dat->len > the_hash_algo->rawsz) {
1123+
11221124
delta_count_attempts_by_type[type]++;
11231125
delta = diff_delta(last->data.buf, last->data.len,
11241126
dat->buf, dat->len,
1125-
&deltalen, dat->len - 20);
1127+
&deltalen, dat->len - the_hash_algo->rawsz);
11261128
} else
11271129
delta = NULL;
11281130

@@ -1231,7 +1233,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
12311233
struct object_id oid;
12321234
unsigned long hdrlen;
12331235
off_t offset;
1234-
git_SHA_CTX c;
1236+
git_hash_ctx c;
12351237
git_zstream s;
12361238
struct sha1file_checkpoint checkpoint;
12371239
int status = Z_OK;
@@ -1246,8 +1248,8 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
12461248

12471249
hdrlen = xsnprintf((char *)out_buf, out_sz, "blob %" PRIuMAX, len) + 1;
12481250

1249-
git_SHA1_Init(&c);
1250-
git_SHA1_Update(&c, out_buf, hdrlen);
1251+
the_hash_algo->init_fn(&c);
1252+
the_hash_algo->update_fn(&c, out_buf, hdrlen);
12511253

12521254
crc32_begin(pack_file);
12531255

@@ -1265,7 +1267,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
12651267
if (!n && feof(stdin))
12661268
die("EOF in data (%" PRIuMAX " bytes remaining)", len);
12671269

1268-
git_SHA1_Update(&c, in_buf, n);
1270+
the_hash_algo->update_fn(&c, in_buf, n);
12691271
s.next_in = in_buf;
12701272
s.avail_in = n;
12711273
len -= n;
@@ -1291,7 +1293,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
12911293
}
12921294
}
12931295
git_deflate_end(&s);
1294-
git_SHA1_Final(oid.hash, &c);
1296+
the_hash_algo->final_fn(oid.hash, &c);
12951297

12961298
if (oidout)
12971299
oidcpy(oidout, &oid);
@@ -1350,25 +1352,25 @@ static void *gfi_unpack_entry(
13501352
{
13511353
enum object_type type;
13521354
struct packed_git *p = all_packs[oe->pack_id];
1353-
if (p == pack_data && p->pack_size < (pack_size + 20)) {
1355+
if (p == pack_data && p->pack_size < (pack_size + the_hash_algo->rawsz)) {
13541356
/* The object is stored in the packfile we are writing to
13551357
* and we have modified it since the last time we scanned
13561358
* back to read a previously written object. If an old
1357-
* window covered [p->pack_size, p->pack_size + 20) its
1359+
* window covered [p->pack_size, p->pack_size + rawsz) its
13581360
* data is stale and is not valid. Closing all windows
13591361
* and updating the packfile length ensures we can read
13601362
* the newly written data.
13611363
*/
13621364
close_pack_windows(p);
13631365
sha1flush(pack_file);
13641366

1365-
/* We have to offer 20 bytes additional on the end of
1367+
/* We have to offer rawsz bytes additional on the end of
13661368
* the packfile as the core unpacker code assumes the
13671369
* footer is present at the file end and must promise
1368-
* at least 20 bytes within any window it maps. But
1370+
* at least rawsz bytes within any window it maps. But
13691371
* we don't actually create the footer here.
13701372
*/
1371-
p->pack_size = pack_size + 20;
1373+
p->pack_size = pack_size + the_hash_algo->rawsz;
13721374
}
13731375
return unpack_entry(p, oe->idx.offset, &type, sizep);
13741376
}
@@ -2204,16 +2206,16 @@ static void construct_path_with_fanout(const char *hex_sha1,
22042206
unsigned char fanout, char *path)
22052207
{
22062208
unsigned int i = 0, j = 0;
2207-
if (fanout >= 20)
2209+
if (fanout >= the_hash_algo->rawsz)
22082210
die("Too large fanout (%u)", fanout);
22092211
while (fanout) {
22102212
path[i++] = hex_sha1[j++];
22112213
path[i++] = hex_sha1[j++];
22122214
path[i++] = '/';
22132215
fanout--;
22142216
}
2215-
memcpy(path + i, hex_sha1 + j, GIT_SHA1_HEXSZ - j);
2216-
path[i + GIT_SHA1_HEXSZ - j] = '\0';
2217+
memcpy(path + i, hex_sha1 + j, the_hash_algo->hexsz - j);
2218+
path[i + the_hash_algo->hexsz - j] = '\0';
22172219
}
22182220

22192221
static uintmax_t do_change_note_fanout(

0 commit comments

Comments
 (0)