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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 1, 2018 at 02:18 UTC 7f89428d3794ce9063172114b98f1ef1e6c8da1a
1 file changed +22 -20
fast-import.c
+22 -20
@@ -1092,15 +1092,15 @@ static int store_object(
1092 unsigned char hdr[96];
1093 struct object_id oid;
1094 unsigned long hdrlen, deltalen;
1095 - git_SHA_CTX c;
1095 + git_hash_ctx c;
1096 git_zstream s;
1097
1098 hdrlen = xsnprintf((char *)hdr, sizeof(hdr), "%s %lu",
1099 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);
1104 if (oidout)
1105 oidcpy(oidout, &oid);
1106
@@ -1118,11 +1118,13 @@ static int store_object(
1118 return 1;
1119 }
1120
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 +
1124 delta_count_attempts_by_type[type]++;
1125 delta = diff_delta(last->data.buf, last->data.len,
1126 dat->buf, dat->len,
1125 - &deltalen, dat->len - 20);
1127 + &deltalen, dat->len - the_hash_algo->rawsz);
1128 } else
1129 delta = NULL;
1130
@@ -1231,7 +1233,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1233 struct object_id oid;
1234 unsigned long hdrlen;
1235 off_t offset;
1234 - git_SHA_CTX c;
1236 + git_hash_ctx c;
1237 git_zstream s;
1238 struct sha1file_checkpoint checkpoint;
1239 int status = Z_OK;
@@ -1246,8 +1248,8 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1248
1249 hdrlen = xsnprintf((char *)out_buf, out_sz, "blob %" PRIuMAX, len) + 1;
1250
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);
1253
1254 crc32_begin(pack_file);
1255
@@ -1265,7 +1267,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1267 if (!n && feof(stdin))
1268 die("EOF in data (%" PRIuMAX " bytes remaining)", len);
1269
1268 - git_SHA1_Update(&c, in_buf, n);
1270 + the_hash_algo->update_fn(&c, in_buf, n);
1271 s.next_in = in_buf;
1272 s.avail_in = n;
1273 len -= n;
@@ -1291,7 +1293,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1293 }
1294 }
1295 git_deflate_end(&s);
1294 - git_SHA1_Final(oid.hash, &c);
1296 + the_hash_algo->final_fn(oid.hash, &c);
1297
1298 if (oidout)
1299 oidcpy(oidout, &oid);
@@ -1350,11 +1352,11 @@ static void *gfi_unpack_entry(
1352 {
1353 enum object_type type;
1354 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)) {
1356 /* The object is stored in the packfile we are writing to
1357 * and we have modified it since the last time we scanned
1358 * 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
1360 * data is stale and is not valid. Closing all windows
1361 * and updating the packfile length ensures we can read
1362 * the newly written data.
@@ -1362,13 +1364,13 @@ static void *gfi_unpack_entry(
1364 close_pack_windows(p);
1365 sha1flush(pack_file);
1366
1365 - /* We have to offer 20 bytes additional on the end of
1367 + /* We have to offer rawsz bytes additional on the end of
1368 * the packfile as the core unpacker code assumes the
1369 * 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
1371 * we don't actually create the footer here.
1372 */
1371 - p->pack_size = pack_size + 20;
1373 + p->pack_size = pack_size + the_hash_algo->rawsz;
1374 }
1375 return unpack_entry(p, oe->idx.offset, &type, sizep);
1376 }
@@ -2204,7 +2206,7 @@ static void construct_path_with_fanout(const char *hex_sha1,
2206 unsigned char fanout, char *path)
2207 {
2208 unsigned int i = 0, j = 0;
2207 - if (fanout >= 20)
2209 + if (fanout >= the_hash_algo->rawsz)
2210 die("Too large fanout (%u)", fanout);
2211 while (fanout) {
2212 path[i++] = hex_sha1[j++];
@@ -2212,8 +2214,8 @@ static void construct_path_with_fanout(const char *hex_sha1,
2214 path[i++] = '/';
2215 fanout--;
2216 }
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';
2219 }
2220
2221 static uintmax_t do_change_note_fanout(