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>
Karthik Nayak committed
Jan 10, 2017 at 14:19 UTC
3ba308cb4b4ad0d06fa834a42a9380c877b0c16a
3 files changed
+33
-26
Documentation/git-for-each-ref.txt
+16
-15
@@ -116,23 +116,24 @@ objectname::
116
117
upstream::
118
The name of a local ref which can be considered ``upstream''
119
- from the displayed ref. Respects `:short` in the same way as
120
- `refname` above. Additionally respects `:track` to show
121
- "[ahead N, behind M]" and `:trackshort` to show the terse
122
- version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
123
- or "=" (in sync). `:track` also prints "[gone]" whenever
124
- unknown upstream ref is encountered. Append `:track,nobracket`
125
- to show tracking information without brackets (i.e "ahead N,
126
- behind M"). Has no effect if the ref does not have tracking
127
- information associated with it. All the options apart from
128
- `nobracket` are mutually exclusive, but if used together the
129
- last option is selected.
119
+ from the displayed ref. Respects `:short` and `:strip` in the
120
+ same way as `refname` above. Additionally respects `:track`
121
+ to show "[ahead N, behind M]" and `:trackshort` to show the
122
+ terse version: ">" (ahead), "<" (behind), "<>" (ahead and
123
+ behind), or "=" (in sync). `:track` also prints "[gone]"
124
+ whenever unknown upstream ref is encountered. Append
125
+ `:track,nobracket` to show tracking information without
126
+ brackets (i.e "ahead N, behind M"). Has no effect if the ref
127
+ does not have tracking information associated with it. All
128
+ the options apart from `nobracket` are mutually exclusive, but
129
+ if used together the last option is selected.
130
131
push::
132
- The name of a local ref which represents the `@{push}` location
133
- for the displayed ref. Respects `:short`, `:track`, and
134
- `:trackshort` options as `upstream` does. Produces an empty
135
- string if no `@{push}` ref is configured.
132
+ The name of a local ref which represents the `@{push}`
133
+ location for the displayed ref. Respects `:short`, `:strip`,
134
+ `:track`, and `:trackshort` options as `upstream`
135
+ does. Produces an empty string if no `@{push}` ref is
136
+ configured.
137
138
HEAD::
139
'*' if HEAD matches current ref (the checked out branch), ' '
ref-filter.c
+15
-11
@@ -54,7 +54,8 @@ static struct used_atom {
54
char color[COLOR_MAXLEN];
55
struct align align;
56
struct {
57
- enum { RR_NORMAL, RR_SHORTEN, RR_TRACK, RR_TRACKSHORT } option;
57
+ enum { RR_REF, RR_TRACK, RR_TRACKSHORT } option;
58
+ struct refname_atom refname;
59
unsigned int nobracket : 1;
60
} remote_ref;
61
struct {
@@ -104,7 +105,9 @@ static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
105
int i;
106
107
if (!arg) {
107
- atom->u.remote_ref.option = RR_NORMAL;
108
+ atom->u.remote_ref.option = RR_REF;
109
+ refname_atom_parser_internal(&atom->u.remote_ref.refname,
110
+ arg, atom->name);
111
return;
112
}
113
@@ -114,16 +117,17 @@ static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
117
for (i = 0; i < params.nr; i++) {
118
const char *s = params.items[i].string;
119
117
- if (!strcmp(s, "short"))
118
- atom->u.remote_ref.option = RR_SHORTEN;
119
- else if (!strcmp(s, "track"))
120
+ if (!strcmp(s, "track"))
121
atom->u.remote_ref.option = RR_TRACK;
122
else if (!strcmp(s, "trackshort"))
123
atom->u.remote_ref.option = RR_TRACKSHORT;
124
else if (!strcmp(s, "nobracket"))
125
atom->u.remote_ref.nobracket = 1;
125
- else
126
- die(_("unrecognized format: %%(%s)"), atom->name);
126
+ else {
127
+ atom->u.remote_ref.option = RR_REF;
128
+ refname_atom_parser_internal(&atom->u.remote_ref.refname,
129
+ arg, atom->name);
130
+ }
131
}
132
133
string_list_clear(¶ms, 0);
@@ -1119,8 +1123,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
1123
struct branch *branch, const char **s)
1124
{
1125
int num_ours, num_theirs;
1122
- if (atom->u.remote_ref.option == RR_SHORTEN)
1123
- *s = shorten_unambiguous_ref(refname, warn_ambiguous_refs);
1126
+ if (atom->u.remote_ref.option == RR_REF)
1127
+ *s = show_ref(&atom->u.remote_ref.refname, refname);
1128
else if (atom->u.remote_ref.option == RR_TRACK) {
1129
if (stat_tracking_info(branch, &num_ours,
1130
&num_theirs, NULL)) {
@@ -1152,8 +1156,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
1156
*s = ">";
1157
else
1158
*s = "<>";
1155
- } else /* RR_NORMAL */
1156
- *s = refname;
1159
+ } else
1160
+ die("BUG: unhandled RR_* enum");
1161
}
1162
1163
char *get_head_description(void)
t/t6300-for-each-ref.sh
+2
@@ -55,8 +55,10 @@ test_atom head refname:strip=1 heads/master
55
test_atom head refname:strip=2 master
56
test_atom head upstream refs/remotes/origin/master
57
test_atom head upstream:short origin/master
58
+test_atom head upstream:strip=2 origin/master
59
test_atom head push refs/remotes/myfork/master
60
test_atom head push:short myfork/master
61
+test_atom head push:strip=1 remotes/myfork/master
62
test_atom head objecttype commit
63
test_atom head objectsize 171
64
test_atom head objectname $(git rev-parse refs/heads/master)