git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, jacob.keller@gmail.com,
	Karthik Nayak <Karthik.188@gmail.com>
Subject: [PATCH v2 00/16] port branch.c to use ref-filter's printing options
Date: Tue, 15 Mar 2016 22:17:00 +0530	[thread overview]
Message-ID: <1458060436-1215-1-git-send-email-Karthik.188@gmail.com> (raw)

This is part of unification of the commands 'git tag -l, git branch -l
and git for-each-ref'. This ports over branch.c to use ref-filter's
printing options.

Initially posted here: $(gmane/279226). It was decided that this series
would follow up after refactoring ref-filter parsing mechanism, which
is now merged into master (9606218b32344c5c756f7c29349d3845ef60b80c).

v1 can be found here: $(gmane/288342)

Changes in this version:

1. Implement parser atoms for %(if:equals=...) and %(if:notequals=...)
2. Include a pointer to the corresponding used_atom within atom_value.
3. add missing documentation for %(upstream:track).
4. Fix commit message.

Thanks to Jacob and Junio for their suggestions on the first iteration.

Karthik Nayak (16):
  ref-filter: implement %(if), %(then), and %(else) atoms
  ref-filter: include reference to 'used_atom' within 'atom_value'
  ref-filter: implement %(if:equals=<string>) and
    %(if:notequals=<string>)
  ref-filter: modify "%(objectname:short)" to take length
  ref-filter: move get_head_description() from branch.c
  ref-filter: introduce format_ref_array_item()
  ref-filter: make %(upstream:track) prints "[gone]" for invalid
    upstreams
  ref-filter: add support for %(upstream:track,nobracket)
  ref-filter: make "%(symref)" atom work with the ':short' modifier
  ref-filter: introduce symref_atom_parser()
  ref-filter: introduce refname_atom_parser()
  ref-filter: add support for %(refname:dir) and %(refname:base)
  ref-filter: allow porcelain to translate messages in the output
  branch, tag: use porcelain output
  branch: use ref-filter printing APIs
  branch: implement '--format' option

 Documentation/git-branch.txt       |   7 +-
 Documentation/git-for-each-ref.txt |  58 ++++-
 builtin/branch.c                   | 267 ++++++----------------
 builtin/tag.c                      |   2 +
 ref-filter.c                       | 447 +++++++++++++++++++++++++++++++------
 ref-filter.h                       |   7 +
 t/t3203-branch-output.sh           |  12 +
 t/t6040-tracking-info.sh           |   2 +-
 t/t6300-for-each-ref.sh            |  40 +++-
 t/t6302-for-each-ref-filter.sh     |  88 ++++++++
 10 files changed, 653 insertions(+), 277 deletions(-)

Interdiff:

diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 193e99e..578bbd1 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -116,10 +116,12 @@ upstream::
 	`refname` above.  Additionally respects `:track` to show
 	"[ahead N, behind M]" and `:trackshort` to show the terse
 	version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
-	or "=" (in sync).  Append `:track,nobracket` to show tracking
-	information without brackets (i.e "ahead N, behind M").  Has
-	no effect if the ref does not have tracking information
-	associated with it.
+	or "=" (in sync).  Has no effect if the ref does not have
+	tracking information associated with it. `:track` also prints
+	"[gone]" whenever unknown upstream ref is encountered. Append
+	`:track,nobracket` to show tracking information without
+	brackets (i.e "ahead N, behind M").  Has no effect if the ref
+	does not have tracking information associated with it.
 
 push::
 	The name of a local ref which represents the `@{push}` location
diff --git a/ref-filter.c b/ref-filter.c
index 76ea7c3..3435df1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -75,6 +75,10 @@ static struct used_atom {
 			unsigned int nlines;
 		} contents;
 		struct {
+			const char *if_equals,
+				*not_equals;
+		} if_then_else;
+		struct {
 			enum { O_FULL, O_LENGTH, O_SHORT } option;
 			unsigned int length;
 		} objectname;
@@ -226,6 +230,18 @@ static void align_atom_parser(struct used_atom *atom, const char *arg)
 	string_list_clear(&params, 0);
 }
 
