From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string
Date: Wed, 7 Dec 2016 17:09:23 +0100 [thread overview]
Message-ID: <20161207160923.7028-3-szeder.dev@gmail.com> (raw)
In-Reply-To: <20161207160923.7028-1-szeder.dev@gmail.com>
ref-filter's parse_ref_filter_atom() function parses an atom between
the start and end pointers it gets as arguments. This is fine for two
of its callers, which process '%(atom)' format specifiers and the end
pointer comes directly from strchr() looking for the closing ')'.
However, it's not quite so straightforward for its other two callers,
which process sort specifiers given as plain nul-terminated strings.
Especially not for ref_default_sorting(), which has the default
hard-coded as a string literal, but can't use it directly, because a
pointer to the end of that string literal is needed as well.
The next patch will add yet another caller using a string literal.
Add a helper function around parse_ref_filter_atom() to parse an atom
up to the terminating nul, and call this helper in those two callers.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
ref-filter.c | 8 ++------
ref-filter.h | 4 ++++
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index dfadf577c..3c6fd4ba7 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1658,19 +1658,16 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
/* If no sorting option is given, use refname to sort as default */
struct ref_sorting *ref_default_sorting(void)
{
- static const char cstr_name[] = "refname";
-
struct ref_sorting *sorting = xcalloc(1, sizeof(*sorting));
sorting->next = NULL;
- sorting->atom = parse_ref_filter_atom(cstr_name, cstr_name + strlen(cstr_name));
+ sorting->atom = parse_ref_filter_atom_from_string("refname");
return sorting;
}
void parse_sorting_string(const char *arg, struct ref_sorting **sorting_tail)
{
struct ref_sorting *s;
- int len;
s = xcalloc(1, sizeof(*s));
s->next = *sorting_tail;
@@ -1683,8 +1680,7 @@ void parse_sorting_string(const char *arg, struct ref_sorting **sorting_tail)
if (skip_prefix(arg, "version:", &arg) ||
skip_prefix(arg, "v:", &arg))
s->version = 1;
- len = strlen(arg);
- s->atom = parse_ref_filter_atom(arg, arg+len);
+ s->atom = parse_ref_filter_atom_from_string(arg);
}
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
diff --git a/ref-filter.h b/ref-filter.h
index 49466a17d..1250537cf 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -94,6 +94,10 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
void ref_array_clear(struct ref_array *array);
/* Parse format string and sort specifiers */
int parse_ref_filter_atom(const char *atom, const char *ep);
+static inline int parse_ref_filter_atom_from_string(const char *atom)
+{
+ return parse_ref_filter_atom(atom, atom+strlen(atom));
+}
/* Used to verify if the given format is correct and to parse out the used atoms */
int verify_ref_format(const char *format);
/* Sort the given ref_array as per the ref_sorting provided */
--
2.11.0.78.g5a2d011
next prev parent reply other threads:[~2016-12-07 16:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-07 16:09 [PATCH 0/2] A bit of ref-filter atom parsing cleanups SZEDER Gábor
2016-12-07 16:09 ` [PATCH 1/2] ref-filter, tag: eliminate duplicated sorting option parsing SZEDER Gábor
2016-12-07 16:09 ` SZEDER Gábor [this message]
2016-12-08 18:58 ` [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string SZEDER Gábor
2017-01-26 13:15 ` SZEDER Gábor
2017-01-26 18:54 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161207160923.7028-3-szeder.dev@gmail.com \
--to=szeder.dev@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).