builtin/fmt-merge-msg: make hash independent

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jul 16, 2018 at 01:28 UTC 5188eb5d8e80c2f330fbafb021ffa28bac2ef88a
1 file changed +10 -9
builtin/fmt-merge-msg.c
+10 -9
@@ -108,14 +108,15 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
108 struct string_list_item *item;
109 int pulling_head = 0;
110 struct object_id oid;
111 + const unsigned hexsz = the_hash_algo->hexsz;
112
112 - if (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\t')
113 + if (len < hexsz + 3 || line[hexsz] != '\t')
114 return 1;
115
115 - if (starts_with(line + GIT_SHA1_HEXSZ + 1, "not-for-merge"))
116 + if (starts_with(line + hexsz + 1, "not-for-merge"))
117 return 0;
118
118 - if (line[GIT_SHA1_HEXSZ + 1] != '\t')
119 + if (line[hexsz + 1] != '\t')
120 return 2;
121
122 i = get_oid_hex(line, &oid);
@@ -130,7 +131,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
131
132 if (line[len - 1] == '\n')
133 line[len - 1] = 0;
133 - line += GIT_SHA1_HEXSZ + 2;
134 + line += hexsz + 2;
135
136 /*
137 * At this point, line points at the beginning of comment e.g.
@@ -342,7 +343,7 @@ static void shortlog(const char *name,
343 const struct object_id *oid = &origin_data->oid;
344 int limit = opts->shortlog_len;
345
345 - branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
346 + branch = deref_tag(parse_object(oid), oid_to_hex(oid), the_hash_algo->hexsz);
347 if (!branch || branch->type != OBJ_COMMIT)
348 return;
349
@@ -545,6 +546,7 @@ static void find_merge_parents(struct merge_parents *result,
546 int len;
547 char *p = in->buf + pos;
548 char *newline = strchr(p, '\n');
549 + const char *q;
550 struct object_id oid;
551 struct commit *parent;
552 struct object *obj;
@@ -552,10 +554,9 @@ static void find_merge_parents(struct merge_parents *result,
554 len = newline ? newline - p : strlen(p);
555 pos += len + !!newline;
556
555 - if (len < GIT_SHA1_HEXSZ + 3 ||
556 - get_oid_hex(p, &oid) ||
557 - p[GIT_SHA1_HEXSZ] != '\t' ||
558 - p[GIT_SHA1_HEXSZ + 1] != '\t')
557 + if (parse_oid_hex(p, &oid, &q) ||
558 + q[0] != '\t' ||
559 + q[1] != '\t')
560 continue; /* skip not-for-merge */
561 /*
562 * Do not use get_merge_parent() here; we do not have