Browse Source

ref-filter: make remote_ref_atom_parser() use refname_atom_parser_internal()

Use the recently introduced refname_atom_parser_internal() within
remote_ref_atom_parser(), this provides a common base for all the ref
printing atoms, allowing %(upstream) and %(push) to also use the
':strip' option.

The atoms '%(push)' and '%(upstream)' will retain the ':track' and
':trackshort' atom modifiers to themselves as they have no meaning in
context to the '%(refname)' and '%(symref)' atoms.

Update the documentation and tests to reflect the same.

Signed-off-by: Karthik Nayak <Karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Karthik Nayak 8 years ago committed by Junio C Hamano
parent
commit
3ba308cb4b
  1. 31
      Documentation/git-for-each-ref.txt
  2. 26
      ref-filter.c
  3. 2
      t/t6300-for-each-ref.sh

31
Documentation/git-for-each-ref.txt

@ -116,23 +116,24 @@ objectname::


upstream:: upstream::
The name of a local ref which can be considered ``upstream'' The name of a local ref which can be considered ``upstream''
from the displayed ref. Respects `:short` in the same way as from the displayed ref. Respects `:short` and `:strip` in the
`refname` above. Additionally respects `:track` to show same way as `refname` above. Additionally respects `:track`
"[ahead N, behind M]" and `:trackshort` to show the terse to show "[ahead N, behind M]" and `:trackshort` to show the
version: ">" (ahead), "<" (behind), "<>" (ahead and behind), terse version: ">" (ahead), "<" (behind), "<>" (ahead and
or "=" (in sync). `:track` also prints "[gone]" whenever behind), or "=" (in sync). `:track` also prints "[gone]"
unknown upstream ref is encountered. Append `:track,nobracket` whenever unknown upstream ref is encountered. Append
to show tracking information without brackets (i.e "ahead N, `:track,nobracket` to show tracking information without
behind M"). Has no effect if the ref does not have tracking brackets (i.e "ahead N, behind M"). Has no effect if the ref
information associated with it. All the options apart from does not have tracking information associated with it. All
`nobracket` are mutually exclusive, but if used together the the options apart from `nobracket` are mutually exclusive, but
last option is selected. if used together the last option is selected.


push:: push::
The name of a local ref which represents the `@{push}` location The name of a local ref which represents the `@{push}`
for the displayed ref. Respects `:short`, `:track`, and location for the displayed ref. Respects `:short`, `:strip`,
`:trackshort` options as `upstream` does. Produces an empty `:track`, and `:trackshort` options as `upstream`
string if no `@{push}` ref is configured. does. Produces an empty string if no `@{push}` ref is
configured.


HEAD:: HEAD::
'*' if HEAD matches current ref (the checked out branch), ' ' '*' if HEAD matches current ref (the checked out branch), ' '

26
ref-filter.c

@ -54,7 +54,8 @@ static struct used_atom {
char color[COLOR_MAXLEN]; char color[COLOR_MAXLEN];
struct align align; struct align align;
struct { struct {
enum { RR_NORMAL, RR_SHORTEN, RR_TRACK, RR_TRACKSHORT } option; enum { RR_REF, RR_TRACK, RR_TRACKSHORT } option;
struct refname_atom refname;
unsigned int nobracket : 1; unsigned int nobracket : 1;
} remote_ref; } remote_ref;
struct { struct {
@ -104,7 +105,9 @@ static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
int i; int i;


if (!arg) { if (!arg) {
atom->u.remote_ref.option = RR_NORMAL; atom->u.remote_ref.option = RR_REF;
refname_atom_parser_internal(&atom->u.remote_ref.refname,
arg, atom->name);
return; return;
} }


@ -114,16 +117,17 @@ static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
for (i = 0; i < params.nr; i++) { for (i = 0; i < params.nr; i++) {
const char *s = params.items[i].string; const char *s = params.items[i].string;


if (!strcmp(s, "short")) if (!strcmp(s, "track"))
atom->u.remote_ref.option = RR_SHORTEN;
else if (!strcmp(s, "track"))
atom->u.remote_ref.option = RR_TRACK; atom->u.remote_ref.option = RR_TRACK;
else if (!strcmp(s, "trackshort")) else if (!strcmp(s, "trackshort"))
atom->u.remote_ref.option = RR_TRACKSHORT; atom->u.remote_ref.option = RR_TRACKSHORT;
else if (!strcmp(s, "nobracket")) else if (!strcmp(s, "nobracket"))
atom->u.remote_ref.nobracket = 1; atom->u.remote_ref.nobracket = 1;
else else {
die(_("unrecognized format: %%(%s)"), atom->name); atom->u.remote_ref.option = RR_REF;
refname_atom_parser_internal(&atom->u.remote_ref.refname,
arg, atom->name);
}
} }


string_list_clear(&params, 0); string_list_clear(&params, 0);
@ -1119,8 +1123,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
struct branch *branch, const char **s) struct branch *branch, const char **s)
{ {
int num_ours, num_theirs; int num_ours, num_theirs;
if (atom->u.remote_ref.option == RR_SHORTEN) if (atom->u.remote_ref.option == RR_REF)
*s = shorten_unambiguous_ref(refname, warn_ambiguous_refs); *s = show_ref(&atom->u.remote_ref.refname, refname);
else if (atom->u.remote_ref.option == RR_TRACK) { else if (atom->u.remote_ref.option == RR_TRACK) {
if (stat_tracking_info(branch, &num_ours, if (stat_tracking_info(branch, &num_ours,
&num_theirs, NULL)) { &num_theirs, NULL)) {
@ -1152,8 +1156,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
*s = ">"; *s = ">";
else else
*s = "<>"; *s = "<>";
} else /* RR_NORMAL */ } else
*s = refname; die("BUG: unhandled RR_* enum");
} }


char *get_head_description(void) char *get_head_description(void)

2
t/t6300-for-each-ref.sh

@ -55,8 +55,10 @@ test_atom head refname:strip=1 heads/master
test_atom head refname:strip=2 master test_atom head refname:strip=2 master
test_atom head upstream refs/remotes/origin/master test_atom head upstream refs/remotes/origin/master
test_atom head upstream:short origin/master test_atom head upstream:short origin/master
test_atom head upstream:strip=2 origin/master
test_atom head push refs/remotes/myfork/master test_atom head push refs/remotes/myfork/master
test_atom head push:short myfork/master test_atom head push:short myfork/master
test_atom head push:strip=1 remotes/myfork/master
test_atom head objecttype commit test_atom head objecttype commit
test_atom head objectsize 171 test_atom head objectsize 171
test_atom head objectname $(git rev-parse refs/heads/master) test_atom head objectname $(git rev-parse refs/heads/master)

Loading…
Cancel
Save