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

[PATCH v2 03/15] builtin/repack: replace hard-coded constants

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 15, 2018, 00:01 UTC
Message-ID
<20181015000202.951965-4-sandals@crustytoothpaste.net>
In-Reply-To
<20181015000202.951965-1-sandals@crustytoothpaste.net>

Note that while the error messages here are not translated, the end user should never see them. We invoke git pack-objects shortly before both invocations, so we can be fairly certain that the data we're receiving is in fact valid.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/repack.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index c6a7943d5c..0223f2880c 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -235,8 +235,8 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
 	while (strbuf_getline_lf(&line, out) != EOF) {
 		char *promisor_name;
 		int fd;
-		if (line.len != 40)
-			die("repack: Expecting 40 character sha1 lines only from pack-objects.");
+		if (line.len != the_hash_algo->hexsz)
+			die("repack: Expecting full hex object ID lines only from pack-objects.");
 		string_list_append(names, line.buf);
 
 		/*
@@ -407,8 +407,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
 	out = xfdopen(cmd.out, "r");
 	while (strbuf_getline_lf(&line, out) != EOF) {
-		if (line.len != 40)
-			die("repack: Expecting 40 character sha1 lines only from pack-objects.");
+		if (line.len != the_hash_algo->hexsz)
+			die("repack: Expecting full hex object ID lines only from pack-objects.");
 		string_list_append(&names, line.buf);
 	}
 	fclose(out);
@@ -535,14 +535,15 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	reprepare_packed_git(the_repository);
 
 	if (delete_redundant) {
+		const int hexsz = the_hash_algo->hexsz;
 		int opts = 0;
 		string_list_sort(&names);
 		for_each_string_list_item(item, &existing_packs) {
 			char *sha1;
 			size_t len = strlen(item->string);
-			if (len < 40)
+			if (len < hexsz)
 				continue;
-			sha1 = item->string + len - 40;
+			sha1 = item->string + len - hexsz;
 			if (!string_list_has_string(&names, sha1))
 				remove_redundant_pack(packdir, item->string);
 		}
Previous: brian m. carlsonNext: brian m. carlson
Message 4 of 17 in “Hash function transition part 15”
  1. 00/15 Hash function transition part 15brian m. carlson, Oct 15, 2018
  2. 01/15 object_id.cocci: match only expressions of type 'struct object_id'brian m. carlson, Oct 15, 2018
  3. 02/15 pack-bitmap-write: use GIT_MAX_RAWSZ for allocationbrian m. carlson, Oct 15, 2018
  4. 03/15 builtin/repack: replace hard-coded constantsbrian m. carlson, Oct 15, 2018
  5. 04/15 builtin/mktree: remove hard-coded constantbrian m. carlson, Oct 15, 2018
  6. 05/15 builtin/fetch-pack: remove constants with parse_oid_hexbrian m. carlson, Oct 15, 2018
  7. 06/15 pack-revindex: express constants in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  8. 07/15 packfile: express constants in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  9. 09/15 upload-pack: express constants in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  10. 08/15 refs/packed-backend: express constants using the_hash_algobrian m. carlson, Oct 15, 2018
  11. 10/15 transport: use parse_oid_hex instead of a constantbrian m. carlson, Oct 15, 2018
  12. 11/15 tag: express constant in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  13. 13/15 apply: rename new_sha1_prefix and old_sha1_prefixbrian m. carlson, Oct 15, 2018
  14. 12/15 apply: replace hard-coded constantsbrian m. carlson, Oct 15, 2018
  15. 14/15 submodule: make zero-oid comparison hash function agnosticbrian m. carlson, Oct 15, 2018
  16. 15/15 rerere: convert to use the_hash_algobrian m. carlson, Oct 15, 2018
  17. Junio C HamanoOct 25, 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.