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

brian m. carlson committed Feb 19, 2019 at 00:05 UTC bbf05cf70e5d0ba113ea4ed4c7c77cb890707911
4 files changed +14 -13
archive-tar.c
+4 -3
@@ -326,14 +326,15 @@ static int write_tar_entry(struct archiver_args *args,
326
327 static void write_global_extended_header(struct archiver_args *args)
328 {
329 - const unsigned char *sha1 = args->commit_sha1;
329 + const struct object_id *oid = args->commit_oid;
330 struct strbuf ext_header = STRBUF_INIT;
331 struct ustar_header header;
332 unsigned int mode;
333
334 - if (sha1)
334 + if (oid)
335 strbuf_append_ext_header(&ext_header, "comment",
336 - sha1_to_hex(sha1), 40);
336 + oid_to_hex(oid),
337 + the_hash_algo->hexsz);
338 if (args->time > USTAR_MAX_MTIME) {
339 strbuf_append_ext_header_uint(&ext_header, "mtime",
340 args->time);
archive-zip.c
+5 -5
@@ -577,7 +577,7 @@ static void write_zip64_trailer(void)
577 write_or_die(1, &locator64, ZIP64_DIR_TRAILER_LOCATOR_SIZE);
578 }
579
580 -static void write_zip_trailer(const unsigned char *sha1)
580 +static void write_zip_trailer(const struct object_id *oid)
581 {
582 struct zip_dir_trailer trailer;
583 int clamped = 0;
@@ -590,14 +590,14 @@ static void write_zip_trailer(const unsigned char *sha1)
590 copy_le16_clamp(trailer.entries, zip_dir_entries, &clamped);
591 copy_le32(trailer.size, zip_dir.len);
592 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);
594
595 write_or_die(1, zip_dir.buf, zip_dir.len);
596 if (clamped)
597 write_zip64_trailer();
598 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);
601 }
602
603 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,
635
636 err = write_archive_entries(args, write_zip_entry);
637 if (!err)
638 - write_zip_trailer(args->commit_sha1);
638 + write_zip_trailer(args->commit_oid);
639
640 strbuf_release(&zip_dir);
641
archive.c
+4 -4
@@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv,
380 int remote)
381 {
382 const char *name = argv[0];
383 - const unsigned char *commit_sha1;
383 + const struct object_id *commit_oid;
384 time_t archive_time;
385 struct tree *tree;
386 const struct commit *commit;
@@ -402,10 +402,10 @@ static void parse_treeish_arg(const char **argv,
402
403 commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
404 if (commit) {
405 - commit_sha1 = commit->object.oid.hash;
405 + commit_oid = &commit->object.oid;
406 archive_time = commit->date;
407 } else {
408 - commit_sha1 = NULL;
408 + commit_oid = NULL;
409 archive_time = time(NULL);
410 }
411
@@ -426,7 +426,7 @@ static void parse_treeish_arg(const char **argv,
426 tree = parse_tree_indirect(&tree_oid);
427 }
428 ar_args->tree = tree;
429 - ar_args->commit_sha1 = commit_sha1;
429 + ar_args->commit_oid = commit_oid;
430 ar_args->commit = commit;
431 ar_args->time = archive_time;
432 }
archive.h
+1 -1
@@ -11,7 +11,7 @@ struct archiver_args {
11 const char *base;
12 size_t baselen;
13 struct tree *tree;
14 - const unsigned char *commit_sha1;
14 + const struct object_id *commit_oid;
15 const struct commit *commit;
16 timestamp_t time;
17 struct pathspec pathspec;