+static void if_atom_parser(struct used_atom *atom, const char *arg)
+{
+	if (!arg)
+		return;
+	else if (skip_prefix(arg, "equals=", &atom->u.if_then_else.if_equals))
+		 ;
+	else if (skip_prefix(arg, "notequals=", &atom->u.if_then_else.not_equals))
+		;
+	else
+		die(_("unrecognized %%(if) argument: %s"), arg);
+}
+
 static void symref_atom_parser(struct used_atom *atom, const char *arg)
 {
 	if (!arg)
@@ -295,7 +311,7 @@ static struct {
 	{ "color", FIELD_STR, color_atom_parser },
 	{ "align", FIELD_STR, align_atom_parser },
 	{ "end" },
-	{ "if" },
+	{ "if", FIELD_STR, if_atom_parser },
 	{ "then" },
 	{ "else" },
 };
@@ -316,11 +332,9 @@ struct ref_formatting_state {
 
 struct atom_value {
 	const char *s;
-	union {
-		struct align align;
-	} u;
 	void (*handler)(struct atom_value *atomv, struct ref_formatting_state *state);
 	unsigned long ul; /* used for sorting when not FIELD_STR */
+	struct used_atom *atom;
 };
 
 /*
@@ -377,7 +391,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
 		valid_atom[i].parser(&used_atom[at], arg);
 	if (*atom == '*')
 		need_tagged = 1;
-	if (starts_with(used_atom[at].name, "symref"))
+	if (!strcmp(valid_atom[i].name, "symref"))
 		need_symref = 1;
 	return at;
 }
@@ -456,7 +470,7 @@ static void align_atom_handler(struct atom_value *atomv, struct ref_formatting_s
 	push_stack_element(&state->stack);
 	new = state->stack;
 	new->at_end = end_align_handler;
-	new->at_end_data = &atomv->u.align;
+	new->at_end_data = &atomv->atom->u.align;
 }
 
 static void if_then_else_handler(struct ref_formatting_stack **stack)
@@ -497,14 +511,9 @@ static void if_atom_handler(struct atom_value *atomv, struct ref_formatting_stat
 {
 	struct ref_formatting_stack *new;
 	struct if_then_else *if_then_else = xcalloc(sizeof(struct if_then_else), 1);
-	const char *valp;
 
-	if (skip_prefix(atomv->s, "equals=", &valp))
-		if_then_else->if_equals = valp;
-	else if (skip_prefix(atomv->s, "notequals=", &valp))
-		if_then_else->not_equals = valp;
-	else if (atomv->s[0])
-		die(_("format: unknown format if:%s"), atomv->s);
+	if_then_else->if_equals = atomv->atom->u.if_then_else.if_equals;
+	if_then_else->not_equals = atomv->atom->u.if_then_else.not_equals;
 
 	push_stack_element(&state->stack);
 	new = state->stack;
@@ -1243,6 +1252,7 @@ static void populate_value(struct ref_array_item *ref)
 		struct branch *branch = NULL;
 
 		v->handler = append_atom;
+		v->atom = atom;
 
 		if (*name == '*') {
 			deref = 1;
@@ -1307,7 +1317,6 @@ static void populate_value(struct ref_array_item *ref)
 				v->s = " ";
 			continue;
 		} else if (starts_with(name, "align")) {
-			v->u.align = atom->u.align;
 			v->handler = align_atom_handler;
 			continue;
 		} else if (!strcmp(name, "end")) {


-- 
2.7.3

             reply	other threads:[~2016-03-15 16:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 16:47 Karthik Nayak [this message]
2016-03-15 16:47 ` [PATCH v2 01/16] ref-filter: implement %(if), %(then), and %(else) atoms Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 02/16] ref-filter: include reference to 'used_atom' within 'atom_value' Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 03/16] ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>) Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 04/16] ref-filter: modify "%(objectname:short)" to take length Karthik Nayak
2016-03-15 22:11   ` Jacob Keller
2016-03-18 18:38     ` Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 05/16] ref-filter: move get_head_description() from branch.c Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 06/16] ref-filter: introduce format_ref_array_item() Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 07/16] ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreams Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 08/16] ref-filter: add support for %(upstream:track,nobracket) Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 09/16] ref-filter: make "%(symref)" atom work with the ':short' modifier Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 10/16] ref-filter: introduce symref_atom_parser() Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 11/16] ref-filter: introduce refname_atom_parser() Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 12/16] ref-filter: add support for %(refname:dir) and %(refname:base) Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 13/16] ref-filter: allow porcelain to translate messages in the output Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 14/16] branch, tag: use porcelain output Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 15/16] branch: use ref-filter printing APIs Karthik Nayak
2016-03-15 16:47 ` [PATCH v2 16/16] branch: implement '--format' option Karthik Nayak
2016-03-15 22:00 ` [PATCH v2 00/16] port branch.c to use ref-filter's printing options Jacob Keller
2016-03-18 18:43   ` 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=1458060436-1215-1-git-send-email-Karthik.188@gmail.com \
    --to=karthik.188@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.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).