[PATCH] Add a RPMBUILD make variable
[git.git] / read-cache.c
index 5a61bf7..f448ab1 100644 (file)
@@ -171,6 +171,30 @@ 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;
+       }
+       return 0;
+}
+
 /*
  * Do we have another file that has the beginning components being a
  * proper superset of the name we're trying to add?