Skip to content

Commit d4e568b

Browse files
committed
Merge branch 'bc/hash-transition-16'
Conversion from unsigned char[20] to struct object_id continues. * bc/hash-transition-16: (35 commits) gitweb: make hash size independent Git.pm: make hash size independent read-cache: read data in a hash-independent way dir: make untracked cache extension hash size independent builtin/difftool: use parse_oid_hex refspec: make hash size independent archive: convert struct archiver_args to object_id builtin/get-tar-commit-id: make hash size independent get-tar-commit-id: parse comment record hash: add a function to lookup hash algorithm by length remote-curl: make hash size independent http: replace sha1_to_hex http: compute hash of downloaded objects using the_hash_algo http: replace hard-coded constant with the_hash_algo http-walker: replace sha1_to_hex http-push: remove remaining uses of sha1_to_hex http-backend: allow 64-character hex names http-push: convert to use the_hash_algo builtin/pull: make hash-size independent builtin/am: make hash size independent ...
2 parents dae82ec + cfb0491 commit d4e568b

37 files changed

+362
-289
lines changed

archive-tar.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,15 @@ static int write_tar_entry(struct archiver_args *args,
326326

327327
static void write_global_extended_header(struct archiver_args *args)
328328
{
329-
const unsigned char *sha1 = args->commit_sha1;
329+
const struct object_id *oid = args->commit_oid;
330330
struct strbuf ext_header = STRBUF_INIT;
331331
struct ustar_header header;
332332
unsigned int mode;
333333

334-
if (sha1)
334+
if (oid)
335335
strbuf_append_ext_header(&ext_header, "comment",
336-
sha1_to_hex(sha1), 40);
336+
oid_to_hex(oid),
337+
the_hash_algo->hexsz);
337338
if (args->time > USTAR_MAX_MTIME) {
338339
strbuf_append_ext_header_uint(&ext_header, "mtime",
339340
args->time);

archive-zip.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static void write_zip64_trailer(void)
577577
write_or_die(1, &locator64, ZIP64_DIR_TRAILER_LOCATOR_SIZE);
578578
}
579579

580-
static void write_zip_trailer(const unsigned char *sha1)
580+
static void write_zip_trailer(const struct object_id *oid)
581581
{
582582
struct zip_dir_trailer trailer;
583583
int clamped = 0;
@@ -590,14 +590,14 @@ static void write_zip_trailer(const unsigned char *sha1)
590590
copy_le16_clamp(trailer.entries, zip_dir_entries, &clamped);
591591
copy_le32(trailer.size, zip_dir.len);
592592
copy_le32_clamp(trailer.offset, zip_offset, &clamped);
593-
copy_le16(trailer.comment_length, sha1 ? GIT_SHA1_HEXSZ : 0);
593+
copy_le16(trailer.comment_length, oid ? the_hash_algo->hexsz : 0);
594594

595595
write_or_die(1, zip_dir.buf, zip_dir.len);
596596
if (clamped)
597597
write_zip64_trailer();
598598
write_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE);
599-
if (sha1)
600-
write_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ);
599+
if (oid)
600+
write_or_die(1, oid_to_hex(oid), the_hash_algo->hexsz);
601601
}
602602

