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

[PATCH 08/14] upload-pack: express constants in terms of the_hash_algo

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 8, 2018, 21:56 UTC
Message-ID
<20181008215701.779099-9-sandals@crustytoothpaste.net>
In-Reply-To
<20181008215701.779099-1-sandals@crustytoothpaste.net>

Convert all uses of the GIT_SHA1_HEXSZ to use the_hash_algo so that they are appropriate for any given hash length.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 upload-pack.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/upload-pack.c b/upload-pack.c
index 62a1000f44..1aae5dd828 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -443,6 +443,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 	struct object *o;
 	char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
 	int i;
+	const unsigned hexsz = the_hash_algo->hexsz;
 
 	cmd->argv = argv;
 	cmd->git_cmd = 1;
@@ -461,7 +462,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 		goto error;
 
 	namebuf[0] = '^';
-	namebuf[GIT_SHA1_HEXSZ + 1] = '\n';
+	namebuf[hexsz + 1] = '\n';
 	for (i = get_max_object_index(); 0 < i; ) {
 		o = get_indexed_object(--i);
 		if (!o)
@@ -470,11 +471,11 @@ static int do_reachable_revlist(struct child_process *cmd,
 			o->flags &= ~TMP_MARK;
 		if (!is_our_ref(o))
 			continue;
-		memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
-		if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0)
+		memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
+		if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
 			goto error;
 	}
-	namebuf[GIT_SHA1_HEXSZ] = '\n';
+	namebuf[hexsz] = '\n';
 	for (i = 0; i < src->nr; i++) {
 		o = src->objects[i].item;
 		if (is_our_ref(o)) {
@@ -484,8 +485,8 @@ static int do_reachable_revlist(struct child_process *cmd,
 		}
 		if (reachable && o->type == OBJ_COMMIT)
 			o->flags |= TMP_MARK;
-		memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
-		if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0)
+		memcpy(namebuf, oid_to_hex(&o->oid), hexsz);
+		if (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)
 			goto error;
 	}
 	close(cmd->in);
Previous: brian m. carlsonNext: brian m. carlson
Message 19 of 30 in “Hash function transition part 15”
  1. 00/14 Hash function transition part 15brian m. carlson, Oct 8, 2018
  2. 01/14 pack-bitmap-write: use GIT_MAX_RAWSZ for allocationbrian m. carlson, Oct 8, 2018
  3. 02/14 builtin/repack: replace hard-coded constantbrian m. carlson, Oct 8, 2018
  4. Stefan BellerOct 8, 2018
  5. Eric SunshineOct 8, 2018
  6. brian m. carlsonOct 9, 2018
  7. 06/14 packfile: express constants in terms of the_hash_algobrian m. carlson, Oct 8, 2018
  8. Stefan BellerOct 8, 2018
  9. brian m. carlsonOct 9, 2018
  10. Stefan BellerOct 9, 2018
  11. brian m. carlsonOct 9, 2018
  12. 03/14 builtin/mktree: remove hard-coded constantbrian m. carlson, Oct 8, 2018
  13. Stefan BellerOct 8, 2018
  14. 04/14 builtin/fetch-pack: remove constants with parse_oid_hexbrian m. carlson, Oct 8, 2018
  15. 05/14 pack-revindex: express constants in terms of the_hash_algobrian m. carlson, Oct 8, 2018
  16. Stefan BellerOct 8, 2018
  17. brian m. carlsonOct 9, 2018
  18. 07/14 refs/packed-backend: express constants using the_hash_algobrian m. carlson, Oct 8, 2018
  19. 08/14 upload-pack: express constants in terms of the_hash_algobrian m. carlson, Oct 8, 2018
  20. 10/14 tag: express constant in terms of the_hash_algobrian m. carlson, Oct 8, 2018
  21. 09/14 transport: use parse_oid_hex instead of a constantbrian m. carlson, Oct 8, 2018
  22. 11/14 apply: replace hard-coded constantsbrian m. carlson, Oct 8, 2018
  23. 12/14 apply: rename new_sha1_prefix and old_sha1_prefixbrian m. carlson, Oct 8, 2018
  24. 13/14 submodule: make zero-oid comparison hash function agnosticbrian m. carlson, Oct 8, 2018
  25. Stefan BellerOct 8, 2018
  26. 14/14 rerere: convert to use the_hash_algobrian m. carlson, Oct 8, 2018
  27. Stefan BellerOct 8, 2018
  28. object_id.cocci: match only expressions of type 'struct object_id'SZEDER Gábor, Oct 12, 2018
  29. Junio C HamanoOct 15, 2018
  30. Junio C HamanoOct 15, 2018

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.