From patchwork Mon Nov 12 13:25:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rafael_Ascens=C3=A3o?= X-Patchwork-Id: 10678633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 242B313B5 for ; Mon, 12 Nov 2018 13:26:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12CB829E61 for ; Mon, 12 Nov 2018 13:26:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06AF229EC5; Mon, 12 Nov 2018 13:26:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CA6229E61 for ; Mon, 12 Nov 2018 13:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729665AbeKLXUA (ORCPT ); Mon, 12 Nov 2018 18:20:00 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39753 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729540AbeKLXUA (ORCPT ); Mon, 12 Nov 2018 18:20:00 -0500 Received: by mail-wm1-f68.google.com with SMTP id u13-v6so8133824wmc.4 for ; Mon, 12 Nov 2018 05:26:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=puP2AsLjKfO1dcYGA/lYiG6mn1gq2I/toP1Cr6t+PcU=; b=EIExVwHIgYS5WDDcHIPXZxlQ1vIzlgb9RixLmhX4KAmrR6J+6p3L3KFqKB5PD5JXim TK/6HU3Mk5tDa6RKOV46AuLl7nF00Hf1cWYOSEFj7Yle0DtRJo70rTDGjrh7gHrGebXJ juI/98OLqxAJ4yFMK39Q/inTWjVie3WP7n7zwnoze7pNk62kQuAYaaDe7g47cpPDwPV/ cJrmJuGu7ojBzytUcnNvdrTG4+jKisxfSHSIKydL0bPbLQo1cLDA5mtz846yZQe33l0j PGrUKvRYuiHlNVmvUJsaTpVe8G+gNTGspjhDf5CGOYfgnyFMFXcq5GDRUnlC/NejQSaM ETxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=puP2AsLjKfO1dcYGA/lYiG6mn1gq2I/toP1Cr6t+PcU=; b=n6yolFZo/DfzyR6DqJlj5KxJcEKx8tzmc6tlS60rvr+Zgev7XxPqaJzaU+d6NdZNyQ mbyOGHQyft8MrXMLFPYTPqEgQrQo4J5p3MGCofxf/fuwqC8XD/RnYZrODDrcMTS7uaE+ oGO/VV3jm+RKaOA2paICyUwBNqkx8KJymsrQR0CnhDJ7UhzB7eUUj6t1EomAusroHoU6 KRcYsU6KugTWR8Fn5iErcz3hNNwO+OX6+vXyWGLUlcrwbfTija8ZZ47ARNJ+vkC6ki8w uEZ9deVZuUHeHuQm1rSyPxxI1L798b3zXvlf69e1eqSoHi2mjpO+HsvD9EDRM9MY8ZLW X3Sw== X-Gm-Message-State: AGRZ1gKX9+4325VUpVdTIHmRfrZ1Qn6Jat+j7QDLzrL/bq7puMXV8TUw lhxUYHPru37+ARWadHFjjURGwXzMKaQ= X-Google-Smtp-Source: AJdET5fy6W9TBgrZOdE3wkw6O4uQl9eCHPOMWiNWQ3QwP3MwyH+Z+1LysiKTzvfARFnIcNnGhnGkpg== X-Received: by 2002:a1c:c543:: with SMTP id v64mr1215526wmf.123.1542029201262; Mon, 12 Nov 2018 05:26:41 -0800 (PST) Received: from localhost.localdomain (236.209.54.77.rev.vodafone.pt. [77.54.209.236]) by smtp.gmail.com with ESMTPSA id 74-v6sm12405818wmn.42.2018.11.12.05.26.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 05:26:40 -0800 (PST) From: =?utf-8?q?Rafael_Ascens=C3=A3o?= To: git@vger.kernel.org Cc: =?utf-8?q?Rafael_Ascens=C3=A3o?= , Junio C Hamano , Michael Haggerty , "brian m. carlson" , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/2] refs: show --exclude failure with --branches/tags/remotes=glob Date: Mon, 12 Nov 2018 13:25:43 +0000 Message-Id: <20181112132545.31092-2-rafa.almas@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181112132545.31092-1-rafa.almas@gmail.com> References: <20181112132545.31092-1-rafa.almas@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The documentation of `--exclude=` option from rev-list and rev-parse explicitly states that exclude patterns *should not* start with 'refs/' when used with `--branches`, `--tags` or `--remotes`. However, following this advice results in refereces not being excluded if the next `--branches`, `--tags`, `--remotes` use the optional inclusive glob. Demonstrate this failure. Signed-off-by: Rafael Ascensão --- t/t6018-rev-list-glob.sh | 60 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index 0bf10d0686..8e2b136356 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -36,7 +36,13 @@ test_expect_success 'setup' ' git tag foo/bar master && commit master3 && git update-ref refs/remotes/foo/baz master && - commit master4 + commit master4 && + git update-ref refs/remotes/upstream/one subspace/one && + git update-ref refs/remotes/upstream/two subspace/two && + git update-ref refs/remotes/upstream/x subspace-x && + git tag qux/one subspace/one && + git tag qux/two subspace/two && + git tag qux/x subspace-x ' test_expect_success 'rev-parse --glob=refs/heads/subspace/*' ' @@ -141,6 +147,54 @@ test_expect_success 'rev-parse accumulates multiple --exclude' ' compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches ' +test_expect_failure 'rev-parse --exclude=glob with --branches=glob' ' + compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" +' + +test_expect_failure 'rev-parse --exclude=glob with --tags=glob' ' + compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two" +' + +test_expect_failure 'rev-parse --exclude=glob with --remotes=glob' ' + compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" +' + +test_expect_failure 'rev-parse --exclude=ref with --branches=glob' ' + compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" +' + +test_expect_failure 'rev-parse --exclude=ref with --tags=glob' ' + compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two" +' + +test_expect_failure 'rev-parse --exclude=ref with --remotes=glob' ' + compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" +' + +test_expect_failure 'rev-list --exclude=glob with --branches=glob' ' + compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" +' + +test_expect_failure 'rev-list --exclude=glob with --tags=glob' ' + compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two" +' + +test_expect_failure 'rev-list --exclude=glob with --remotes=glob' ' + compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" +' + +test_expect_failure 'rev-list --exclude=ref with --branches=glob' ' + compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" +' + +test_expect_failure 'rev-list --exclude=ref with --tags=glob' ' + compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two" +' + +test_expect_failure 'rev-list --exclude=ref with --remotes=glob' ' + compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" +' + test_expect_success 'rev-list --glob=refs/heads/subspace/*' ' compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*" @@ -233,7 +287,7 @@ test_expect_success 'rev-list --tags=foo' ' test_expect_success 'rev-list --tags' ' - compare rev-list "foo/bar" "--tags" + compare rev-list "foo/bar qux/x qux/two qux/one" "--tags" ' @@ -292,7 +346,7 @@ test_expect_success 'shortlog accepts --glob/--tags/--remotes' ' "master other/three someref subspace-x subspace/one subspace/two" \ "--glob=heads/*" && compare shortlog foo/bar --tags=foo && - compare shortlog foo/bar --tags && + compare shortlog "foo/bar qux/one qux/two qux/x" --tags && compare shortlog foo/baz --remotes=foo ' From patchwork Mon Nov 12 13:25:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rafael_Ascens=C3=A3o?= X-Patchwork-Id: 10678635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C8D4109C for ; Mon, 12 Nov 2018 13:26:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BD5C29E82 for ; Mon, 12 Nov 2018 13:26:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EF0B29EDC; Mon, 12 Nov 2018 13:26:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDC4629E82 for ; Mon, 12 Nov 2018 13:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729670AbeKLXUD (ORCPT ); Mon, 12 Nov 2018 18:20:03 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38568 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729540AbeKLXUD (ORCPT ); Mon, 12 Nov 2018 18:20:03 -0500 Received: by mail-wm1-f68.google.com with SMTP id f2-v6so8101671wme.3 for ; Mon, 12 Nov 2018 05:26:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S9964/CSASE7PzfeD3Obqi98pNN8fTXCQN881Q/nAKs=; b=UPtSJT5Gw3+PFwmx24dl9TZ2SrSmMS3ueaYfcIqzS3Xyvn27p5/0LKzh93ugHfOwCV lkq7lcRYUMgjaOPzaWk/uPgj0SEY9vAgSivAXANYZE0MwYn9zvWYN3q94n4zx2jREgam 2HO/DIgaMEuC9hMRfWMUkShaN15mwVBbcFMNAjghw45QZrj7t1DMnyfIBZJ8BYpyYMrj HjzVq4PGP9oYGJnZghiZgZmLBEb9qA9B7KrbxMJIHgQ9IHYT6xPpH6zfvmVgr1aupJln RKerqkq3RqRVvbb9rrnd7t0tYtG7BX5GghNE9lh3mrAAkkFSqoGnC4KGXE2kvF5c91dP V9Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S9964/CSASE7PzfeD3Obqi98pNN8fTXCQN881Q/nAKs=; b=IOKeHyR7pAkmqrLGOA8l6JOXXw2ozKLO1i9WzRBOl2ysoCefQHJHiw8bHNInKfVoC6 Fn8r7vwMo8eHg3mt5q5+5vImwDCJacP1yNIH3E1pDS85/x7vlwCHjpIoCpZaO099vEJO Z86akCmUzyhAb5u8ApZoPWMX/b/rqVI933AfDdlCGLnpb9yU270zYOTmdj4/rmckrA/g GYQ9zp75NjH615weEsD8XQYyxJoXKqbbebmyNGj8INPFfNwtM7x44Ipf3uHhcU/wwVT5 FEgPuzld4ROLKhuvdom3EZR35wmt0eUw+m7sIZHfvSE7JidFzJX065SyFFwyk/5VtWGv V2Kg== X-Gm-Message-State: AGRZ1gKBZRwSM3NClVuPnfvbQfc/r1U8b6Hy48/mvZ4lZyGNM7sOoEWp Emo+4j9j3yTPpJGrmiUTYU7LJONk8zA= X-Google-Smtp-Source: AJdET5erfXI7/o0266GGPE2Cz9x6imEjpi5khMt/XBiNOWB7xtXSq48VCc8HnIhWhGYRBALTja9tfQ== X-Received: by 2002:a1c:880e:: with SMTP id k14-v6mr8029957wmd.88.1542029204725; Mon, 12 Nov 2018 05:26:44 -0800 (PST) Received: from localhost.localdomain (236.209.54.77.rev.vodafone.pt. [77.54.209.236]) by smtp.gmail.com with ESMTPSA id 74-v6sm12405818wmn.42.2018.11.12.05.26.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 05:26:44 -0800 (PST) From: =?utf-8?q?Rafael_Ascens=C3=A3o?= To: git@vger.kernel.org Cc: =?utf-8?q?Rafael_Ascens=C3=A3o?= , "brian m. carlson" , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= , Jeff King , Michael Haggerty Subject: [PATCH 2/2] refs: fix some exclude patterns being ignored Date: Mon, 12 Nov 2018 13:25:44 +0000 Message-Id: <20181112132545.31092-3-rafa.almas@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181112132545.31092-1-rafa.almas@gmail.com> References: <20181112132545.31092-1-rafa.almas@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP `--exclude` from rev-list and rev-parse fails to exclude references if the next `--branches`, `--tags` or `--remotes` use the optional inclusive glob because those options are implemented as particular cases of `--glob=`, which itself requires that exclude patterns begin with 'refs/'. But it makes sense for `--branches=glob` and friends to be aware that exclusions patterns for them shouldn't be 'refs//' prefixed, the same way exclude patterns for `--branches` and friends (without the optional glob) already are. Let's record in 'refs.c:struct ref_filter' which context the exclude pattern is tied to, so refs.c:filter_refs() can decide if it should ignore the prefix when trying to match. Signed-off-by: Rafael Ascensão --- refs.c | 4 ++++ t/t6018-rev-list-glob.sh | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/refs.c b/refs.c index de81c7be7c..539f385f61 100644 --- a/refs.c +++ b/refs.c @@ -217,6 +217,7 @@ char *resolve_refdup(const char *refname, int resolve_flags, /* The argument to filter_refs */ struct ref_filter { const char *pattern; + const char *prefix; each_ref_fn *fn; void *cb_data; }; @@ -296,6 +297,8 @@ static int filter_refs(const char *refname, const struct object_id *oid, if (wildmatch(filter->pattern, refname, 0)) return 0; + if (filter->prefix) + skip_prefix(refname, filter->prefix, &refname); return filter->fn(refname, oid, flags, filter->cb_data); } @@ -458,6 +461,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, } filter.pattern = real_pattern.buf; + filter.prefix = prefix; filter.fn = fn; filter.cb_data = cb_data; ret = for_each_ref(filter_refs, &filter); diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index 8e2b136356..7dc6cbdc42 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -147,51 +147,51 @@ test_expect_success 'rev-parse accumulates multiple --exclude' ' compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches ' -test_expect_failure 'rev-parse --exclude=glob with --branches=glob' ' +test_expect_success 'rev-parse --exclude=glob with --branches=glob' ' compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" ' -test_expect_failure 'rev-parse --exclude=glob with --tags=glob' ' +test_expect_success 'rev-parse --exclude=glob with --tags=glob' ' compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two" ' -test_expect_failure 'rev-parse --exclude=glob with --remotes=glob' ' +test_expect_success 'rev-parse --exclude=glob with --remotes=glob' ' compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" ' -test_expect_failure 'rev-parse --exclude=ref with --branches=glob' ' +test_expect_success 'rev-parse --exclude=ref with --branches=glob' ' compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" ' -test_expect_failure 'rev-parse --exclude=ref with --tags=glob' ' +test_expect_success 'rev-parse --exclude=ref with --tags=glob' ' compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two" ' -test_expect_failure 'rev-parse --exclude=ref with --remotes=glob' ' +test_expect_success 'rev-parse --exclude=ref with --remotes=glob' ' compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" ' -test_expect_failure 'rev-list --exclude=glob with --branches=glob' ' +test_expect_success 'rev-list --exclude=glob with --branches=glob' ' compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" ' -test_expect_failure 'rev-list --exclude=glob with --tags=glob' ' +test_expect_success 'rev-list --exclude=glob with --tags=glob' ' compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two" ' -test_expect_failure 'rev-list --exclude=glob with --remotes=glob' ' +test_expect_success 'rev-list --exclude=glob with --remotes=glob' ' compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" ' -test_expect_failure 'rev-list --exclude=ref with --branches=glob' ' +test_expect_success 'rev-list --exclude=ref with --branches=glob' ' compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" ' -test_expect_failure 'rev-list --exclude=ref with --tags=glob' ' +test_expect_success 'rev-list --exclude=ref with --tags=glob' ' compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two" ' -test_expect_failure 'rev-list --exclude=ref with --remotes=glob' ' +test_expect_success 'rev-list --exclude=ref with --remotes=glob' ' compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" '