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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 13, 2017 at 11:02 UTC
29ef53cd361e8751f9f2f40811af0ce863e449b6
1 file changed
+8
-4
ref-filter.c
+8
-4
@@ -2114,6 +2114,12 @@ void pretty_print_ref(const char *name, const unsigned char *sha1,
2114
free_array_item(ref_item);
2115
}
2116
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
+
2123
/* If no sorting option is given, use refname to sort as default */
2124
struct ref_sorting *ref_default_sorting(void)
2125
{
@@ -2122,14 +2128,13 @@ struct ref_sorting *ref_default_sorting(void)
2128
struct ref_sorting *sorting = xcalloc(1, sizeof(*sorting));
2129
2130
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);
2132
return sorting;
2133
}
2134
2135
void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
2136
{
2137
struct ref_sorting *s;
2132
- int len;
2138
2139
s = xcalloc(1, sizeof(*s));
2140
s->next = *sorting_tail;
@@ -2142,8 +2147,7 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
2147
if (skip_prefix(arg, "version:", &arg) ||
2148
skip_prefix(arg, "v:", &arg))
2149
s->version = 1;
2145
- len = strlen(arg);
2146
- s->atom = parse_ref_filter_atom(arg, arg+len);
2150
+ s->atom = parse_sorting_atom(arg);
2151
}
2152
2153
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)