603603
static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
@@ -635,7 +635,7 @@ static int write_zip_archive(const struct archiver *ar,
635635

636636
err = write_archive_entries(args, write_zip_entry);
637637
if (!err)
638-
write_zip_trailer(args->commit_sha1);
638+
write_zip_trailer(args->commit_oid);
639639

640640
strbuf_release(&zip_dir);
641641

archive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv,
380380
int remote)
381381
{
382382
const char *name = argv[0];
383-
const unsigned char *commit_sha1;
383+
const struct object_id *commit_oid;
384384
time_t archive_time;
385385
struct tree *tree;
386386
const struct commit *commit;
@@ -402,10 +402,10 @@ static void parse_treeish_arg(const char **argv,
402402

403403
commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
404404
if (commit) {
405-
commit_sha1 = commit->object.oid.hash;
405+
commit_oid = &commit->object.oid;
406406
archive_time = commit->date;
407407
} else {
408-
commit_sha1 = NULL;
408+
commit_oid = NULL;
409409
archive_time = time(NULL);
410410
}
411411

@@ -426,7 +426,7 @@ static void parse_treeish_arg(const char **argv,
426426
tree = parse_tree_indirect(&tree_oid);
427427
}
428428
ar_args->tree = tree;
429-
ar_args->commit_sha1 = commit_sha1;
429+
ar_args->commit_oid = commit_oid;
430430
ar_args->commit = commit;
431431
ar_args->time = archive_time;
432432
}

archive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct archiver_args {
1111
const char *base;
1212
size_t baselen;
1313
struct tree *tree;
14-
const unsigned char *commit_sha1;
14+
const struct object_id *commit_oid;
1515
const struct commit *commit;
1616
timestamp_t time;
1717
struct pathspec pathspec;

builtin/am.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,23 +486,24 @@ static int copy_notes_for_rebase(const struct am_state *state)
486486

487487
while (!strbuf_getline_lf(&sb, fp)) {
488488
struct object_id from_obj, to_obj;
489+
const char *p;
489490

490-
if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) {
491+
if (sb.len != the_hash_algo->hexsz * 2 + 1) {
491492
ret = error(invalid_line, sb.buf);
492493
goto finish;
493494
}
494495

495-
if (get_oid_hex(sb.buf, &from_obj)) {
496+
if (parse_oid_hex(sb.buf, &from_obj, &p)) {
496497
ret = error(invalid_line, sb.buf);
497498
goto finish;
498499
}
499500

500-
if (sb.buf[GIT_SHA1_HEXSZ] != ' ') {
501+
if (*p != ' ') {
501502
ret = error(invalid_line, sb.buf);
502503
goto finish;
503504
}
504505

505-
if (get_oid_hex(sb.buf + GIT_SHA1_HEXSZ + 1, &to_obj)) {
506+
if (get_oid_hex(p + 1, &to_obj)) {
506507
ret = error(invalid_line, sb.buf);
507508
goto finish;
508509
}

builtin/difftool.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,12 @@ static int parse_index_info(char *p, int *mode1, int *mode2,
6565
*mode2 = (int)strtol(p + 1, &p, 8);
6666
if (*p != ' ')
6767
return error("expected ' ', got '%c'", *p);
68-
if (get_oid_hex(++p, oid1))
69-
return error("expected object ID, got '%s'", p + 1);
70-
p += GIT_SHA1_HEXSZ;
68+
if (parse_oid_hex(++p, oid1, (const char **)&p))
69+
return error("expected object ID, got '%s'", p);
7170
if (*p != ' ')
7271
return error("expected ' ', got '%c'", *p);
73-
if (get_oid_hex(++p, oid2))
74-
return error("expected object ID, got '%s'", p + 1);
75-
p += GIT_SHA1_HEXSZ;
72+
if (parse_oid_hex(++p, oid2, (const char **)&p))
73+
return error("expected object ID, got '%s'", p);
7674
if (*p != ' ')
7775
return error("expected ' ', got '%c'", *p);
7876
*status = *++p;

builtin/get-tar-commit-id.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
2121
char *content = buffer + RECORDSIZE;
2222
const char *comment;
2323
ssize_t n;
24+
long len;
25+
char *end;
2426

2527
if (argc != 1)
2628
usage(builtin_get_tar_commit_id_usage);
@@ -32,10 +34,18 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
3234
die_errno("git get-tar-commit-id: EOF before reading tar header");
3335
if (header->typeflag[0] != 'g')
3436
return 1;
35-
if (!skip_prefix(content, "52 comment=", &comment))
37+
38+
len = strtol(content, &end, 10);
39+
if (errno == ERANGE || end == content || len < 0)
40+
return 1;
41+
if (!skip_prefix(end, " comment=", &comment))
42+
return 1;
43+
len -= comment - content;
44+
if (len < 1 || !(len % 2) ||
45+
hash_algo_by_length((len - 1) / 2) == GIT_HASH_UNKNOWN)
3646
return 1;
3747

38-
if (write_in_full(1, comment, 41) < 0)
48+
if (write_in_full(1, comment, len) < 0)
3949
die_errno("git get-tar-commit-id: write error");
4050

4151
return 0;

builtin/name-rev.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,25 @@ static char const * const name_rev_usage[] = {
361361
static void name_rev_line(char *p, struct name_ref_data *data)
362362
{
363363
struct strbuf buf = STRBUF_INIT;
364-
int forty = 0;
364+
int counter = 0;
365365
char *p_start;
366+
const unsigned hexsz = the_hash_algo->hexsz;
367+
366368
for (p_start = p; *p; p++) {
367369
#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
368370
if (!ishex(*p))
369-
forty = 0;
370-
else if (++forty == GIT_SHA1_HEXSZ &&
371+
counter = 0;
372+
else if (++counter == hexsz &&
371373
!ishex(*(p+1))) {
372374
struct object_id oid;
373375
const char *name = NULL;
374376
char c = *(p+1);
375377
int p_len = p - p_start + 1;
376378

377-
forty = 0;
379+
counter = 0;
378380

379381
*(p+1) = 0;
380-
if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
382+
if (!get_oid(p - (hexsz - 1), &oid)) {
381383
struct object *o =
382384
lookup_object(the_repository,
383385
oid.hash);
@@ -390,7 +392,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
390392
continue;
391393

392394
if (data->name_only)
393-
printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name);
395+
printf("%.*s%s", p_len - hexsz, p_start, name);
394396
else
395397
printf("%.*s (%s)", p_len, p_start, name);
396398
p_start = p + 1;

builtin/pack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,7 @@ static int can_reuse_delta(const unsigned char *base_sha1,
14871487
struct object_entry **base_out)
14881488
{
14891489
struct object_entry *base;
1490+
struct object_id base_oid;
14901491

14911492
if (!base_sha1)
14921493
return 0;
@@ -1508,10 +1509,9 @@ static int can_reuse_delta(const unsigned char *base_sha1,
15081509
* even if it was buried too deep in history to make it into the
15091510
* packing list.
15101511
*/
1511-
if (thin && bitmap_has_sha1_in_uninteresting(bitmap_git, base_sha1)) {
1512+
oidread(&base_oid, base_sha1);
1513+
if (thin && bitmap_has_oid_in_uninteresting(bitmap_git, &base_oid)) {
15121514
if (use_delta_islands) {
1513-
struct object_id base_oid;
1514-
hashcpy(base_oid.hash, base_sha1);
15151515
if (!in_same_island(&delta->idx.oid, &base_oid))
15161516
return 0;
15171517
}

builtin/pack-redundant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
641641
pl = red = pack_list_difference(local_packs, min);
642642
while (pl) {
643643
printf("%s\n%s\n",
644-
sha1_pack_index_name(pl->pack->sha1),
644+
sha1_pack_index_name(pl->pack->hash),
645645
pl->pack->pack_name);
646646
pl = pl->next;
647647
}

0 commit comments

Comments
 (0)