summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c841aa8)
raw | patch | inline | side by side (parent: c841aa8)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sat, 17 Jan 2009 15:50:34 +0000 (16:50 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 18 Jan 2009 02:30:37 +0000 (18:30 -0800) |
Replace isspecial() by the new macro is_glob_special(), which is more,
well, specialized. The former included the NUL char in its character
class, while the letter only included characters that are special to
file name globbing.
The new name contains underscores because they enhance readability
considerably now that it's made up of three words. Renaming the
function is necessary to document its changed scope.
The call sites of isspecial() are updated to check explicitly for NUL.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
well, specialized. The former included the NUL char in its character
class, while the letter only included characters that are special to
file name globbing.
The new name contains underscores because they enhance readability
considerably now that it's made up of three words. Renaming the
function is necessary to document its changed scope.
The call sites of isspecial() are updated to check explicitly for NUL.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ctype.c | patch | blob | history | |
dir.c | patch | blob | history | |
git-compat-util.h | patch | blob | history | |
grep.c | patch | blob | history | |
test-ctype.c | patch | blob | history |
index 6528687000ba594c86bcd2725ceba6c8a417eb9a..9de187c812ff39a5cd7bbe81d9808130c9c40bec 100644 (file)
--- a/ctype.c
+++ b/ctype.c
S = GIT_SPACE,
A = GIT_ALPHA,
D = GIT_DIGIT,
- G = GIT_SPECIAL, /* \0, *, ?, [, \\ */
+ G = GIT_GLOB_SPECIAL, /* *, ?, [, \\ */
};
unsigned char sane_ctype[256] = {
- G, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0, /* 0.. 15 */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0, /* 0.. 15 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16.. 31 */
S, 0, 0, 0, 0, 0, 0, 0, 0, 0, G, 0, 0, 0, 0, 0, /* 32.. 47 */
D, D, D, D, D, D, D, D, D, D, 0, 0, 0, 0, 0, G, /* 48.. 63 */
index 0131983dfbc143ce5dae77e067663bb2e7d5f126..7ae1e2e75c4a588d8390c21951368b6471914a24 100644 (file)
--- a/dir.c
+++ b/dir.c
for (;;) {
unsigned char c1 = *match;
unsigned char c2 = *name;
- if (isspecial(c1))
+ if (c1 == '\0' || is_glob_special(c1))
break;
if (c1 != c2)
return 0;
for (;;) {
unsigned char c = *match++;
len++;
- if (isspecial(c))
+ if (c == '\0' || is_glob_special(c))
return len;
}
}
diff --git a/git-compat-util.h b/git-compat-util.h
index e20b1e858cc715d1840da11c6198a1d6e6bec2a4..7c925881d97df5db2ee89aba4fa95579e04dcc30 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
#define GIT_SPACE 0x01
#define GIT_DIGIT 0x02
#define GIT_ALPHA 0x04
-#define GIT_SPECIAL 0x08
+#define GIT_GLOB_SPECIAL 0x08
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
#define isspace(x) sane_istest(x,GIT_SPACE)
#define isdigit(x) sane_istest(x,GIT_DIGIT)
#define isalpha(x) sane_istest(x,GIT_ALPHA)
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
-#define isspecial(x) sane_istest(x,GIT_SPECIAL)
+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
#define tolower(x) sane_case((unsigned char)(x), 0x20)
#define toupper(x) sane_case((unsigned char)(x), 0)
index 6485760ff30e0575ee13b43fc8c7fb8e2e291346..f9a45258aa0485df6f6205aa8121bdad07a480b0 100644 (file)
--- a/grep.c
+++ b/grep.c
static int isregexspecial(int c)
{
- return isspecial(c) || c == '$' || c == '(' || c == ')' || c == '+' ||
- c == '.' || c == '^' || c == '{' || c == '|';
+ return c == '\0' || is_glob_special(c) ||
+ c == '$' || c == '(' || c == ')' || c == '+' ||
+ c == '.' || c == '^' || c == '{' || c == '|';
}
static int is_fixed(const char *s)
diff --git a/test-ctype.c b/test-ctype.c
index 723eff4e96ca4389f2ffba70fbda3e44b2a96ebf..d6425d5b40b6849d63a4f6b924fb2eb3dbded9e7 100644 (file)
--- a/test-ctype.c
+++ b/test-ctype.c
return isalnum(c);
}
+static int test_is_glob_special(int c)
+{
+ return is_glob_special(c);
+}
+
#define DIGIT "0123456789"
#define LOWER "abcdefghijklmnopqrstuvwxyz"
#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
{ "isspace", test_isspace, " \n\r\t" },
{ "isalpha", test_isalpha, LOWER UPPER },
{ "isalnum", test_isalnum, LOWER UPPER DIGIT },
+ { "is_glob_special", test_is_glob_special, "*?[\\" },
{ NULL }
};