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

[PATCH 07/14] refs/packed-backend: express constants using the_hash_algo

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

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

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs/packed-backend.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 74e2996e93..c01c7f5901 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -274,8 +274,8 @@ struct snapshot_record {
 static int cmp_packed_ref_records(const void *v1, const void *v2)
 {
 	const struct snapshot_record *e1 = v1, *e2 = v2;
-	const char *r1 = e1->start + GIT_SHA1_HEXSZ + 1;
-	const char *r2 = e2->start + GIT_SHA1_HEXSZ + 1;
+	const char *r1 = e1->start + the_hash_algo->hexsz + 1;
+	const char *r2 = e2->start + the_hash_algo->hexsz + 1;
 
 	while (1) {
 		if (*r1 == '\n')
@@ -297,7 +297,7 @@ static int cmp_packed_ref_records(const void *v1, const void *v2)
  */
 static int cmp_record_to_refname(const char *rec, const char *refname)
 {
-	const char *r1 = rec + GIT_SHA1_HEXSZ + 1;
+	const char *r1 = rec + the_hash_algo->hexsz + 1;
 	const char *r2 = refname;
 
 	while (1) {
@@ -344,7 +344,7 @@ static void sort_snapshot(struct snapshot *snapshot)
 		if (!eol)
 			/* The safety check should prevent this. */
 			BUG("unterminated line found in packed-refs");
-		if (eol - pos < GIT_SHA1_HEXSZ + 2)
+		if (eol - pos < the_hash_algo->hexsz + 2)
 			die_invalid_line(snapshot->refs->path,
 					 pos, eof - pos);
 		eol++;
@@ -456,7 +456,7 @@ static void verify_buffer_safe(struct snapshot *snapshot)
 		return;
 
 	last_line = find_start_of_record(start, eof - 1);
-	if (*(eof - 1) != '\n' || eof - last_line < GIT_SHA1_HEXSZ + 2)
+	if (*(eof - 1) != '\n' || eof - last_line < the_hash_algo->hexsz + 2)
 		die_invalid_line(snapshot->refs->path,
 				 last_line, eof - last_line);
 }
@@ -796,7 +796,7 @@ static int next_record(struct packed_ref_iterator *iter)
 
 	iter->base.flags = REF_ISPACKED;
 
-	if (iter->eof - p < GIT_SHA1_HEXSZ + 2 ||
+	if (iter->eof - p < the_hash_algo->hexsz + 2 ||
 	    parse_oid_hex(p, &iter->oid, &p) ||
 	    !isspace(*p++))
 		die_invalid_line(iter->snapshot->refs->path,
@@ -826,7 +826,7 @@ static int next_record(struct packed_ref_iterator *iter)
 
 	if (iter->pos < iter->eof && *iter->pos == '^') {
 		p = iter->pos + 1;
-		if (iter->eof - p < GIT_SHA1_HEXSZ + 1 ||
+		if (iter->eof - p < the_hash_algo->hexsz + 1 ||
 		    parse_oid_hex(p, &iter->peeled, &p) ||
 		    *p++ != '\n')
 			die_invalid_line(iter->snapshot->refs->path,
Previous: brian m. carlsonNext: brian m. carlson
Message 18 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.