Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 builtin/branch.c       |  4 ++--
 builtin/for-each-ref.c | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 0836890..7d084da 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -416,8 +416,8 @@ static int ref_cmp(const void *r1, const void *r2)
        return strcmp(c1->name, c2->name);
 }
 
-static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
-               int show_upstream_ref)
+void fill_tracking_info(struct strbuf *stat, const char *branch_name,
+                       int show_upstream_ref)
 {
        int ours, theirs;
        char *ref = NULL;
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 498d703..b10d48a 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -76,6 +76,8 @@ static struct {
        { "symref" },
        { "flag" },
        { "current" },
+       { "tracking" },
+       { "tracking:upstream" },
 };
 
 /*
@@ -615,6 +617,8 @@ static inline char *copy_advance(char *dst, const char *src)
        return dst;
 }
 
+extern void fill_tracking_info(struct strbuf *stat, const char *branch_name,
+                              int show_upstream_ref);
 /*
  * Parse the object referred by ref, and grab needed value.
  */
@@ -689,6 +693,20 @@ static void populate_value(struct refinfo *ref)
                                v->s = " ";
                        continue;
                }
+               else if (!strcmp(name, "tracking") &&
+                        !prefixcmp(ref->refname, "refs/heads/")) {
+                       struct strbuf sb = STRBUF_INIT;
+                       fill_tracking_info(&sb, ref->refname + 11, 0);
+                       v->s = sb.buf;
+                       continue;
+               }
+               else if (!strcmp(name, "tracking:upstream") &&
+                        !prefixcmp(ref->refname, "refs/heads/")) {
+                       struct strbuf sb = STRBUF_INIT;
+                       fill_tracking_info(&sb, ref->refname + 11, 1);
+                       v->s = sb.buf;
+                       continue;
+               }
                else
                        continue;
 
-- 
1.8.2.83.gc99314b

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to