Remove poor git__removechar function Going back over this, the git__removechar function was not needed (only invoked once) and is actually mislabeled. As implemented, it really only made sense for removing backslash characters, since two of the "removed" characters in a row would include the second one -- i.e. it really implements stripping backslash-escaped strings where a backslash allows internal whitespace in a word.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
diff --git a/src/attr.c b/src/attr.c
index 3fe76d1..fa1a4f1 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -232,7 +232,7 @@ int git_attr_cache__push_file(
file = git_hashtable_lookup(cache->files, filename);
if (file == NULL && git_futils_exists(filename) == GIT_SUCCESS) {
if ((error = git_attr_file__new(&file)) == GIT_SUCCESS)
- error = (*loader)(repo, filename, file);
+ error = loader(repo, filename, file);
add_to_cache = (error == GIT_SUCCESS);
}
diff --git a/src/attr_file.c b/src/attr_file.c
index f6eaad6..4303c76 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -363,8 +363,18 @@ int git_attr_fnmatch__parse(
*base = git__next_line(pattern);
return GIT_ENOMEM;
} else {
- /* remove '\' that might have be used for internal whitespace */
- spec->length = git__removechar(spec->pattern, '\\');
+ /* strip '\' that might have be used for internal whitespace */
+ char *to = spec->pattern;
+ for (scan = spec->pattern; *scan; to++, scan++) {
+ if (*scan == '\\')
+ scan++; /* skip '\' but include next char */
+ if (to != scan)
+ *to = *scan;
+ }
+ if (to != scan) {
+ *to = '\0';
+ spec->length = (to - spec->pattern);
+ }
}
return GIT_SUCCESS;
diff --git a/src/util.c b/src/util.c
index f47de9e..1ca9d85 100644
--- a/src/util.c
+++ b/src/util.c
@@ -156,23 +156,6 @@ void git__strtolower(char *str)
git__strntolower(str, strlen(str));
}
-size_t git__removechar(char *str, char remove)
-{
- char *from = str, *to = str;
-
- while (*from) {
- if (*from == remove)
- from++;
- if (to != from)
- *to = *from;
- to++;
- from++;
- }
- *to = '\0';
-
- return (to - str);
-}
-
int git__prefixcmp(const char *str, const char *prefix)
{
for (;;) {
diff --git a/src/util.h b/src/util.h
index 818e6f0..6c929cf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -102,8 +102,6 @@ extern char *git__strtok(char **end, const char *sep);
extern void git__strntolower(char *str, size_t len);
extern void git__strtolower(char *str);
-extern size_t git__removechar(char *str, char remove);
-
GIT_INLINE(const char *) git__next_line(const char *s)
{
while (*s && *s != '\n') s++;