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

[PATCH v2 10/16] builtin/fmt-merge-msg: make hash independent

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jul 16, 2018, 01:28 UTC
Message-ID
<20180716012808.961328-11-sandals@crustytoothpaste.net>
In-Reply-To
<20180716012808.961328-1-sandals@crustytoothpaste.net>

Convert several uses of GIT_SHA1_HEXSZ into references to the_hash_algo. Switch other uses into a use of parse_oid_hex and uses of its computed pointer.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/fmt-merge-msg.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index bd680be687..e8c13a2c03 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -108,14 +108,15 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
 	struct string_list_item *item;
 	int pulling_head = 0;
 	struct object_id oid;
+	const unsigned hexsz = the_hash_algo->hexsz;
 
-	if (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\t')
+	if (len < hexsz + 3 || line[hexsz] != '\t')
 		return 1;
 
-	if (starts_with(line + GIT_SHA1_HEXSZ + 1, "not-for-merge"))
+	if (starts_with(line + hexsz + 1, "not-for-merge"))
 		return 0;
 
-	if (line[GIT_SHA1_HEXSZ + 1] != '\t')
+	if (line[hexsz + 1] != '\t')
 		return 2;
 
 	i = get_oid_hex(line, &oid);
@@ -130,7 +131,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
 
 	if (line[len - 1] == '\n')
 		line[len - 1] = 0;
-	line += GIT_SHA1_HEXSZ + 2;
+	line += hexsz + 2;
 
 	/*
 	 * At this point, line points at the beginning of comment e.g.
@@ -342,7 +343,7 @@ static void shortlog(const char *name,
 	const struct object_id *oid = &origin_data->oid;
 	int limit = opts->shortlog_len;
 
-	branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
+	branch = deref_tag(parse_object(oid), oid_to_hex(oid), the_hash_algo->hexsz);
 	if (!branch || branch->type != OBJ_COMMIT)
 		return;
 
@@ -545,6 +546,7 @@ static void find_merge_parents(struct merge_parents *result,
 		int len;
 		char *p = in->buf + pos;
 		char *newline = strchr(p, '\n');
+		const char *q;
 		struct object_id oid;
 		struct commit *parent;
 		struct object *obj;
@@ -552,10 +554,9 @@ static void find_merge_parents(struct merge_parents *result,
 		len = newline ? newline - p : strlen(p);
 		pos += len + !!newline;
 
-		if (len < GIT_SHA1_HEXSZ + 3 ||
-		    get_oid_hex(p, &oid) ||
-		    p[GIT_SHA1_HEXSZ] != '\t' ||
-		    p[GIT_SHA1_HEXSZ + 1] != '\t')
+		if (parse_oid_hex(p, &oid, &q) ||
+		    q[0] != '\t' ||
+		    q[1] != '\t')
 			continue; /* skip not-for-merge */
 		/*
 		 * Do not use get_merge_parent() here; we do not have
Previous: brian m. carlsonNext: brian m. carlson
Message 11 of 20 in “object_id part 14”
  1. 00/16 object_id part 14brian m. carlson, Jul 16, 2018
  2. 01/16 cache: update object ID functions for the_hash_algobrian m. carlson, Jul 16, 2018
  3. 02/16 tree-walk: replace hard-coded constants with the_hash_algobrian m. carlson, Jul 16, 2018
  4. 03/16 hex: switch to using the_hash_algobrian m. carlson, Jul 16, 2018
  5. 05/16 strbuf: allocate space with GIT_MAX_HEXSZbrian m. carlson, Jul 16, 2018
  6. 04/16 commit: express tree entry constants in terms of the_hash_algobrian m. carlson, Jul 16, 2018
  7. 07/16 refs/files-backend: use the_hash_algo for writing refsbrian m. carlson, Jul 16, 2018
  8. 08/16 builtin/update-index: convert to using the_hash_algobrian m. carlson, Jul 16, 2018
  9. 09/16 builtin/update-index: simplify parsing of cacheinfobrian m. carlson, Jul 16, 2018
  10. 06/16 sha1-name: use the_hash_algo when parsing object namesbrian m. carlson, Jul 16, 2018
  11. 10/16 builtin/fmt-merge-msg: make hash independentbrian m. carlson, Jul 16, 2018
  12. 11/16 builtin/merge: switch to use the_hash_algobrian m. carlson, Jul 16, 2018
  13. 12/16 builtin/merge-recursive: make hash independentbrian m. carlson, Jul 16, 2018
  14. 13/16 diff: switch GIT_SHA1_HEXSZ to use the_hash_algobrian m. carlson, Jul 16, 2018
  15. 14/16 log-tree: switch GIT_SHA1_HEXSZ to the_hash_algo->hexszbrian m. carlson, Jul 16, 2018
  16. 15/16 sha1-file: convert constants to uses of the_hash_algobrian m. carlson, Jul 16, 2018
  17. 16/16 pretty: switch hard-coded constants to the_hash_algobrian m. carlson, Jul 16, 2018
  18. Derrick StoleeJul 16, 2018
  19. Taylor BlauJul 16, 2018
  20. Stefan BellerJul 16, 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.