Re: multiple source file extensions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 01, 2015 at 09:11:01PM -0400, Jeff King wrote:
> Unfortunately there is no way to use curly braces with git's pathspec,
> so you have to write out three separate `*` arguments rather than using
> the shell-style {cc,cpp,h}.

Noted. Need to add curly brace support in pathspec :-)

>   git grep pattern -- '*.cc' '*.cpp' '*.h'
> 
> Note that the "--" is important (it's what tells git "these are
> pathspecs and not revision names"; normally git will guess if you are
> passing literal pathnames, but the glob patterns fool the guessing
> machinery).

I'm having something like below to avoid the need for "--" in this
case. Probably a good time to throw it out and get some feedback. I
think it's a good change and does not compromise our ambiguity check..

This patch is modified just for reading so it may not build. The real
series takes care of "--" for both wildcard and magic pathspec. But I
don't think we need to see it now.

-- 8< --
Subject: [PATCH] Avoid the need of "--" when wildcard pathspec is used

When "--" is lacking from the command line and a command can take both
revs and paths, the idea is if an argument can be seen as both an
extended SHA-1 and a path, then "--" is required or git refuses to
continue. It's currently implemented as:

 (1) if an argument is rev, then it must not exist in worktree

 (2) else, it must exist in worktree

 (3) else, "--" is required.

These rules work for literal paths, but when non-literal pathspec is
involved, it almost always requires the user to add "--" because it
fails (2) and (1) is really rarely met (take "*.c" for example,
(1) is met if there is a ref named "*.c").

This patch modifies the rules a bit by considering any valid (*)
wildcard pathspec "exist in worktree". The rules become:

 (1) if an arg is a rev, then it must either exist in worktree or not
     be a valid wildcard pathspec.

 (2) else, it either exists in worktree or is a wildcard pathspec

 (3) else, "--" is required.

With the new rules, "--" is not needed most of the time when wildcard
pathspec is involved.
---
 setup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/setup.c b/setup.c
index 979b13f..1055b82 100644
--- a/setup.c
+++ b/setup.c
@@ -140,7 +140,9 @@ int check_filename(const char *prefix, const char *arg)
 		if (arg[2] == '\0') /* ":/" is root dir, always exists */
 			return 1;
 		name = arg + 2;
-	} else if (prefix)
+	} else if (!no_wildcard(arg))
+		return 1;
+	else if (prefix)
 		name = prefix_filename(prefix, strlen(prefix), arg);
 	else
 		name = arg;
-- 
2.3.0.rc1.137.g477eb31

-- 8< --
 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]