summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2012-10-15 06:24:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-10-15 21:57:16 (GMT)
commit593cb8802eb43b17e6344790278cea7e6ec68b43 (patch)
treec67bf765091c25cbd3be94cc02c331eef6b735be /dir.c
parent692663303f67371a2e4af4e3d353b042f754c036 (diff)
downloadgit-593cb8802eb43b17e6344790278cea7e6ec68b43.zip
git-593cb8802eb43b17e6344790278cea7e6ec68b43.tar.gz
git-593cb8802eb43b17e6344790278cea7e6ec68b43.tar.bz2
exclude: split basename matching code into a separate function
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/dir.c b/dir.c
index b0ae417..d9b5561 100644
--- a/dir.c
+++ b/dir.c
@@ -503,6 +503,25 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
dir->basebuf[baselen] = '\0';
}
+static int match_basename(const char *basename, int basenamelen,
+ const char *pattern, int prefix, int patternlen,
+ int flags)
+{
+ if (prefix == patternlen) {
+ if (!strcmp_icase(pattern, basename))
+ return 1;
+ } else if (flags & EXC_FLAG_ENDSWITH) {
+ if (patternlen - 1 <= basenamelen &&
+ !strcmp_icase(pattern + 1,
+ basename + basenamelen - patternlen + 1))
+ return 1;
+ } else {
+ if (fnmatch_icase(pattern, basename, 0) == 0)
+ return 1;
+ }
+ return 0;
+}
+
/* Scan the list and let the last match determine the fate.
* Return 1 for exclude, 0 for include and -1 for undecided.
*/
@@ -529,19 +548,11 @@ int excluded_from_list(const char *pathname,
}
if (x->flags & EXC_FLAG_NODIR) {
- /* match basename */
- if (prefix == x->patternlen) {
- if (!strcmp_icase(exclude, basename))
- return to_exclude;
- } else if (x->flags & EXC_FLAG_ENDSWITH) {
- int len = pathlen - (basename - pathname);
- if (x->patternlen - 1 <= len &&
- !strcmp_icase(exclude + 1, basename + len - x->patternlen + 1))
- return to_exclude;
- } else {
- if (fnmatch_icase(exclude, basename, 0) == 0)
- return to_exclude;
- }
+ if (match_basename(basename,
+ pathlen - (basename - pathname),
+ exclude, prefix, x->patternlen,
+ x->flags))
+ return to_exclude;
continue;
}