Skip to content

Commit ba0897e

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent e6ac6e1 commit ba0897e

4 files changed

Lines changed: 12 additions & 13 deletions

File tree

dir.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
5353
int check_only, const struct path_simplify *simplify);
5454
static int get_dtype(struct dirent *de, const char *path, int len);
5555

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)
5857
{
5958
return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
6059
}
6160

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)
6362
{
6463
return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
6564
}
@@ -802,12 +801,12 @@ int match_basename(const char *basename, int basenamelen,
802801
{
803802
if (prefix == patternlen) {
804803
if (patternlen == basenamelen &&
805-
!strncmp_icase(pattern, basename, basenamelen))
804+
!fspathncmp(pattern, basename, basenamelen))
806805
return 1;
807806
} else if (flags & EXC_FLAG_ENDSWITH) {
808807
/* "*literal" matching against "fooliteral" */
809808
if (patternlen - 1 <= basenamelen &&
810-
!strncmp_icase(pattern + 1,
809+
!fspathncmp(pattern + 1,
811810
basename + basenamelen - (patternlen - 1),
812811
patternlen - 1))
813812
return 1;
@@ -844,7 +843,7 @@ int match_pathname(const char *pathname, int pathlen,
844843
*/
845844
if (pathlen < baselen + 1 ||
846845
(baselen && pathname[baselen] != '/') ||
847-
strncmp_icase(pathname, base, baselen))
846+
fspathncmp(pathname, base, baselen))
848847
return 0;
849848

850849
namelen = baselen ? pathlen - baselen - 1 : pathlen;
@@ -858,7 +857,7 @@ int match_pathname(const char *pathname, int pathlen,
858857
if (prefix > namelen)
859858
return 0;
860859

861-
if (strncmp_icase(pattern, name, prefix))
860+
if (fspathncmp(pattern, name, prefix))
862861
return 0;
863862
pattern += prefix;
864863
patternlen -= prefix;

dir.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ extern int remove_dir_recursively(struct strbuf *path, int flag);
270270
/* tries to remove the path with empty directories along it, ignores ENOENT */
271271
extern int remove_path(const char *path);
272272

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);
275275
extern int fnmatch_icase(const char *pattern, const char *string, int flags);
276276

277277
/*

fast-import.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ static int tree_content_set(
15121512
t = root->tree;
15131513
for (i = 0; i < t->entry_count; i++) {
15141514
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)) {
15161516
if (!*slash1) {
15171517
if (!S_ISDIR(mode)
15181518
&& e->versions[1].mode == mode
@@ -1602,7 +1602,7 @@ static int tree_content_remove(
16021602
t = root->tree;
16031603
for (i = 0; i < t->entry_count; i++) {
16041604
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)) {
16061606
if (*slash1 && !S_ISDIR(e->versions[1].mode))
16071607
/*
16081608
* If p names a file in some subdirectory, and a
@@ -1669,7 +1669,7 @@ static int tree_content_get(
16691669
t = root->tree;
16701670
for (i = 0; i < t->entry_count; i++) {
16711671
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)) {
16731673
if (!*slash1)
16741674
goto found_entry;
16751675
if (!S_ISDIR(e->versions[1].mode))

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
301301
return -1;
302302
}
303303
}
304-
if (!strcmp_icase(ent->base, normalized_objdir)) {
304+
if (!fspathcmp(ent->base, normalized_objdir)) {
305305
free(ent);
306306
return -1;
307307
}

0 commit comments

Comments
 (0)