On Tue, 7 Feb 2017, Linus Torvalds wrote: > > [ Clarification from original message, since Junio asked: I didn't > actually want the semantics of '.' at all, since in a subdirectory it > limits to the current subdirectory. So I'd suggest that in the absence > of any positive pattern, there is simply no filtering at all, so > whenever I say '.' as a pattern, I really meant ":(top)." which is > even more of a cumbersom syntax that the current model really > encourages. Crazy. Since I tend to always work in the top directory, > the two are the same for me ] So here's an RFC patch, and I'm quoting the above part of my thinking because it's what the patch does, but it turns out that it's probably not what we want, and I suspect the "." behavior (as opposed to "no filtering at all") is actually better. Now _I_ don't much care, since I only work from the top level, but without the "." behavior, you get into an odd situation that the negative match will be relative to the current directory, but then the positive matches will be everywhere else. Obviously, a negative match that has "top" set would change that logic. So this patch is purely a request for further discussion. When I wrote the patch, I actually also removed the now stale entries from the 'po' files, but I'm not including that part here because it just distracts from the meat of it all. So this diff was actually generated with the new syntax: git diff -p --stat -- :^po/ and the only thing even remotely subtle here is that it changes our ctype array to make '^' be both a regex and a pathspec magic character. Everything else should be pretty darn obvious. The code *could* just track all the 'relative to top or not' bits in the exclusion pattern, and then use whatever top-ness the exclusion patterns have (and maybe fall back to the old warning if it had a mixture of exclusionary patterns). I'll happily change it to act that way if people think that makes sense. Comments? Linus --- ctype.c | 3 ++- pathspec.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ctype.c b/ctype.c index fc0225ceb..250e2ce15 100644 --- a/ctype.c +++ b/ctype.c @@ -14,6 +14,7 @@ enum { P = GIT_PATHSPEC_MAGIC, /* other non-alnum, except for ] and } */ X = GIT_CNTRL, U = GIT_PUNCT, + Y = GIT_REGEX_SPECIAL | GIT_PATHSPEC_MAGIC, Z = GIT_CNTRL | GIT_SPACE }; @@ -23,7 +24,7 @@ const unsigned char sane_ctype[256] = { S, P, P, P, R, P, P, P, R, R, G, R, P, P, R, P, /* 32.. 47 */ D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G, /* 48.. 63 */ P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 64.. 79 */ - A, A, A, A, A, A, A, A, A, A, A, G, G, U, R, P, /* 80.. 95 */ + A, A, A, A, A, A, A, A, A, A, A, G, G, U, Y, P, /* 80.. 95 */ P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 96..111 */ A, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X, /* 112..127 */ /* Nothing in the 128.. range */ diff --git a/pathspec.c b/pathspec.c index 7ababb315..ef59d080d 100644 --- a/pathspec.c +++ b/pathspec.c @@ -72,6 +72,7 @@ static struct pathspec_magic { { PATHSPEC_GLOB, '\0', "glob" }, { PATHSPEC_ICASE, '\0', "icase" }, { PATHSPEC_EXCLUDE, '!', "exclude" }, + { PATHSPEC_EXCLUDE, '^', "exclude" }, }; static void prefix_magic(struct strbuf *sb, int prefixlen, unsigned magic) @@ -516,7 +517,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; @@ -540,10 +541,14 @@ 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) { + init_pathspec_item(item + n, 0, "", 0, ""); + pathspec->nr++; + } if (pathspec->magic & PATHSPEC_MAXDEPTH) { if (flags & PATHSPEC_KEEP_ORDER)