/*
* This handles recursive filename detection with exclude
* files, index knowledge etc..
*
* Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006
*/
#include "cache.h"
#include "dir.h"
#include "refs.h"
struct path_simplify {
int len;
const char *path;
};
static int read_directory_recursive(struct dir_struct *dir, const char *path, int len,
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)
{
return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
}
int strncmp_icase(const char *a, const char *b, size_t count)
{
return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
}
int fnmatch_icase(const char *pattern, const char *string, int flags)
{
return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0));
}
static size_t common_prefix_len(const char **pathspec)
{
const char *n, *first;
size_t max = 0;
if (!pathspec)
return max;
first = *pathspec;
while ((n = *pathspec++)) {
size_t i, len = 0;
for (i = 0; first == n || i < max; i++) {
char c = n[i];
if (!c || c != first[i] || is_glob_special(c))
break;
if (c == '/')
len = i + 1;
}
if (first == n || len < max) {
max = len;
if (!max)
break;
}
}
return max;
}
/*
* Returns a copy of the longest leading path common among all
* pathspecs.
*/
char *common_prefix(const char **pathspec)
{
unsigned long len = common_prefix_len(pathspec);
return len ? xmemdupz(*pathspec,
|