From mboxrd@z Thu Jan 1 00:00:00 1970 From: Karthik Nayak Subject: [PATCH v5 03/11] ref-filter: implement '--points-at' option Date: Thu, 25 Jun 2015 01:23:44 +0530 Message-ID: <1435175632-27803-3-git-send-email-karthik.188@gmail.com> References: <1435175632-27803-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 Wed Jun 24 21:54:18 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 1Z7qkT-0007pI-G2 for gcvg-git-2@plane.gmane.org; Wed, 24 Jun 2015 21:54:17 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753448AbbFXTyL (ORCPT ); Wed, 24 Jun 2015 15:54:11 -0400 Received: from mail-pd0-f178.google.com ([209.85.192.178]:36001 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753083AbbFXTyH (ORCPT ); Wed, 24 Jun 2015 15:54:07 -0400 Received: by pdcu2 with SMTP id u2so37116093pdc.3 for ; Wed, 24 Jun 2015 12:54:07 -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=44BRFK6m+KQ5R5wE64TEjbK24v/lgnWqmDzyHgwcPlE=; b=qM8uXWLf131T7B9DpJYtsW4QiTMR1rSAeICjzGMGBAgTKi3I7kvfxpyA9+iwXLbK4w ody3A+Ru7u5Si4FRdCcmTG0UcgzuULinQyWpQe/gfQiKNrKrHnDIP6hjIXnM2+0xudr5 s4Y29l5v1Odyp6mvbXjNlYCszLXsNLj7FLvYflVbQM2kts2V1+RQZY+26f2O3OxWNwfU 4Dn/UU/Sk0IdK1AXrYKw3zw+PF2rratBfHSU02E0eqMaRN79krZVHvow0KQEV61G1eSA 0Jw83ZfAM4VFA7uO2M2RZW5gms2viOQbPBocHd1UJpgnAAMPUhFSM6SjtX9FFDWWUU6R 6gpw== X-Received: by 10.66.255.67 with SMTP id ao3mr11506866pad.60.1435175646970; Wed, 24 Jun 2015 12:54:06 -0700 (PDT) Received: from ashley.localdomain ([106.51.130.23]) by mx.google.com with ESMTPSA id zx1sm27583483pbb.73.2015.06.24.12.54.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Jun 2015 12:54:06 -0700 (PDT) X-Mailer: git-send-email 2.4.4 In-Reply-To: <1435175632-27803-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: In 'tag -l' we have '--points-at' option which lets users list only tags which point to a particular commit. Implement this option in 'ref-filter.{c,h}' so that other commands can benefit from this. This is duplicated from tag.c, we will eventually remove that when we port tag.c to use ref-filter APIs. Based-on-patch-by: Jeff King Mentored-by: Christian Couder Mentored-by: Matthieu Moy Signed-off-by: Karthik Nayak --- builtin/tag.c | 4 ++++ ref-filter.c | 26 ++++++++++++++++++++++++++ ref-filter.h | 1 + 3 files changed, 31 insertions(+) diff --git a/builtin/tag.c b/builtin/tag.c index e36c43e..280981f 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -56,6 +56,10 @@ static int match_pattern(const char **patterns, const char *ref) return 0; } +/* + * This is currently duplicated in ref-filter.c, and will eventually be + * removed as we port tag.c to use the ref-filter APIs. + */ static const unsigned char *match_points_at(const char *refname, const unsigned char *sha1) { diff --git a/ref-filter.c b/ref-filter.c index 43502a4..f40f06e 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -842,6 +842,29 @@ static int match_name_as_path(const char **pattern, const char *refname) return 0; } +/* + * Given a ref (sha1, refname) see if it points to one of the sha1s + * in a sha1_array. + */ +static int match_points_at(struct sha1_array *points_at, const unsigned char *sha1, + const char *refname) +{ + struct object *obj; + + if (!points_at || !points_at->nr) + return 1; + + if (sha1_array_lookup(points_at, sha1) >= 0) + return 1; + + obj = parse_object_or_die(sha1, refname); + if (obj->type == OBJ_TAG && + sha1_array_lookup(points_at, ((struct tag *)obj)->tagged->sha1) >= 0) + return 1; + + return 0; +} + /* Allocate space for a new ref_array_item and copy the objectname and flag to it */ static struct ref_array_item *new_ref_array_item(const char *refname, const unsigned char *objectname, @@ -875,6 +898,9 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid, if (*filter->name_patterns && !match_name_as_path(filter->name_patterns, refname)) return 0; + if (!match_points_at(&filter->points_at, oid->hash, refname)) + return 0; + /* * We do not open the object yet; sort may only need refname * to do its job and the resulting list may yet to be pruned diff --git a/ref-filter.h b/ref-filter.h index 6997984..c2856b8 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -42,6 +42,7 @@ struct ref_array { struct ref_filter { const char **name_patterns; + struct sha1_array points_at; }; struct ref_filter_cbdata { -- 2.4.4