[PATCH Cogito] match pathnames in exclude handling
- From
Matthias Urlichs <smurf@smurf.noris.de>
- Date
- May 11, 2005, 05:25 UTC
- Message-ID
- <20050511052546.GC11192@kiste.smurf.noris.de>
- In-Reply-To
- <4281281F.6000101@cobite.com>
Hi,
David Mansfield:
> Is there/will there be support for path matching in the ignore files? > > If the answer is no, but people like the idea, I could look into it. >
I already did, last week. (I do need to cleanup my changes...)
The idea is that "foo" matches anywhere, "foo/bar" the exact pathname. As a special case, "./foo" matches in the root directory only.
NB: "*" can cross subdirectory paths, so "*/foo/bar" does match "a/b/c/foo/bar".
Signed-Off-By: Matthias Urlichs <smurf@smurf.noris.de>
---
Index: ls-files.c =================================================================== --- 972d8624458936868e6f392b40858b7c362af8cd/ls-files.c (mode:100644) +++ 12deb13b12cdb338fe3fdc2e77a024490d6c39ea/ls-files.c (mode:100644) @@ -80,9 +80,17 @@ if (nr_excludes) { const char *basename = strrchr(pathname, '/'); basename = (basename) ? basename+1 : pathname; - for (i = 0; i < nr_excludes; i++) - if (fnmatch(excludes[i], basename, 0) == 0) - return 1; + for (i = 0; i < nr_excludes; i++) { + if (excludes[i][0] != '.' || excludes[i][1] != '/') { + if (fnmatch(excludes[i], pathname, 0) == 0) + return 1; + if (basename != pathname && fnmatch(excludes[i], pathname, 0) == 0) + return 1; + } else { + if (fnmatch(excludes[i]+2, pathname, 0) == 0) + return 1; + } + } } return 0; } @@ -129,10 +137,10 @@ if (de->d_name[0] == '.') continue; - if (excluded(de->d_name) != show_ignored) - continue; len = strlen(de->d_name); memcpy(fullname + baselen, de->d_name, len+1); + if (excluded(fullname) != show_ignored) + continue; switch (DTYPE(de)) { struct stat st;
--
Matthias Urlichs | {M:U} IT Design @ m-u-it.de | smurf@smurf.noris.de