From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: christian.couder@gmail.com, Matthieu.Moy@grenoble-inp.fr,
gitster@pobox.com, Karthik Nayak <Karthik.188@gmail.com>
Subject: [PATCH v12 00/13] port tag.c to use ref-filter.c APIs
Date: Wed, 19 Aug 2015 00:07:19 +0530 [thread overview]
Message-ID: <1439923052-7373-1-git-send-email-Karthik.188@gmail.com> (raw)
This is part of my GSoC project to "unify the code used by branch -l,
tag -l, and for-each-ref". This series ports over tag.c to use ref-filter
APIs.
Version 11 was posted here:
http://article.gmane.org/gmane.comp.version-control.git/275997
Changes in this version:
* Small style and formatting changes.
* Remove unnecessary variable from push_new_state().
* pop_state doesn't return a value now and attaches the buffer
into the previous state.
* use strcmp() rather than starts_with() while checking for
alignment position.
* Change attend to at_end
Karthik Nayak (13):
ref-filter: move `struct atom_value` to ref-filter.c
ref-filter: introduce ref_formatting_state
ref-filter: introduce the ref_formatting_state stack machinery
utf8: add function to align a string into given strbuf
ref-filter: implement an `align` atom
ref-filter: add option to filter out tags, branches and remotes
ref-filter: support printing N lines from tag annotation
ref-filter: add support to sort by version
ref-filter: add option to match literal pattern
tag.c: use 'ref-filter' data structures
tag.c: use 'ref-filter' APIs
tag.c: implement '--format' option
tag.c: implement '--merged' and '--no-merged' options
Documentation/git-for-each-ref.txt | 11 ++
Documentation/git-tag.txt | 34 +++-
builtin/for-each-ref.c | 3 +-
builtin/tag.c | 367 +++++++------------------------------
ref-filter.c | 312 +++++++++++++++++++++++++++----
ref-filter.h | 32 +++-
refs.c | 9 +
refs.h | 1 +
t/t6302-for-each-ref-filter.sh | 84 +++++++++
t/t7004-tag.sh | 51 +++++-
utf8.c | 21 +++
utf8.h | 15 ++
12 files changed, 577 insertions(+), 363 deletions(-)
Interdiff:
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 3099631..760d719 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -128,8 +128,8 @@ color::
are described in `color.branch.*`.
align::
- left-, middle-, or right-align the content between %(align:..)
- and %(end). Followed by `:<position>,<width>`, where the
+ Left-, middle-, or right-align the content between %(align:..)
+ and %(end). Followed by `:<width>>,<position>`, where the
`<position>` is either left, right or middle and `<width>` is
the total length of the content with alignment. If the
contents length is more than the width then no alignment is
diff --git a/ref-filter.c b/ref-filter.c
index a6086b2..665221b 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -66,9 +66,9 @@ struct align {
};
struct ref_formatting_state {
- struct strbuf output;
struct ref_formatting_state *prev;
- void (*attend)(struct ref_formatting_state *state);
+ struct strbuf output;
+ void (*at_end)(struct ref_formatting_state *state);
void *cb_data;
int quote_style;
};
@@ -149,24 +149,25 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
return at;
}
-static struct ref_formatting_state *push_new_state(struct ref_formatting_state **state)
+static void push_new_state(struct ref_formatting_state **stack)
{
- struct ref_formatting_state *new = xcalloc(1, sizeof(struct ref_formatting_state));
- struct ref_formatting_state *old = *state;
+ struct ref_formatting_state *s = xcalloc(1, sizeof(struct ref_formatting_state));
- *state = new;
- new->prev = old;
- return new;
+ strbuf_init(&s->output, 0);
+ s->prev = *stack;
+ *stack = s;
}
-static void pop_state(struct ref_formatting_state **state)
+static void pop_state(struct ref_formatting_state **stack)
{
- struct ref_formatting_state *current = *state;
+ struct ref_formatting_state *current = *stack;
struct ref_formatting_state *prev = current->prev;
+ if (prev)
+ strbuf_addbuf(&prev->output, ¤t->output);
strbuf_release(¤t->output);
free(current);
- *state = prev;
+ *stack = prev;
}
/*
@@ -641,29 +642,31 @@ static inline char *copy_advance(char *dst, const char *src)
static void align_handler(struct ref_formatting_state *state)
{
- struct strbuf aligned = STRBUF_INIT;
- struct ref_formatting_state *return_to = state->prev;
struct align *align = (struct align *)state->cb_data;
+ struct strbuf s = STRBUF_INIT;
- strbuf_utf8_align(&aligned, align->position, align->width, state->output.buf);
- strbuf_addbuf(&return_to->output, &aligned);
- strbuf_release(&aligned);
+ strbuf_utf8_align(&s, align->position, align->width, state->output.buf);
+ strbuf_reset(&state->output);
+ strbuf_addbuf(&state->output, &s);
+ free(align);
}
static void align_atom_handler(struct atom_value *atomv, struct ref_formatting_state **state)
{
- struct ref_formatting_state *new = push_new_state(state);
- strbuf_init(&new->output, 0);
- new->attend = align_handler;
+ struct ref_formatting_state *new;
+
+ push_new_state(state);
+ new = *state;
+ new->at_end = align_handler;
new->cb_data = atomv->align;
}
static void end_atom_handler(struct atom_value *atomv, struct ref_formatting_state **state)
{
struct ref_formatting_state *current = *state;
- if (!current->attend)
+ if (!current->at_end)
die(_("format: `end` atom used without a supporting atom"));
- current->attend(current);
+ current->at_end(current);
pop_state(state);
}
@@ -771,11 +774,11 @@ static void populate_value(struct ref_array_item *ref)
if (strtoul_ui(valp, 10, &align->width))
die(_("positive width expected align:%s"), valp);
- if (!ep || starts_with(ep + 1, "left"))
+ if (!ep || !strcmp(ep + 1, "left"))
align->position = ALIGN_LEFT;
- else if (starts_with(ep + 1, "right"))
+ else if (!strcmp(ep + 1, "right"))
align->position = ALIGN_RIGHT;
- else if (starts_with(ep + 1, "middle"))
+ else if (!strcmp(ep + 1, "middle"))
align->position = ALIGN_MIDDLE;
else
die(_("improper format entered align:%s"), ep + 1);
@@ -1305,7 +1308,7 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
/* Simple per-ref filtering */
if (type & FILTER_REFS_INCLUDE_BROKEN) {
- type -= FILTER_REFS_INCLUDE_BROKEN;
+ type &= ~FILTER_REFS_INCLUDE_BROKEN;
broken = 1;
}
@@ -1484,7 +1487,7 @@ void show_ref_array_item(struct ref_array_item *info, const char *format,
struct strbuf *final_buf;
struct ref_formatting_state *state = NULL;
- state = push_new_state(&state);
+ push_new_state(&state);
state->quote_style = quote_style;
for (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {
diff --git a/ref-filter.h b/ref-filter.h
index 72fdf9e..8241066 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -5,7 +5,6 @@
#include "refs.h"
#include "commit.h"
#include "parse-options.h"
-#include "utf8.h"
/* Quoting styles */
#define QUOTE_NONE 0
diff --git a/refs.c b/refs.c
index 0f18c34..a92bba1 100644
--- a/refs.c
+++ b/refs.c
@@ -2147,9 +2147,11 @@ int for_each_replace_ref(each_ref_fn fn, void *cb_data)
int for_each_reftype_fullpath(each_ref_fn fn, char *type, unsigned int broken, void *cb_data)
{
+ unsigned int flag = 0;
+
if (broken)
- broken = DO_FOR_EACH_INCLUDE_BROKEN;
- return do_for_each_ref(&ref_cache, type, fn, 0, broken, cb_data);
+ flag = DO_FOR_EACH_INCLUDE_BROKEN;
+ return do_for_each_ref(&ref_cache, type, fn, 0, flag, cb_data);
}
int head_ref_namespaced(each_ref_fn fn, void *cb_data)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 5b73539..335396e 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1462,7 +1462,7 @@ test_expect_success 'invalid sort parameter on command line' '
test_expect_success 'invalid sort parameter in configuratoin' '
git config tag.sort "v:notvalid" &&
- test_must_fail git tag -l "foo*" >actual
+ test_must_fail git tag -l "foo*"
'
test_expect_success 'version sort with prerelease reordering' '
diff --git a/utf8.c b/utf8.c
index 0fb8e9d..00e10c8 100644
--- a/utf8.c
+++ b/utf8.c
@@ -660,7 +660,7 @@ void strbuf_utf8_align(struct strbuf *buf, align_type position, unsigned int wid
if (position == ALIGN_LEFT)
strbuf_addf(buf, "%-*s", width + utf8_compensation, s);
else if (position == ALIGN_MIDDLE) {
- int left = (width - display_len)/2;
+ int left = (width - display_len) / 2;
strbuf_addf(buf, "%*s%-*s", left, "", width - left + utf8_compensation, s);
} else if (position == ALIGN_RIGHT)
strbuf_addf(buf, "%*s", width + utf8_compensation, s);
--
2.5.0
next reply other threads:[~2015-08-18 18:37 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-18 18:37 Karthik Nayak [this message]
2015-08-18 18:37 ` [PATCH v12 01/13] ref-filter: move `struct atom_value` to ref-filter.c Karthik Nayak
2015-08-19 14:56 ` Matthieu Moy
2015-08-19 15:29 ` Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 02/13] ref-filter: introduce ref_formatting_state Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 03/13] ref-filter: introduce the ref_formatting_state stack machinery Karthik Nayak
2015-08-19 14:56 ` Matthieu Moy
2015-08-19 15:39 ` Karthik Nayak
2015-08-19 15:44 ` Matthieu Moy
2015-08-19 15:54 ` Karthik Nayak
2015-08-19 16:10 ` Karthik Nayak
2015-08-20 7:29 ` Matthieu Moy
2015-08-20 10:29 ` Karthik Nayak
2015-08-20 16:47 ` Junio C Hamano
2015-08-20 17:19 ` Matthieu Moy
2015-08-20 18:29 ` Junio C Hamano
2015-08-19 18:52 ` Junio C Hamano
2015-08-20 10:31 ` Karthik Nayak
2015-08-20 16:51 ` Junio C Hamano
2015-08-18 18:37 ` [PATCH v12 04/13] utf8: add function to align a string into given strbuf Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 05/13] ref-filter: implement an `align` atom Karthik Nayak
2015-08-18 19:28 ` Karthik Nayak
2015-08-20 20:23 ` Eric Sunshine
2015-08-21 1:55 ` Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 06/13] ref-filter: add option to filter out tags, branches and remotes Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 07/13] ref-filter: support printing N lines from tag annotation Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 08/13] ref-filter: add support to sort by version Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 09/13] ref-filter: add option to match literal pattern Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 10/13] tag.c: use 'ref-filter' data structures Karthik Nayak
2015-08-19 14:56 ` Matthieu Moy
2015-08-19 15:51 ` Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 11/13] tag.c: use 'ref-filter' APIs Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 12/13] tag.c: implement '--format' option Karthik Nayak
2015-08-19 14:53 ` Matthieu Moy
2015-08-20 15:50 ` Karthik Nayak
2015-08-18 18:37 ` [PATCH v12 13/13] tag.c: implement '--merged' and '--no-merged' options Karthik Nayak
2015-08-18 19:18 ` [PATCH v12 00/13] port tag.c to use ref-filter.c APIs Eric Sunshine
2015-08-18 19:25 ` Karthik Nayak
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=1439923052-7373-1-git-send-email-Karthik.188@gmail.com \
--to=karthik.188@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=christian.couder@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).