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>
Nguyễn Thái Ngọc Duy committed
Apr 22, 2016 at 20:01 UTC
ba0897e6ae6b0b3f259efb31be0f1ab3d820aacf
4 files changed
+12
-13
dir.c
+6
-7
@@ -53,13 +53,12 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
53
int check_only, const struct path_simplify *simplify);
54
static int get_dtype(struct dirent *de, const char *path, int len);
55
56
-/* helper string functions with support for the ignore_case flag */
57
-int strcmp_icase(const char *a, const char *b)
56
+int fspathcmp(const char *a, const char *b)
57
{
58
return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
59
}
60
62
-int strncmp_icase(const char *a, const char *b, size_t count)
61
+int fspathncmp(const char *a, const char *b, size_t count)
62
{
63
return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
64
}
@@ -802,12 +801,12 @@ int match_basename(const char *basename, int basenamelen,
801
{
802
if (prefix == patternlen) {
803
if (patternlen == basenamelen &&
805
- !strncmp_icase(pattern, basename, basenamelen))
804
+ !fspathncmp(pattern, basename, basenamelen))
805
return 1;
806
} else if (flags & EXC_FLAG_ENDSWITH) {
807
/* "*literal" matching against "fooliteral" */
808
if (patternlen - 1 <= basenamelen &&
810
- !strncmp_icase(pattern + 1,
809
+ !fspathncmp(pattern + 1,
810
basename + basenamelen - (patternlen - 1),
811
patternlen - 1))
812
return 1;
@@ -844,7 +843,7 @@ int match_pathname(const char *pathname, int pathlen,
843
*/
844
if (pathlen < baselen + 1 ||
845
(baselen && pathname[baselen] != '/') ||
847
- strncmp_icase(pathname, base, baselen))
846
+ fspathncmp(pathname, base, baselen))
847
return 0;
848
849
namelen = baselen ? pathlen - baselen - 1 : pathlen;
@@ -858,7 +857,7 @@ int match_pathname(const char *pathname, int pathlen,
857
if (prefix > namelen)
858
return 0;
859
861
- if (strncmp_icase(pattern, name, prefix))
860
+ if (fspathncmp(pattern, name, prefix))
861
return 0;
862
pattern += prefix;
863
patternlen -= prefix;
dir.h
+2
-2
@@ -270,8 +270,8 @@ extern int remove_dir_recursively(struct strbuf *path, int flag);
270
/* tries to remove the path with empty directories along it, ignores ENOENT */
271
extern int remove_path(const char *path);
272
273
-extern int strcmp_icase(const char *a, const char *b);
274
-extern int strncmp_icase(const char *a, const char *b, size_t count);
273
+extern int fspathcmp(const char *a, const char *b);
274
+extern int fspathncmp(const char *a, const char *b, size_t count);
275
extern int fnmatch_icase(const char *pattern, const char *string, int flags);
276
277
/*
fast-import.c
+3
-3
@@ -1512,7 +1512,7 @@ static int tree_content_set(
1512
t = root->tree;
1513
for (i = 0; i < t->entry_count; i++) {
1514
e = t->entries[i];
1515
- if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
1515
+ if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
1516
if (!*slash1) {
1517
if (!S_ISDIR(mode)
1518
&& e->versions[1].mode == mode
@@ -1602,7 +1602,7 @@ static int tree_content_remove(
1602
t = root->tree;
1603
for (i = 0; i < t->entry_count; i++) {
1604
e = t->entries[i];
1605
- if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
1605
+ if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
1606
if (*slash1 && !S_ISDIR(e->versions[1].mode))
1607
/*
1608
* If p names a file in some subdirectory, and a
@@ -1669,7 +1669,7 @@ static int tree_content_get(
1669
t = root->tree;
1670
for (i = 0; i < t->entry_count; i++) {
1671
e = t->entries[i];
1672
- if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
1672
+ if (e->name->str_len == n && !fspathncmp(p, e->name->str_dat, n)) {
1673
if (!*slash1)
1674
goto found_entry;
1675
if (!S_ISDIR(e->versions[1].mode))
sha1_file.c
+1
-1
@@ -301,7 +301,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
301
return -1;
302
}
303
}
304
- if (!strcmp_icase(ent->base, normalized_objdir)) {
304
+ if (!fspathcmp(ent->base, normalized_objdir)) {
305
free(ent);
306
return -1;
307
}