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 <sxlijin@xxxxxxxxx> --- dir.c | 10 +++++----- dir.h | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dir.c b/dir.c index 214a148ee..1bf2d20e7 100644 --- a/dir.c +++ b/dir.c @@ -1844,7 +1844,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, return dir_state; } -static int cmp_name(const void *p1, const void *p2) +int cmp_dir_entry(const void *p1, const void *p2) { const struct dir_entry *e1 = *(const struct dir_entry **)p1; const struct dir_entry *e2 = *(const struct dir_entry **)p2; @@ -1853,7 +1853,7 @@ static int cmp_name(const void *p1, const void *p2) } /* check if *out lexically contains *in */ -static int check_contains(const struct dir_entry *out, const struct dir_entry *in) +int check_dir_entry_contains(const struct dir_entry *out, const struct dir_entry *in) { return (out->len < in->len) && (out->name[out->len - 1] == '/') && @@ -2073,8 +2073,8 @@ int read_directory(struct dir_struct *dir, const char *path, dir->untracked = NULL; if (!len || treat_leading_path(dir, path, len, pathspec)) read_directory_recursive(dir, path, len, untracked, 0, pathspec); - QSORT(dir->entries, dir->nr, cmp_name); - QSORT(dir->ignored, dir->ignored_nr, cmp_name); + QSORT(dir->entries, dir->nr, cmp_dir_entry); + QSORT(dir->ignored, dir->ignored_nr, cmp_dir_entry); // if DIR_SHOW_IGNORED_TOO, read_directory_recursive() will also pick // up untracked contents of untracked dirs; by default we discard these, @@ -2091,7 +2091,7 @@ int read_directory(struct dir_struct *dir, const char *path, for (j = i + 1; j < dir->nr; j++) { if (!dir->entries[j]) continue; - if (check_contains(dir->entries[i], dir->entries[j])) { + if (check_dir_entry_contains(dir->entries[i], dir->entries[j])) { nr_removed++; free(dir->entries[j]); dir->entries[j] = NULL; diff --git a/dir.h b/dir.h index 650e54bdf..edb5fda58 100644 --- a/dir.h +++ b/dir.h @@ -327,6 +327,9 @@ static inline int dir_path_match(const struct dir_entry *ent, has_trailing_dir); } +int cmp_dir_entry(const void *p1, const void *p2); +int check_dir_entry_contains(const struct dir_entry *out, const struct dir_entry *in); + void untracked_cache_invalidate_path(struct index_state *, const char *); void untracked_cache_remove_from_index(struct index_state *, const char *); void untracked_cache_add_to_index(struct index_state *, const char *); -- 2.12.2