Skip to content

Commit bbf05cf

Browse files
bk2204gitster
authored andcommitted
archive: convert struct archiver_args to object_id
Change the commit_sha1 member to be called "commit_oid" and change it to be a pointer to struct object_id. Additionally, update some uses of GIT_SHA1_HEXSZ and hard-coded values to use the_hash_algo instead. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87003d2 commit bbf05cf

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
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;

0 commit comments

Comments
 (0)