From 42ebeb9d07de3c6d3a263f8ebce0508e489e5cc9 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 7 Feb 2017 21:05:28 -0800 Subject: pathspec magic: add '^' as alias for '!' The choice of '!' for a negative pathspec ends up not only not matching what we do for revisions, it's also a horrible character for shell expansion since it needs quoting. So add '^' as an alternative alias for an excluding pathspec entry. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index 8ad29e6..822ca83 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -386,8 +386,8 @@ Glob magic is incompatible with literal magic. exclude;; After a path matches any non-exclude pathspec, it will be run - through all exclude pathspec (magic signature: `!`). If it - matches, the path is ignored. + through all exclude pathspec (magic signature: `!` or its + synonym `^`). If it matches, the path is ignored. -- [[def_parent]]parent:: diff --git a/pathspec.c b/pathspec.c index 7ababb3..ecad034 100644 --- a/pathspec.c +++ b/pathspec.c @@ -224,6 +224,12 @@ static const char *parse_short_magic(unsigned *magic, const char *elem) char ch = *pos; int i; + /* Special case alias for '!' */ + if (ch == '^') { + *magic |= PATHSPEC_EXCLUDE; + continue; + } + if (!is_pathspec_magic(ch)) break; -- cgit v0.10.2-6-g49f6 From 859b7f1d0e742493d2a9396794cd9040213ad846 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 7 Feb 2017 21:08:15 -0800 Subject: pathspec: don't error out on all-exclusionary pathspec patterns Instead of erroring out and telling the user that they should add a positive pattern that covers everything else, just _do_ that. For commands where we honor the current cwd by default (ie grep, ls-files etc), we make that default positive pathspec be the current working directory. And for commands that default to the whole project (ie diff, log, etc), the default positive pathspec is the whole project. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index 822ca83..fc9320e 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -387,7 +387,9 @@ Glob magic is incompatible with literal magic. exclude;; After a path matches any non-exclude pathspec, it will be run through all exclude pathspec (magic signature: `!` or its - synonym `^`). If it matches, the path is ignored. + synonym `^`). If it matches, the path is ignored. When there + is no non-exclude pathspec, the exclusion is applied to the + result set as if invoked without any pathspec. -- [[def_parent]]parent:: diff --git a/pathspec.c b/pathspec.c index ecad034..b961f00 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); + ALLOC_ARRAY(pathspec->items, n + 1); item = pathspec->items; prefixlen = prefix ? strlen(prefix) : 0; @@ -546,10 +546,15 @@ 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) { + int plen = (!(flags & PATHSPEC_PREFER_CWD)) ? 0 : prefixlen; + init_pathspec_item(item + n, 0, prefix, plen, ""); + pathspec->nr++; + } if (pathspec->magic & PATHSPEC_MAXDEPTH) { if (flags & PATHSPEC_KEEP_ORDER) diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index d51595c..9dd5cde 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' ' -- cgit v0.10.2-6-g49f6