git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 29/35] archive: convert struct archiver_args to object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Feb 19, 2019, 00:05 UTC
Message-ID
<20190219000526.476553-30-sandals@crustytoothpaste.net>
In-Reply-To
<20190219000526.476553-1-sandals@crustytoothpaste.net>

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>
---
 archive-tar.c |  7 ++++---
 archive-zip.c | 10 +++++-----
 archive.c     |  8 ++++----
 archive.h     |  2 +-
 4 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/archive-tar.c b/archive-tar.c
index 4aabd566fb..3e53aac1e6 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -326,14 +326,15 @@ static int write_tar_entry(struct archiver_args *args,
 
 static void write_global_extended_header(struct archiver_args *args)
 {
-	const unsigned char *sha1 = args->commit_sha1;
+	const struct object_id *oid = args->commit_oid;
 	struct strbuf ext_header = STRBUF_INIT;
 	struct ustar_header header;
 	unsigned int mode;
 
-	if (sha1)
+	if (oid)
 		strbuf_append_ext_header(&ext_header, "comment",
-					 sha1_to_hex(sha1), 40);
+					 oid_to_hex(oid),
+					 the_hash_algo->hexsz);
 	if (args->time > USTAR_MAX_MTIME) {
 		strbuf_append_ext_header_uint(&ext_header, "mtime",
 					      args->time);
diff --git a/archive-zip.c b/archive-zip.c
index 155ee4a779..4d66b5be6e 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -577,7 +577,7 @@ static void write_zip64_trailer(void)
 	write_or_die(1, &locator64, ZIP64_DIR_TRAILER_LOCATOR_SIZE);
 }
 
-static void write_zip_trailer(const unsigned char *sha1)
+static void write_zip_trailer(const struct object_id *oid)
 {
 	struct zip_dir_trailer trailer;
 	int clamped = 0;
@@ -590,14 +590,14 @@ static void write_zip_trailer(const unsigned char *sha1)
 	copy_le16_clamp(trailer.entries, zip_dir_entries, &clamped);
 	copy_le32(trailer.size, zip_dir.len);
 	copy_le32_clamp(trailer.offset, zip_offset, &clamped);
-	copy_le16(trailer.comment_length, sha1 ? GIT_SHA1_HEXSZ : 0);
+	copy_le16(trailer.comment_length, oid ? the_hash_algo->hexsz : 0);
 
 	write_or_die(1, zip_dir.buf, zip_dir.len);
 	if (clamped)
 		write_zip64_trailer();
 	write_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE);
-	if (sha1)
-		write_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ);
+	if (oid)
+		write_or_die(1, oid_to_hex(oid), the_hash_algo->hexsz);
 }
 
 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,
 
 	err = write_archive_entries(args, write_zip_entry);
 	if (!err)
-		write_zip_trailer(args->commit_sha1);
+		write_zip_trailer(args->commit_oid);
 
 	strbuf_release(&zip_dir);
 
