builtin/commit.c: extract ignore_non_trailer() helper function
[gitweb.git] / pathspec.h
index 987d70c55a2e68662609b0ed3b7507dda2170913..a75e9242d1bea7e9318426d6786bd5eae9dc6215 100644 (file)
@@ -5,12 +5,16 @@
 #define PATHSPEC_FROMTOP       (1<<0)
 #define PATHSPEC_MAXDEPTH      (1<<1)
 #define PATHSPEC_LITERAL       (1<<2)
+#define PATHSPEC_GLOB          (1<<3)
+#define PATHSPEC_ICASE         (1<<4)
 #define PATHSPEC_ALL_MAGIC       \
        (PATHSPEC_FROMTOP       | \
         PATHSPEC_MAXDEPTH      | \
-        PATHSPEC_LITERAL)
+        PATHSPEC_LITERAL       | \
+        PATHSPEC_GLOB          | \
+        PATHSPEC_ICASE)
 
-#define PATHSPEC_ONESTAR 1     /* the pathspec pattern sastisfies GFNM_ONESTAR */
+#define PATHSPEC_ONESTAR 1     /* the pathspec pattern satisfies GFNM_ONESTAR */
 
 struct pathspec {
        const char **_raw; /* get_pathspec() result, not freed by free_pathspec() */
@@ -54,6 +58,13 @@ struct pathspec {
 #define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<5)
 #define PATHSPEC_PREFIX_ORIGIN (1<<6)
 #define PATHSPEC_KEEP_ORDER (1<<7)
+/*
+ * For the callers that just need pure paths from somewhere else, not
+ * from command line. Global --*-pathspecs options are ignored. No
+ * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is
+ * allowed, then it will automatically set for every pathspec.
+ */
+#define PATHSPEC_LITERAL_PATH (1<<8)
 
 extern void parse_pathspec(struct pathspec *pathspec,
                           unsigned magic_mask,
@@ -63,6 +74,24 @@ extern void parse_pathspec(struct pathspec *pathspec,
 extern void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
 extern void free_pathspec(struct pathspec *);
 
+static inline int ps_strncmp(const struct pathspec_item *item,
+                            const char *s1, const char *s2, size_t n)
+{
+       if (item->magic & PATHSPEC_ICASE)
+               return strncasecmp(s1, s2, n);
+       else
+               return strncmp(s1, s2, n);
+}
+
+static inline int ps_strcmp(const struct pathspec_item *item,
+                           const char *s1, const char *s2)
+{
+       if (item->magic & PATHSPEC_ICASE)
+               return strcasecmp(s1, s2);
+       else
+               return strcmp(s1, s2);
+}
+
 extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec);
 extern void add_pathspec_matches_against_index(const struct pathspec *pathspec, char *seen);
 extern const char *check_path_for_gitlink(const char *path);