]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pathspec.c
Merge branch 'en/rebase-merge-on-sequencer'
[thirdparty/git.git] / pathspec.c
index 6f005996fdc8f3e412b0faafc12e65aed359be3b..e85298f68cfeee14494466b0604e572a5c345810 100644 (file)
@@ -659,3 +659,41 @@ void clear_pathspec(struct pathspec *pathspec)
        FREE_AND_NULL(pathspec->items);
        pathspec->nr = 0;
 }
+
+int match_pathspec_attrs(const struct index_state *istate,
+                        const char *name, int namelen,
+                        const struct pathspec_item *item)
+{
+       int i;
+       char *to_free = NULL;
+
+       if (name[namelen])
+               name = to_free = xmemdupz(name, namelen);
+
+       git_check_attr(istate, name, item->attr_check);
+
+       free(to_free);
+
+       for (i = 0; i < item->attr_match_nr; i++) {
+               const char *value;
+               int matched;
+               enum attr_match_mode match_mode;
+
+               value = item->attr_check->items[i].value;
+               match_mode = item->attr_match[i].match_mode;
+
+               if (ATTR_TRUE(value))
+                       matched = (match_mode == MATCH_SET);
+               else if (ATTR_FALSE(value))
+                       matched = (match_mode == MATCH_UNSET);
+               else if (ATTR_UNSET(value))
+                       matched = (match_mode == MATCH_UNSPECIFIED);
+               else
+                       matched = (match_mode == MATCH_VALUE &&
+                                  !strcmp(item->attr_match[i].value, value));
+               if (!matched)
+                       return 0;
+       }
+
+       return 1;
+}