From: Santiago Torres <santi...@nyu.edu>

The format specifier will be likely used in other functions throughout
git tag. One likely candidate to require format strings in the future is
the gpg_verify_tag function. However, changing the signature of
functions such as for_each_ref or verify_tag would be quite burdensome.

Instead, we move the format string specifier to a static global variable
that modules can access in the same way git-log and other modules handle
this case.

Signed-off-by: Santiago Torres <santi...@nyu.edu>
---
 builtin/tag.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index 50e4ae5..dbf271f 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -30,8 +30,9 @@ static const char * const git_tag_usage[] = {
 
 static unsigned int colopts;
 static int force_sign_annotate;
+static const char *fmt_pretty;
 
-static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, 
const char *format)
+static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting)
 {
        struct ref_array array;
        char *to_free = NULL;
@@ -42,23 +43,23 @@ static int list_tags(struct ref_filter *filter, struct 
ref_sorting *sorting, con
        if (filter->lines == -1)
                filter->lines = 0;
 
-       if (!format) {
+       if (!fmt_pretty) {
                if (filter->lines) {
                        to_free = xstrfmt("%s %%(contents:lines=%d)",
                                          "%(align:15)%(refname:strip=2)%(end)",
                                          filter->lines);
-                       format = to_free;
+                       fmt_pretty = to_free;
                } else
-                       format = "%(refname:strip=2)";
+                       fmt_pretty = "%(refname:strip=2)";
        }
 
-       verify_ref_format(format);
+       verify_ref_format(fmt_pretty);
        filter->with_commit_tag_algo = 1;
        filter_refs(&array, filter, FILTER_REFS_TAGS);
        ref_array_sort(sorting, &array);
 
        for (i = 0; i < array.nr; i++)
-               show_ref_array_item(array.items[i], format, 0);
+               show_ref_array_item(array.items[i], fmt_pretty, 0);
        ref_array_clear(&array);
        free(to_free);
 
@@ -334,7 +335,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        struct strbuf err = STRBUF_INIT;
        struct ref_filter filter;
        static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
-       const char *format = NULL;
        struct option options[] = {
                OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
                { OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
@@ -369,7 +369,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                        OPTION_CALLBACK, 0, "points-at", &filter.points_at, 
N_("object"),
                        N_("print only tags of the object"), 0, 
parse_opt_object_name
                },
-               OPT_STRING(  0 , "format", &format, N_("format"), N_("format to 
use for the output")),
+               OPT_STRING(  0 , "format", &fmt_pretty, N_("format"), 
N_("format to use for the output")),
                OPT_END()
        };
 
@@ -410,7 +410,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                        run_column_filter(colopts, &copts);
                }
                filter.name_patterns = argv;
-               ret = list_tags(&filter, sorting, format);
+               ret = list_tags(&filter, sorting);
                if (column_active(colopts))
                        stop_column_filter();
                return ret;
-- 
2.10.0

Reply via email to