From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-6.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 0181320259 for ; Wed, 7 Dec 2016 15:37:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753466AbcLGPhE (ORCPT ); Wed, 7 Dec 2016 10:37:04 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:32913 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752934AbcLGPgv (ORCPT ); Wed, 7 Dec 2016 10:36:51 -0500 Received: by mail-pg0-f65.google.com with SMTP id 3so23838328pgd.0 for ; Wed, 07 Dec 2016 07:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XSlrj1950UunUYCScxi3uExEdng5pJqfCr08C/IlZK0=; b=D9h4xfmKebOsbHaZqtheCSf7x6//ChCc1y/nvMmnSoRlWzEnWplahueIaENzphVm7K 1zdeagnO5JZiZOVOCKSCBHsFZffJu+KUsKV7xptHW+nfl2frO4U3yClEk7rnr+UhJFH+ w+rW2qLJ9OqN+AH2DxAyqfBjvlZP2zhHZZGboXhHO7jBw1jmZ8+wrtXDH75YEUWwdFh0 Vqj6VLXsnJ9wsaoScYsaMaVHRXsi7ufewo8UGfCzv7QNbXEZDEY/YSaNvoRgWcxg2ujg ubEOTbUyBj3k9F2hrsqqZmzeAnTfHOriVBV5eWe7G2BM2c4zJOR7r8B9GmOFX2iV20/+ L0fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XSlrj1950UunUYCScxi3uExEdng5pJqfCr08C/IlZK0=; b=X0T7zjQpfi6D/SLZ5TMG5XO40k6JWGKW43lwvRMePCHCFGjMyw90uOqQW0bHID2d/p 9Nd18o7AI+cGdj0AJ79NtI4zGmVkIMRVNBLLlnI+IwVOeeN+ueA3bBBwReMkJXL7qoT4 VDXAkDsryRObBgrcQTaUbdL3e1chsi3tqGwy4gQPwHoNhJipyVKLy0LtHEy861mqr5DF 0e5uPjkHJj0WVDfnZ5dDYzvhuMiuRTwkYtcP6K85UOkXbnv2I6GmYXdv8uHx72PT+0je 8JMx9fNqSDVL2PjO/XOf+Wbsjoy0Ec0cyJ1wKRPoDQJpVq5u+DuKjj3PwN3cdrrJkRGZ Ds7A== X-Gm-Message-State: AKaTC03PhbIiiohk7ZGC5jlWHtggf2lsaap9oKqyMPDF6eDbaAfE9G261ANO2KFitS36CA== X-Received: by 10.84.209.140 with SMTP id y12mr146144371plh.74.1481124985703; Wed, 07 Dec 2016 07:36:25 -0800 (PST) Received: from AamlaJuice.corp.endurance.com ([122.15.255.69]) by smtp.gmail.com with ESMTPSA id l7sm43584459pfg.35.2016.12.07.07.36.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 07:36:25 -0800 (PST) From: Karthik Nayak X-Google-Original-From: Karthik Nayak To: git@vger.kernel.org Cc: jacob.keller@gmail.com, gitster@pobox.com, jnareb@gmail.com, Karthik Nayak Subject: [PATCH v8 08/19] ref-filter: add support for %(upstream:track,nobracket) Date: Wed, 7 Dec 2016 21:06:16 +0530 Message-Id: <20161207153627.1468-9-Karthik.188@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161207153627.1468-1-Karthik.188@gmail.com> References: <20161207153627.1468-1-Karthik.188@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Karthik Nayak Add support for %(upstream:track,nobracket) which will print the tracking information without the brackets (i.e. "ahead N, behind M"). This is needed when we port branch.c to use ref-filter's printing APIs. Add test and documentation for the same. Mentored-by: Christian Couder Mentored-by: Matthieu Moy Signed-off-by: Karthik Nayak --- Documentation/git-for-each-ref.txt | 10 ++++-- ref-filter.c | 67 +++++++++++++++++++++++++------------- t/t6300-for-each-ref.sh | 2 ++ 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 536846f..e1d250e 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -117,9 +117,13 @@ upstream:: `refname` above. Additionally respects `:track` to show "[ahead N, behind M]" and `:trackshort` to show the terse version: ">" (ahead), "<" (behind), "<>" (ahead and behind), - or "=" (in sync). Has no effect if the ref does not have - tracking information associated with it. `:track` also prints - "[gone]" whenever unknown upstream ref is encountered. + or "=" (in sync). `:track` also prints "[gone]" whenever + unknown upstream ref is encountered. Append `:track,nobracket` + to show tracking information without brackets (i.e "ahead N, + behind M"). Has no effect if the ref does not have tracking + information associated with it. All the options apart from + `nobracket` are mutually exclusive, but if used together the + last option is selected. push:: The name of a local ref which represents the `@{push}` location diff --git a/ref-filter.c b/ref-filter.c index e0229d3..49bb120 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -47,8 +47,10 @@ static struct used_atom { union { char color[COLOR_MAXLEN]; struct align align; - enum { RR_NORMAL, RR_SHORTEN, RR_TRACK, RR_TRACKSHORT } - remote_ref; + struct { + enum { RR_NORMAL, RR_SHORTEN, RR_TRACK, RR_TRACKSHORT } option; + unsigned int nobracket: 1; + } remote_ref; struct { enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, C_SUB } option; unsigned int nlines; @@ -76,16 +78,33 @@ static void color_atom_parser(struct used_atom *atom, const char *color_value) static void remote_ref_atom_parser(struct used_atom *atom, const char *arg) { - if (!arg) - atom->u.remote_ref = RR_NORMAL; - else if (!strcmp(arg, "short")) - atom->u.remote_ref = RR_SHORTEN; - else if (!strcmp(arg, "track")) - atom->u.remote_ref = RR_TRACK; - else if (!strcmp(arg, "trackshort")) - atom->u.remote_ref = RR_TRACKSHORT; - else - die(_("unrecognized format: %%(%s)"), atom->name); + struct string_list params = STRING_LIST_INIT_DUP; + int i; + + if (!arg) { + atom->u.remote_ref.option = RR_NORMAL; + return; + } + + atom->u.remote_ref.nobracket = 0; + string_list_split(¶ms, arg, ',', -1); + + for (i = 0; i < params.nr; i++) { + const char *s = params.items[i].string; + + if (!strcmp(s, "short")) + atom->u.remote_ref.option = RR_SHORTEN; + else if (!strcmp(s, "track")) + atom->u.remote_ref.option = RR_TRACK; + else if (!strcmp(s, "trackshort")) + atom->u.remote_ref.option = RR_TRACKSHORT; + else if (!strcmp(s, "nobracket")) + atom->u.remote_ref.nobracket = 1; + else + die(_("unrecognized format: %%(%s)"), atom->name); + } + + string_list_clear(¶ms, 0); } static void body_atom_parser(struct used_atom *atom, const char *arg) @@ -1049,25 +1068,27 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname, struct branch *branch, const char **s) { int num_ours, num_theirs; - if (atom->u.remote_ref == RR_SHORTEN) + if (atom->u.remote_ref.option == RR_SHORTEN) *s = shorten_unambiguous_ref(refname, warn_ambiguous_refs); - else if (atom->u.remote_ref == RR_TRACK) { + else if (atom->u.remote_ref.option == RR_TRACK) { if (stat_tracking_info(branch, &num_ours, &num_theirs, NULL)) { - *s = "[gone]"; - return; - } - - if (!num_ours && !num_theirs) + *s = xstrdup("gone"); + } else if (!num_ours && !num_theirs) *s = ""; else if (!num_ours) - *s = xstrfmt("[behind %d]", num_theirs); + *s = xstrfmt("behind %d", num_theirs); else if (!num_theirs) - *s = xstrfmt("[ahead %d]", num_ours); + *s = xstrfmt("ahead %d", num_ours); else - *s = xstrfmt("[ahead %d, behind %d]", + *s = xstrfmt("ahead %d, behind %d", num_ours, num_theirs); - } else if (atom->u.remote_ref == RR_TRACKSHORT) { + if (!atom->u.remote_ref.nobracket && *s[0]) { + const char *to_free = *s; + *s = xstrfmt("[%s]", *s); + free((void *)to_free); + } + } else if (atom->u.remote_ref.option == RR_TRACKSHORT) { if (stat_tracking_info(branch, &num_ours, &num_theirs, NULL)) return; diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 5019f40..ed36a0a 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -372,6 +372,8 @@ test_expect_success 'setup for upstream:track[short]' ' test_atom head upstream:track '[ahead 1]' test_atom head upstream:trackshort '>' +test_atom head upstream:track,nobracket 'ahead 1' +test_atom head upstream:nobracket,track 'ahead 1' test_atom head push:track '[ahead 1]' test_atom head push:trackshort '>' -- 2.10.2