diff --git a/archive.c b/archive.c
index 1f98324a93..f2c78a2712 100644
--- a/archive.c
+++ b/archive.c
@@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv,
 		int remote)
 {
 	const char *name = argv[0];
-	const unsigned char *commit_sha1;
+	const struct object_id *commit_oid;
 	time_t archive_time;
 	struct tree *tree;
 	const struct commit *commit;
@@ -402,10 +402,10 @@ static void parse_treeish_arg(const char **argv,
 
 	commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
 	if (commit) {
-		commit_sha1 = commit->object.oid.hash;
+		commit_oid = &commit->object.oid;
 		archive_time = commit->date;
 	} else {
-		commit_sha1 = NULL;
+		commit_oid = NULL;
 		archive_time = time(NULL);
 	}
 
@@ -426,7 +426,7 @@ static void parse_treeish_arg(const char **argv,
 		tree = parse_tree_indirect(&tree_oid);
 	}
 	ar_args->tree = tree;
-	ar_args->commit_sha1 = commit_sha1;
+	ar_args->commit_oid = commit_oid;
 	ar_args->commit = commit;
 	ar_args->time = archive_time;
 }
diff --git a/archive.h b/archive.h
index 21ac010699..dd022a6b46 100644
--- a/archive.h
+++ b/archive.h
@@ -11,7 +11,7 @@ struct archiver_args {
 	const char *base;
 	size_t baselen;
 	struct tree *tree;
-	const unsigned char *commit_sha1;
+	const struct object_id *commit_oid;
 	const struct commit *commit;
 	timestamp_t time;
 	struct pathspec pathspec;
Previous: brian m. carlsonNext: brian m. carlson
Message 26 of 36 in “Hash function transition part 16”
  1. 00/35 Hash function transition part 16brian m. carlson, Feb 19, 2019
  2. 01/35 t/lib-submodule-update: use appropriate length constantbrian m. carlson, Feb 19, 2019
  3. 02/35 khash: move oid hash table definitionbrian m. carlson, Feb 19, 2019
  4. 03/35 pack-bitmap: make bitmap header handling hash agnosticbrian m. carlson, Feb 19, 2019
  5. 06/35 pack-bitmap: switch hard-coded constants to the_hash_algobrian m. carlson, Feb 19, 2019
  6. 05/35 pack-bitmap: replace sha1_to_hexbrian m. carlson, Feb 19, 2019
  7. 07/35 pack-bitmap: switch hash tables to use struct object_idbrian m. carlson, Feb 19, 2019
  8. 09/35 notes-merge: switch to use the_hash_algobrian m. carlson, Feb 19, 2019
  9. 08/35 submodule: avoid hard-coded constantsbrian m. carlson, Feb 19, 2019
  10. 11/35 notes: replace sha1_to_hexbrian m. carlson, Feb 19, 2019
  11. 14/35 fast-import: make hash-size independentbrian m. carlson, Feb 19, 2019
  12. 17/35 builtin/pull: make hash-size independentbrian m. carlson, Feb 19, 2019
  13. 15/35 fast-import: replace sha1_to_hexbrian m. carlson, Feb 19, 2019
  14. 12/35 object-store: rename and expand packed_git's sha1 memberbrian m. carlson, Feb 19, 2019
  15. 19/35 http-backend: allow 64-character hex namesbrian m. carlson, Feb 19, 2019
  16. 18/35 http-push: convert to use the_hash_algobrian m. carlson, Feb 19, 2019
  17. 21/35 http-walker: replace sha1_to_hexbrian m. carlson, Feb 19, 2019
  18. 22/35 http: replace hard-coded constant with the_hash_algobrian m. carlson, Feb 19, 2019
  19. 20/35 http-push: remove remaining uses of sha1_to_hexbrian m. carlson, Feb 19, 2019
  20. 23/35 http: compute hash of downloaded objects using the_hash_algobrian m. carlson, Feb 19, 2019
  21. 24/35 http: replace sha1_to_hexbrian m. carlson, Feb 19, 2019
  22. 25/35 remote-curl: make hash size independentbrian m. carlson, Feb 19, 2019
  23. 26/35 hash: add a function to lookup hash algorithm by lengthbrian m. carlson, Feb 19, 2019
  24. 30/35 refspec: make hash size independentbrian m. carlson, Feb 19, 2019
  25. 27/35 get-tar-commit-id: parse comment recordbrian m. carlson, Feb 19, 2019
  26. 29/35 archive: convert struct archiver_args to object_idbrian m. carlson, Feb 19, 2019
  27. 34/35 Git.pm: make hash size independentbrian m. carlson, Feb 19, 2019
  28. 33/35 read-cache: read data in a hash-independent waybrian m. carlson, Feb 19, 2019
  29. 31/35 builtin/difftool: use parse_oid_hexbrian m. carlson, Feb 19, 2019
  30. 35/35 gitweb: make hash size independentbrian m. carlson, Feb 19, 2019
  31. 32/35 dir: make untracked cache extension hash size independentbrian m. carlson, Feb 19, 2019
  32. 16/35 builtin/am: make hash size independentbrian m. carlson, Feb 19, 2019
  33. 28/35 builtin/get-tar-commit-id: make hash size independentbrian m. carlson, Feb 19, 2019
  34. 13/35 builtin/name-rev: make hash-size independentbrian m. carlson, Feb 19, 2019
  35. 04/35 pack-bitmap: convert struct stored_bitmap to object_idbrian m. carlson, Feb 19, 2019
  36. 10/35 notes: make hash size independentbrian m. carlson, Feb 19, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.