diff options
author | Jeff King <peff@peff.net> | 2009-04-07 03:09:39 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-04-07 23:22:15 -0700 |
commit | 8cae19d987b1bbd43258558f591e39d9d216dcb3 (patch) | |
tree | 79e914df66245e75991c066cd3b1c7b59274a88a /builtin-for-each-ref.c | |
parent | 8db9a4b85d6b0d7424c8a19b77a5baa8529ab64c (diff) | |
download | git-8cae19d987b1bbd43258558f591e39d9d216dcb3.tar.gz |
for-each-ref: add "upstream" format field
The logic for determining the upstream ref of a branch is
somewhat complex to perform in a shell script. This patch
provides a plumbing mechanism for scripts to access the C
logic used internally by git-status, git-branch, etc.
For example:
$ git for-each-ref \
--format='%(refname:short) %(upstream:short)' \
refs/heads/
master origin/master
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-for-each-ref.c')
-rw-r--r-- | builtin-for-each-ref.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 653dca9a57..8796352eb6 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -8,6 +8,7 @@ #include "blob.h" #include "quote.h" #include "parse-options.h" +#include "remote.h" /* Quoting styles */ #define QUOTE_NONE 0 @@ -66,6 +67,7 @@ static struct { { "subject" }, { "body" }, { "contents" }, + { "upstream" }, }; /* @@ -682,6 +684,18 @@ static void populate_value(struct refinfo *ref) if (!prefixcmp(name, "refname")) refname = ref->refname; + else if(!prefixcmp(name, "upstream")) { + struct branch *branch; + /* only local branches may have an upstream */ + if (prefixcmp(ref->refname, "refs/heads/")) + continue; + branch = branch_get(ref->refname + 11); + + if (!branch || !branch->merge || !branch->merge[0] || + !branch->merge[0]->dst) + continue; + refname = branch->merge[0]->dst; + } else continue; |