Skip to content

Commit 25a8d79

Browse files
KarthikNayakgitster
authored andcommitted
ref-filter: introduce parse_align_position()
Extract parse_align_position() from populate_value(), which, given a string, would give us the alignment position. This is a preparatory patch as to introduce prefixes for the %(align) atom and avoid redundancy in the code. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Karthik Nayak <Karthik.188@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fd935cc commit 25a8d79

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

ref-filter.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ static void color_atom_parser(struct used_atom *atom, const char *color_value)
4444
die(_("unrecognized color: %%(color:%s)"), color_value);
4545
}
4646

47+
static align_type parse_align_position(const char *s)
48+
{
49+
if (!strcmp(s, "right"))
50+
return ALIGN_RIGHT;
51+
else if (!strcmp(s, "middle"))
52+
return ALIGN_MIDDLE;
53+
else if (!strcmp(s, "left"))
54+
return ALIGN_LEFT;
55+
return -1;
56+
}
57+
4758
static struct {
4859
const char *name;
4960
cmp_type cmp_type;
@@ -912,14 +923,12 @@ static void populate_value(struct ref_array_item *ref)
912923
string_list_split(&params, valp, ',', -1);
913924
for (i = 0; i < params.nr; i++) {
914925
const char *s = params.items[i].string;
926+
int position;
927+
915928
if (!strtoul_ui(s, 10, (unsigned int *)&width))
916929
;
917-
else if (!strcmp(s, "left"))
918-
align->position = ALIGN_LEFT;
919-
else if (!strcmp(s, "right"))
920-
align->position = ALIGN_RIGHT;
921-
else if (!strcmp(s, "middle"))
922-
align->position = ALIGN_MIDDLE;
930+
else if ((position = parse_align_position(s)) >= 0)
931+
align->position = position;
923932
else
924933
die(_("improper format entered align:%s"), s);
925934
}

0 commit comments

Comments
 (0)