dir.c: rename str(n)cmp_icase to fspath(n)cmp

These functions compare two paths that are taken from file system.
Depending on the running file system, paths may need to be compared
case-sensitively or not, and maybe even something else in future. The
current names do not convey that well.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2016-04-22 20:01:24 +07:00 committed by Junio C Hamano
parent e6ac6e1f7d
commit ba0897e6ae
4 changed files with 12 additions and 13 deletions

13
dir.c
View File

@ -53,13 +53,12 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
int check_only, const struct path_simplify *simplify); int check_only, const struct path_simplify *simplify);
static int get_dtype(struct dirent *de, const char *path, int len); static int get_dtype(struct dirent *de, const char *path, int len);
/* helper string functions with support for the ignore_case flag */ int fspathcmp(const char *a, const char *b)
int strcmp_icase(const char *a, const char *b)
{ {
return ignore_case ? strcasecmp(a, b) : strcmp(a, b); return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
} }
int strncmp_icase(const char *a, const char *b, size_t count) int fspathncmp(const char *a, const char *b, size_t count)
{ {
return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count); return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
} }
@ -802,12 +801,12 @@ int match_basename(const char *basename, int basenamelen,
{ {
if (prefix == patternlen) { if (prefix == patternlen) {
if (patternlen == basenamelen && if (patternlen == basenamelen &&
!strncmp_icase(pattern, basename, basenamelen)) !fspathncmp(pattern, basename, basenamelen))
return 1; return 1;
} else if (flags & EXC_FLAG_ENDSWITH) { } else if (flags & EXC_FLAG_ENDSWITH) {
/* "*literal" matching against "fooliteral" */ /* "*literal" matching against "fooliteral" */
if (patternlen - 1 <= basenamelen && if (patternlen - 1 <= basenamelen &&
!strncmp_icase(pattern + 1, !fspathncmp(pattern + 1,
basename + basenamelen - (patternlen - 1), basename + basenamelen - (patternlen - 1),
patternlen - 1)) patternlen - 1))
return 1; return 1;
@ -844,7 +843,7 @@ int match_pathname(const char *pathname, int pathlen,
*/ */
if (pathlen < baselen + 1 || if (pathlen < baselen + 1 ||
(baselen && pathname[baselen] != '/') || (baselen && pathname[baselen] != '/') ||
strncmp_icase(pathname, base, baselen)) fspathncmp(pathname, base, baselen))
return 0; return 0;
namelen = baselen ? pathlen - baselen - 1 : pathlen; namelen = baselen ? pathlen - baselen - 1 : pathlen;
@ -858,7 +857,7 @@ int match_pathname(const char *pathname, int pathlen,
if (prefix > namelen) if (prefix > namelen)
return 0; return 0;
if (strncmp_icase(pattern, name, prefix)) if (fspathncmp(pattern, name, prefix))
return 0; return 0;
pattern += prefix; pattern += prefix;
patternlen -= prefix; patternlen -= prefix;

4
dir.h
View File

@ -270,8 +270,8 @@ extern int remove_dir_recursively(struct strbuf *path, int flag);
/* tries to remove the path with empty directories along it, ignores ENOENT */ /* tries to remove the path with empty directories along it, ignores ENOENT */
extern int remove_path(const char *path); extern int remove_path(const char *path);
extern int strcmp_icase(const char *a, const char *b); extern int fspathcmp(const char *a, const char *b);
extern int strncmp_icase(const char *a, const char *b, size_t count); extern int fspathncmp(const char *a, const char *b, size_t count);
extern int fnmatch_icase(const char *pattern, const char *string, int flags); extern int fnmatch_icase(const char *pattern, const char *string, int flags);
/* /*

View File

@ -1512,7 +1512,7 @@ static int tree_content_set(
t = root->tree; t = root->tree;
for (i = 0; i < t->entry_count; i++) { for (i = 0; i < t->entry_count; i++) {
e = t->entries[i]; e = t->entries[i];
if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) { if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
if (!*slash1) { if (!*slash1) {
if (!S_ISDIR(mode) if (!S_ISDIR(mode)
&& e->versions[1].mode == mode && e->versions[1].mode == mode
@ -1602,7 +1602,7 @@ static int tree_content_remove(
t = root->tree; t = root->tree;
for (i = 0; i < t->entry_count; i++) { for (i = 0; i < t->entry_count; i++) {
e = t->entries[i]; e = t->entries[i];
if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) { if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
if (*slash1 && !S_ISDIR(e->versions[1].mode)) if (*slash1 && !S_ISDIR(e->versions[1].mode))
/* /*
* If p names a file in some subdirectory, and a * If p names a file in some subdirectory, and a
@ -1669,7 +1669,7 @@ static int tree_content_get(
t = root->tree; t = root->tree;
for (i = 0; i < t->entry_count; i++) { for (i = 0; i < t->entry_count; i++) {
e = t->entries[i]; e = t->entries[i];
if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) { if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
if (!*slash1) if (!*slash1)
goto found_entry; goto found_entry;
if (!S_ISDIR(e->versions[1].mode)) if (!S_ISDIR(e->versions[1].mode))

View File

@ -301,7 +301,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
return -1; return -1;
} }
} }
if (!strcmp_icase(ent->base, normalized_objdir)) { if (!fspathcmp(ent->base, normalized_objdir)) {
free(ent); free(ent);
return -1; return -1;
} }