From 29bc88505f22068d7ee6694240e6b13fddb5d059 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 21 May 2015 00:45:55 -0400 Subject: for-each-ref: accept "%(push)" format Just as we have "%(upstream)" to report the "@{upstream}" for each ref, this patch adds "%(push)" to match "@{push}". It supports the same tracking format modifiers as upstream (because you may want to know, for example, which branches have commits to push). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/for-each-ref.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 2bd19caa9c..05dd23d2a3 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -74,6 +74,7 @@ static struct { { "contents:body" }, { "contents:signature" }, { "upstream" }, + { "push" }, { "symref" }, { "flag" }, { "HEAD" }, @@ -669,6 +670,16 @@ static void populate_value(struct refinfo *ref) refname = branch_get_upstream(branch, NULL); if (!refname) continue; + } else if (starts_with(name, "push")) { + const char *branch_name; + if (!skip_prefix(ref->refname, "refs/heads/", + &branch_name)) + continue; + branch = branch_get(branch_name); + + refname = branch_get_push(branch, NULL); + if (!refname) + continue; } else if (starts_with(name, "color:")) { char color[COLOR_MAXLEN] = ""; @@ -714,7 +725,8 @@ static void populate_value(struct refinfo *ref) refname = shorten_unambiguous_ref(refname, warn_ambiguous_refs); else if (!strcmp(formatp, "track") && - starts_with(name, "upstream")) { + (starts_with(name, "upstream") || + starts_with(name, "push"))) { char buf[40]; if (stat_tracking_info(branch, &num_ours, @@ -736,7 +748,8 @@ static void populate_value(struct refinfo *ref) } continue; } else if (!strcmp(formatp, "trackshort") && - starts_with(name, "upstream")) { + (starts_with(name, "upstream") || + starts_with(name, "push"))) { assert(branch); if (stat_tracking_info(branch, &num_ours, -- cgit v1.2.3