From mboxrd@z Thu Jan 1 00:00:00 1970 From: Karthik Nayak Subject: [PATCH v3 04/11] for-each-ref: add '--points-at' option Date: Tue, 16 Jun 2015 19:50:50 +0530 Message-ID: <1434464457-10749-4-git-send-email-karthik.188@gmail.com> References: <1434464457-10749-1-git-send-email-karthik.188@gmail.com> Cc: christian.couder@gmail.com, Matthieu.Moy@grenoble-inp.fr, Karthik Nayak To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Jun 16 16:25:14 2015 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z4rnK-00069a-O8 for gcvg-git-2@plane.gmane.org; Tue, 16 Jun 2015 16:24:55 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756221AbbFPOYm (ORCPT ); Tue, 16 Jun 2015 10:24:42 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:35820 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756694AbbFPOYd (ORCPT ); Tue, 16 Jun 2015 10:24:33 -0400 Received: by pacyx8 with SMTP id yx8so13860531pac.2 for ; Tue, 16 Jun 2015 07:24:33 -0700 (PDT) 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=kc9xLvM2DfxvU9YwEfK6K5Ax5mTXiGFeHP8WfWeHa2o=; b=PrVJ4iQRnTqthgkKCGqlXUYg77ywyaFuhJNnDJMr7IB41S0TmGqCdIcvQ/P90BoMaR c3/OGZL1HXNHQvnVda30XM6xEkDuwAkH23HPVO5oQzvJ0JIi5ZHCUgZLnk8ROsTNbjYV iFC9GCRiK2TBj55w+pmXR6eHvGV6EbhrIBWepmkag/i4pp05lmoNy16hjk/gp2CfmIu+ C5nBzpMATZejH2pPC4FjH9JKsD2UIAG3cztXUY10VYs61gK7Bhbp65ySsZNnMzbUlH7C +HqMwqYkpdTVTun6pdTQ9Zq64gkHQYGXSB0s32wge7u3wBY4ws2QTQUgYKRomF/t2Ytc l+9w== X-Received: by 10.66.65.162 with SMTP id y2mr1023495pas.101.1434464673156; Tue, 16 Jun 2015 07:24:33 -0700 (PDT) Received: from ashley.localdomain ([106.51.130.23]) by mx.google.com with ESMTPSA id s1sm1594145pda.54.2015.06.16.07.24.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Jun 2015 07:24:30 -0700 (PDT) X-Mailer: git-send-email 2.4.3.436.g722e2ce.dirty In-Reply-To: <1434464457-10749-1-git-send-email-karthik.188@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Add the '--points-at' option provided by 'ref-filter'. The option lets the user to pick only refs which point to a particular commit. Add documentation and tests for the same. Based-on-patch-by: Jeff King Mentored-by: Christian Couder Mentored-by: Matthieu Moy Signed-off-by: Karthik Nayak --- Documentation/git-for-each-ref.txt | 3 +++ builtin/for-each-ref.c | 9 +++++++-- t/t6301-for-each-ref-filter.sh | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 7f8d9a5..0524ac4 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -10,6 +10,7 @@ SYNOPSIS [verse] 'git for-each-ref' [--count=] [--shell|--perl|--python|--tcl] [(--sort=)...] [--format=] [...] + [--points-at ] DESCRIPTION ----------- @@ -62,6 +63,8 @@ OPTIONS the specified host language. This is meant to produce a scriptlet that can directly be `eval`ed. +--points-at :: + Only list refs of the given object. FIELD NAMES ----------- diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 7919206..2dee149 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -7,6 +7,7 @@ static char const * const for_each_ref_usage[] = { N_("git for-each-ref [] []"), + N_("git for-each-ref [--points-at ]"), NULL }; @@ -34,9 +35,15 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")), OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"), N_("field name to sort on"), &parse_opt_ref_sorting), + OPT_CALLBACK(0, "points-at", &filter.points_at, + N_("object"), N_("print only refs of the object"), + parse_opt_object_name), OPT_END(), }; + memset(&array, 0, sizeof(array)); + memset(&filter, 0, sizeof(filter)); + parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0); if (maxcount < 0) { error("invalid --count argument: `%d'", maxcount); @@ -55,8 +62,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) /* for warn_ambiguous_refs */ git_config(git_default_config, NULL); - memset(&array, 0, sizeof(array)); - memset(&filter, 0, sizeof(filter)); filter.name_patterns = argv; filter_refs(&array, &filter, FILTER_REFS_ALL | FILTER_REFS_INCLUDE_BROKEN); ref_array_sort(sorting, &array); diff --git a/t/t6301-for-each-ref-filter.sh b/t/t6301-for-each-ref-filter.sh index bfcb866..1ad65f0 100755 --- a/t/t6301-for-each-ref-filter.sh +++ b/t/t6301-for-each-ref-filter.sh @@ -33,4 +33,14 @@ test_expect_success 'filtering with fnmatch' ' test_cmp expect actual ' +test_expect_success 'filtering with --points-at' ' + cat >expect <<-\EOF && + refs/heads/master + refs/odd/spot + refs/tags/three + EOF + git for-each-ref --format="%(refname)" --points-at=master >actual && + test_cmp expect actual +' + test_done -- 2.4.3.436.g722e2ce.dirty