Skip to content

Commit 29ef53c

Browse files
peffgitster
authored andcommitted
ref-filter: factor out the parsing of sorting atoms
We parse sort strings as single formatting atoms, and just build on parse_ref_filter_atom(). Let's pull this idea into its own function, since it's about to get a little more complex. As a bonus, we can give the function a slightly more natural interface, since our single atoms are in their own strings. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa8a5d1 commit 29ef53c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ref-filter.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,12 @@ void pretty_print_ref(const char *name, const unsigned char *sha1,
21142114
free_array_item(ref_item);
21152115
}
21162116

2117+
static int parse_sorting_atom(const char *atom)
2118+
{
2119+
const char *end = atom + strlen(atom);
2120+
return parse_ref_filter_atom(atom, end);
2121+
}
2122+
21172123
/* If no sorting option is given, use refname to sort as default */
21182124
struct ref_sorting *ref_default_sorting(void)
21192125
{
@@ -2122,14 +2128,13 @@ struct ref_sorting *ref_default_sorting(void)
21222128
struct ref_sorting *sorting = xcalloc(1, sizeof(*sorting));
21232129

21242130
sorting->next = NULL;
2125-
sorting->atom = parse_ref_filter_atom(cstr_name, cstr_name + strlen(cstr_name));
2131+
sorting->atom = parse_sorting_atom(cstr_name);
21262132
return sorting;
21272133
}
21282134

21292135
void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
21302136
{
21312137
struct ref_sorting *s;
2132-
int len;
21332138

21342139
s = xcalloc(1, sizeof(*s));
21352140
s->next = *sorting_tail;
@@ -2142,8 +2147,7 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
21422147
if (skip_prefix(arg, "version:", &arg) ||
21432148
skip_prefix(arg, "v:", &arg))
21442149
s->version = 1;
2145-
len = strlen(arg);
2146-
s->atom = parse_ref_filter_atom(arg, arg+len);
2150+
s->atom = parse_sorting_atom(arg);
21472151
}
21482152

21492153
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)

0 commit comments

Comments
 (0)