Skip to content

Commit bbf504a

Browse files
Samuel Lijingitster
authored andcommitted
dir: expose cmp_name() and check_contains()
We want to use cmp_name() and check_contains() (which both compare `struct dir_entry`s, the former in terms of the sort order, the latter in terms of whether one lexically contains another) outside of dir.c, so we have to (1) change their linkage and (2) rename them as appropriate for the global namespace. The second is achieved by renaming cmp_name() to cmp_dir_entry() and check_contains() to check_dir_entry_contains(). Signed-off-by: Samuel Lijin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb89888 commit bbf504a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

dir.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
18051805
return dir_state;
18061806
}
18071807

1808-
static int cmp_name(const void *p1, const void *p2)
1808+
int cmp_dir_entry(const void *p1, const void *p2)
18091809
{
18101810
const struct dir_entry *e1 = *(const struct dir_entry **)p1;
18111811
const struct dir_entry *e2 = *(const struct dir_entry **)p2;
@@ -1814,7 +1814,7 @@ static int cmp_name(const void *p1, const void *p2)
18141814
}
18151815

18161816
/* check if *out lexically strictly contains *in */
1817-
static int check_contains(const struct dir_entry *out, const struct dir_entry *in)
1817+
int check_dir_entry_contains(const struct dir_entry *out, const struct dir_entry *in)
18181818
{
18191819
return (out->len < in->len) &&
18201820
(out->name[out->len - 1] == '/') &&
@@ -2034,8 +2034,8 @@ int read_directory(struct dir_struct *dir, const char *path,
20342034
dir->untracked = NULL;
20352035
if (!len || treat_leading_path(dir, path, len, pathspec))
20362036
read_directory_recursive(dir, path, len, untracked, 0, pathspec);
2037-
QSORT(dir->entries, dir->nr, cmp_name);
2038-
QSORT(dir->ignored, dir->ignored_nr, cmp_name);
2037+
QSORT(dir->entries, dir->nr, cmp_dir_entry);
2038+
QSORT(dir->ignored, dir->ignored_nr, cmp_dir_entry);
20392039

20402040
/*
20412041
* If DIR_SHOW_IGNORED_TOO is set, read_directory_recursive() will
@@ -2048,7 +2048,8 @@ int read_directory(struct dir_struct *dir, const char *path,
20482048

20492049
/* remove from dir->entries untracked contents of untracked dirs */
20502050
for (i = j = 0; j < dir->nr; j++) {
2051-
if (i && check_contains(dir->entries[i - 1], dir->entries[j])) {
2051+
if (i &&
2052+
check_dir_entry_contains(dir->entries[i - 1], dir->entries[j])) {
20522053
free(dir->entries[j]);
20532054
dir->entries[j] = NULL;
20542055
} else {

dir.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ static inline int dir_path_match(const struct dir_entry *ent,
327327
has_trailing_dir);
328328
}
329329

330+
int cmp_dir_entry(const void *p1, const void *p2);
331+
int check_dir_entry_contains(const struct dir_entry *out, const struct dir_entry *in);
332+
330333
void untracked_cache_invalidate_path(struct index_state *, const char *);
331334
void untracked_cache_remove_from_index(struct index_state *, const char *);
332335
void untracked_cache_add_to_index(struct index_state *, const char *);

0 commit comments

Comments
 (0)