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:
parent
e6ac6e1f7d
commit
ba0897e6ae
13
dir.c
13
dir.c
@ -53,13 +53,12 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
|
||||
int check_only, const struct path_simplify *simplify);
|
||||
static int get_dtype(struct dirent *de, const char *path, int len);
|
||||
|
||||
/* helper string functions with support for the ignore_case flag */
|
||||
int strcmp_icase(const char *a, const char *b)
|
||||
int fspathcmp(const char *a, const char *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);
|
||||
}
|
||||
@ -802,12 +801,12 @@ int match_basename(const char *basename, int basenamelen,
|
||||
{
|
||||
if (prefix == patternlen) {
|
||||
if (patternlen == basenamelen &&
|
||||
!strncmp_icase(pattern, basename, basenamelen))
|
||||
!fspathncmp(pattern, basename, basenamelen))
|
||||
return 1;
|
||||
} else if (flags & EXC_FLAG_ENDSWITH) {
|
||||
/* "*literal" matching against "fooliteral" */
|
||||
if (patternlen - 1 <= basenamelen &&
|
||||
!strncmp_icase(pattern + 1,
|
||||
!fspathncmp(pattern + 1,
|
||||
basename + basenamelen - (patternlen - 1),
|
||||
patternlen - 1))
|
||||
return 1;
|
||||
@ -844,7 +843,7 @@ int match_pathname(const char *pathname, int pathlen,
|
||||
*/
|
||||
if (pathlen < baselen + 1 ||
|
||||
(baselen && pathname[baselen] != '/') ||
|
||||
strncmp_icase(pathname, base, baselen))
|
||||
fspathncmp(pathname, base, baselen))
|
||||
return 0;
|
||||
|
||||
namelen = baselen ? pathlen - baselen - 1 : pathlen;
|
||||
@ -858,7 +857,7 @@ int match_pathname(const char *pathname, int pathlen,
|
||||
if (prefix > namelen)
|
||||
return 0;
|
||||
|
||||
if (strncmp_icase(pattern, name, prefix))
|
||||
if (fspathncmp(pattern, name, prefix))
|
||||
return 0;
|
||||
pattern += prefix;
|
||||
patternlen -= prefix;
|
||||
|
4
dir.h
4
dir.h
@ -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 */
|
||||
extern int remove_path(const char *path);
|
||||
|
||||
extern int strcmp_icase(const char *a, const char *b);
|
||||
extern int strncmp_icase(const char *a, const char *b, size_t count);
|
||||
extern int fspathcmp(const char *a, const char *b);
|
||||
extern int fspathncmp(const char *a, const char *b, size_t count);
|
||||
extern int fnmatch_icase(const char *pattern, const char *string, int flags);
|
||||
|
||||
/*
|
||||
|
@ -1512,7 +1512,7 @@ static int tree_content_set(
|
||||
t = root->tree;
|
||||
for (i = 0; i < t->entry_count; 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 (!S_ISDIR(mode)
|
||||
&& e->versions[1].mode == mode
|
||||
@ -1602,7 +1602,7 @@ static int tree_content_remove(
|
||||
t = root->tree;
|
||||
for (i = 0; i < t->entry_count; 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 p names a file in some subdirectory, and a
|
||||
@ -1669,7 +1669,7 @@ static int tree_content_get(
|
||||
t = root->tree;
|
||||
for (i = 0; i < t->entry_count; 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)
|
||||
goto found_entry;
|
||||
if (!S_ISDIR(e->versions[1].mode))
|
||||
|
@ -301,7 +301,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (!strcmp_icase(ent->base, normalized_objdir)) {
|
||||
if (!fspathcmp(ent->base, normalized_objdir)) {
|
||||
free(ent);
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user