From: Junio C Hamano <gitster@pobox.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns
Date: Wed, 08 Feb 2017 13:59:34 -0800 [thread overview]
Message-ID: <xmqqk290uywp.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <alpine.LFD.2.20.1702072113380.25002@i7.lan> (Linus Torvalds's message of "Tue, 7 Feb 2017 21:14:40 -0800 (PST)")
Linus Torvalds <torvalds@linux-foundation.org> writes:
> @@ -546,10 +546,16 @@ void parse_pathspec(struct pathspec *pathspec,
> pathspec->magic |= item[i].magic;
> }
>
> - if (nr_exclude == n)
> - die(_("There is nothing to exclude from by :(exclude) patterns.\n"
> - "Perhaps you forgot to add either ':/' or '.' ?"));
> -
> + /*
> + * If everything is an exclude pattern, add one positive pattern
> + * that matches everyting. We allocated an extra one for this.
> + */
> + if (nr_exclude == n) {
> + if (!(flags & PATHSPEC_PREFER_CWD))
> + prefixlen = 0;
> + init_pathspec_item(item + n, 0, prefix, prefixlen, "");
> + pathspec->nr++;
> + }
>
> if (pathspec->magic & PATHSPEC_MAXDEPTH) {
> if (flags & PATHSPEC_KEEP_ORDER)
Thanks. Even though the current code does not refer to the original
prefixlen after the added hunk, I'd prefer not to destroy it to
avoid future troubles, so I'll queue with a bit of tweak there,
perhaps like the attached.
Also this has an obvious fallout to the tests, whose (minimum) fix
is rather trivial.
Thanks.
pathspec.c | 7 +++----
t/t6132-pathspec-exclude.sh | 6 ++++--
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/pathspec.c b/pathspec.c
index d8f78088c8..b961f00c8c 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -522,7 +522,7 @@ void parse_pathspec(struct pathspec *pathspec,
}
pathspec->nr = n;
- ALLOC_ARRAY(pathspec->items, n+1);
+ ALLOC_ARRAY(pathspec->items, n + 1);
item = pathspec->items;
prefixlen = prefix ? strlen(prefix) : 0;
@@ -551,9 +551,8 @@ void parse_pathspec(struct pathspec *pathspec,
* that matches everyting. We allocated an extra one for this.
*/
if (nr_exclude == n) {
- if (!(flags & PATHSPEC_PREFER_CWD))
- prefixlen = 0;
- init_pathspec_item(item + n, 0, prefix, prefixlen, "");
+ int plen = (!(flags & PATHSPEC_PREFER_CWD)) ? 0 : prefixlen;
+ init_pathspec_item(item + n, 0, prefix, plen, "");
pathspec->nr++;
}
diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh
index d51595cf6b..9dd5cde5fc 100755
--- a/t/t6132-pathspec-exclude.sh
+++ b/t/t6132-pathspec-exclude.sh
@@ -25,8 +25,10 @@ EOF
test_cmp expect actual
'
-test_expect_success 'exclude only should error out' '
- test_must_fail git log --oneline --format=%s -- ":(exclude)sub"
+test_expect_success 'exclude only no longer errors out' '
+ git log --oneline --format=%s -- . ":(exclude)sub" >expect &&
+ git log --oneline --format=%s -- ":(exclude)sub" >actual &&
+ test_cmp expect actual
'
test_expect_success 't_e_i() exclude sub' '
next prev parent reply other threads:[~2017-02-08 22:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-08 5:14 [PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns Linus Torvalds
2017-02-08 13:23 ` Cornelius Weig
2017-02-08 21:59 ` Junio C Hamano [this message]
2017-02-08 22:16 ` Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqk290uywp.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).