From 83bfbdf593a76c591bb9cbd40cec6fca36c81a9c Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 16 Jan 2012 18:00:18 -0800 Subject: [PATCH] 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. --- src/attr.c | 2 +- src/attr_file.c | 14 ++++++++++++-- src/util.c | 17 ----------------- src/util.h | 2 -- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/attr.c b/src/attr.c index 3fe76d124..fa1a4f121 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 f6eaad69d..4303c7667 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 f47de9e53..1ca9d850c 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 818e6f0f2..6c929cf0a 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++;