Skip to content

Commit 5188eb5

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe04ccf commit 5188eb5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

builtin/fmt-merge-msg.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
108108
struct string_list_item *item;
109109
int pulling_head = 0;
110110
struct object_id oid;
111+
const unsigned hexsz = the_hash_algo->hexsz;
111112

112-
if (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\t')
113+
if (len < hexsz + 3 || line[hexsz] != '\t')
113114
return 1;
114115

115-
if (starts_with(line + GIT_SHA1_HEXSZ + 1, "not-for-merge"))
116+
if (starts_with(line + hexsz + 1, "not-for-merge"))
116117
return 0;
117118

118-
if (line[GIT_SHA1_HEXSZ + 1] != '\t')
119+
if (line[hexsz + 1] != '\t')
119120
return 2;
120121

121122
i = get_oid_hex(line, &oid);
@@ -130,7 +131,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
130131

131132
if (line[len - 1] == '\n')
132133
line[len - 1] = 0;
133-
line += GIT_SHA1_HEXSZ + 2;
134+
line += hexsz + 2;
134135

135136
/*
136137
* At this point, line points at the beginning of comment e.g.
@@ -342,7 +343,7 @@ static void shortlog(const char *name,
342343
const struct object_id *oid = &origin_data->oid;
343344
int limit = opts->shortlog_len;
344345

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);
346347
if (!branch || branch->type != OBJ_COMMIT)
347348
return;
348349

@@ -545,17 +546,17 @@ static void find_merge_parents(struct merge_parents *result,
545546
int len;
546547
char *p = in->buf + pos;
547548
char *newline = strchr(p, '\n');
549+
const char *q;
548550
struct object_id oid;
549551
struct commit *parent;
550552
struct object *obj;
551553

552554
len = newline ? newline - p : strlen(p);
553555
pos += len + !!newline;
554556

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')
559560
continue; /* skip not-for-merge */
560561
/*
561562
* Do not use get_merge_parent() here; we do not have

0 commit comments

Comments
 (0)