All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] A bit of ref-filter atom parsing cleanups
@ 2016-12-07 16:09 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 ` [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string SZEDER Gábor
  0 siblings, 2 replies; 6+ messages in thread
From: SZEDER Gábor @ 2016-12-07 16:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor

The diffstat of the second patch doesn't show any benefits, but only
because the first patch removed a callsite that would have benefited from
it.

It merges cleanly with Karthik's "port branch.c to use ref-filter's
printing options" series.

SZEDER Gábor (2):
  ref-filter, tag: eliminate duplicated sorting option parsing
  ref-filter: add function to parse atoms from a nul-terminated string

 builtin/tag.c | 24 ------------------------
 ref-filter.c  | 24 +++++++++++++-----------
 ref-filter.h  |  6 ++++++
 3 files changed, 19 insertions(+), 35 deletions(-)

-- 
2.11.0.78.g5a2d011


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] ref-filter, tag: eliminate duplicated sorting option parsing
  2016-12-07 16:09 [PATCH 0/2] A bit of ref-filter atom parsing cleanups SZEDER Gábor
@ 2016-12-07 16:09 ` SZEDER Gábor
  2016-12-07 16:09 ` [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string SZEDER Gábor
  1 sibling, 0 replies; 6+ messages in thread
From: SZEDER Gábor @ 2016-12-07 16:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor

Sorting options are either specified on the command line, which is
handled by parse_opt_ref_sorting() in ref-filter.c, or via the
'tag.sort' config variable, which is handled by parse_sorting_string()
in builtin/tag.c.  These two functions are nearly identical, the
difference being only their signature and the former having a couple
of extra lines at the beginning.

Eliminate the code duplication by making parse_sorting_string() part
of the public ref-filter API, and turning parse_opt_ref_sorting() into
a thin wrapper around that function.  This way builtin/tag.c can
continue using it as before (and it might be useful if there ever will
be a 'branch.sort' config variable).  Change its return type from int
to void, because it always returned zero and none of its callers cared
about it (the actual error handling is done inside
parse_ref_filter_atom() by die()ing on error).

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 builtin/tag.c | 24 ------------------------
 ref-filter.c  | 16 +++++++++++-----
 ref-filter.h  |  2 ++
 3 files changed, 13 insertions(+), 29 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index 50e4ae567..6fe723bee 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -122,30 +122,6 @@ static const char tag_template_nocleanup[] =
 	"Lines starting with '%c' will be kept; you may remove them"
 	" yourself if you want to.\n");
 
-/* Parse arg given and add it the ref_sorting array */
-static int 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;
-	*sorting_tail = s;
-
-	if (*arg == '-') {
-		s->reverse = 1;
-		arg++;
-	}
-	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);
-
-	return 0;
-}
-
 static int git_tag_config(const char *var, const char *value, void *cb)
 {
 	int status;
diff --git a/ref-filter.c b/ref-filter.c
index bc551a752..dfadf577c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1667,15 +1667,11 @@ struct ref_sorting *ref_default_sorting(void)
 	return sorting;
 }
 
-int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
+void parse_sorting_string(const char *arg, struct ref_sorting **sorting_tail)
 {
-	struct ref_sorting **sorting_tail = opt->value;
 	struct ref_sorting *s;
 	int len;
 
-	if (!arg) /* should --no-sort void the list ? */
-		return -1;
-
 	s = xcalloc(1, sizeof(*s));
 	s->next = *sorting_tail;
 	*sorting_tail = s;
@@ -1689,6 +1685,16 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
 		s->version = 1;
 	len = strlen(arg);
 	s->atom = parse_ref_filter_atom(arg, arg+len);
+}
+
+int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
+{
+	struct ref_sorting **sorting_tail = opt->value;
+
+	if (!arg) /* should --no-sort void the list ? */
+		return -1;
+
+	parse_sorting_string(arg, sorting_tail);
 	return 0;
 }
 
diff --git a/ref-filter.h b/ref-filter.h
index 14d435e2c..49466a17d 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -100,6 +100,8 @@ int verify_ref_format(const char *format);
 void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
 /*  Print the ref using the given format and quote_style */
 void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style);
+/* Parse given arg and append it to the ref_sorting list */
+void parse_sorting_string(const char *arg, struct ref_sorting **sorting_tail);
 /*  Callback function for parsing the sort option */
 int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
 /*  Default sort option based on refname */
-- 
2.11.0.78.g5a2d011


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string
  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
  2016-12-08 18:58   ` SZEDER Gábor
  2017-01-26 13:15   ` SZEDER Gábor
  1 sibling, 2 replies; 6+ messages in thread
From: SZEDER Gábor @ 2016-12-07 16:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string
  2016-12-07 16:09 ` [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string SZEDER Gábor
@ 2016-12-08 18:58   ` SZEDER Gábor
  2017-01-26 13:15   ` SZEDER Gábor
  1 sibling, 0 replies; 6+ messages in thread
From: SZEDER Gábor @ 2016-12-08 18:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor

On Wed, Dec 7, 2016 at 5:09 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:
> 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.

Oops, that last sentence should be deleted, there is no third patch, sorry.

Gábor

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string
  2016-12-07 16:09 ` [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string SZEDER Gábor
  2016-12-08 18:58   ` SZEDER Gábor
@ 2017-01-26 13:15   ` SZEDER Gábor
  2017-01-26 18:54     ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: SZEDER Gábor @ 2017-01-26 13:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor

On Wed, Dec 7, 2016 at 5:09 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:
> 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(-)

Ping?

It looks like that this little two piece cleanup series fell on the floor.



> 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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string
  2017-01-26 13:15   ` SZEDER Gábor
@ 2017-01-26 18:54     ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2017-01-26 18:54 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git

SZEDER Gábor <szeder.dev@gmail.com> writes:

> On Wed, Dec 7, 2016 at 5:09 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:
>> 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(-)
>
> Ping?
>
> It looks like that this little two piece cleanup series fell on the floor.

I am still waiting for somebody else to comment on the changes, and
the final reroll after such a review discussion to address your own
comment in <CAM0VKjk1mnNzQX6LThq1t7keesBz_fjE9x2e0ywsBKSNKP9SCw@mail.gmail.com>




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-01-26 18:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] ref-filter: add function to parse atoms from a nul-terminated string SZEDER Gábor
2016-12-08 18:58   ` SZEDER Gábor
2017-01-26 13:15   ` SZEDER Gábor
2017-01-26 18:54     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.