X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=read-cache.c;h=ced597318e783ab08b73c88f8b724be51f3b3dec;hb=2f0f8b71ee45bcf91c2de480474a26030596fe3c;hp=5a61bf752bdc15f311215f91ea923f5422e8ad5c;hpb=b155725daeec48436d1fcbec4854ffd317408a6e;p=git.git diff --git a/read-cache.c b/read-cache.c index 5a61bf75..ced59731 100644 --- a/read-cache.c +++ b/read-cache.c @@ -171,6 +171,32 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b) return ce_namelen(b) == len && !memcmp(a->name, b->name, len); } +int ce_path_match(const struct cache_entry *ce, const char **pathspec) +{ + const char *match, *name; + int len; + + if (!pathspec) + return 1; + + len = ce_namelen(ce); + name = ce->name; + while ((match = *pathspec++) != NULL) { + int matchlen = strlen(match); + if (matchlen > len) + continue; + if (memcmp(name, match, matchlen)) + continue; + if (matchlen && name[matchlen-1] == '/') + return 1; + if (name[matchlen] == '/' || !name[matchlen]) + return 1; + if (!matchlen) + return 1; + } + return 0; +} + /* * Do we have another file that has the beginning components being a * proper superset of the name we're trying to add? @@ -368,7 +394,7 @@ int read_cache(void) return (errno == ENOENT) ? 0 : error("open failed"); size = 0; // avoid gcc warning - map = (void *)-1; + map = MAP_FAILED; if (!fstat(fd, &st)) { size = st.st_size; errno = EINVAL; @@ -376,7 +402,7 @@ int read_cache(void) map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); } close(fd); - if (-1 == (int)(long)map) + if (map == MAP_FAILED) return error("mmap failed"); hdr = map;