THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.3KB

  1. #ifndef PATHSPEC_H
  2. #define PATHSPEC_H
  3. struct index_state;
  4. /* Pathspec magic */
  5. #define PATHSPEC_FROMTOP (1<<0)
  6. #define PATHSPEC_MAXDEPTH (1<<1)
  7. #define PATHSPEC_LITERAL (1<<2)
  8. #define PATHSPEC_GLOB (1<<3)
  9. #define PATHSPEC_ICASE (1<<4)
  10. #define PATHSPEC_EXCLUDE (1<<5)
  11. #define PATHSPEC_ATTR (1<<6)
  12. #define PATHSPEC_ALL_MAGIC \
  13. (PATHSPEC_FROMTOP | \
  14. PATHSPEC_MAXDEPTH | \
  15. PATHSPEC_LITERAL | \
  16. PATHSPEC_GLOB | \
  17. PATHSPEC_ICASE | \
  18. PATHSPEC_EXCLUDE | \
  19. PATHSPEC_ATTR)
  20. #define PATHSPEC_ONESTAR 1 /* the pathspec pattern satisfies GFNM_ONESTAR */
  21. struct pathspec {
  22. int nr;
  23. unsigned int has_wildcard:1;
  24. unsigned int recursive:1;
  25. unsigned int recurse_submodules:1;
  26. unsigned magic;
  27. int max_depth;
  28. struct pathspec_item {
  29. char *match;
  30. char *original;
  31. unsigned magic;
  32. int len, prefix;
  33. int nowildcard_len;
  34. int flags;
  35. int attr_match_nr;
  36. struct attr_match {
  37. char *value;
  38. enum attr_match_mode {
  39. MATCH_SET,
  40. MATCH_UNSET,
  41. MATCH_VALUE,
  42. MATCH_UNSPECIFIED
  43. } match_mode;
  44. } *attr_match;
  45. struct attr_check *attr_check;
  46. } *items;
  47. };
  48. #define GUARD_PATHSPEC(ps, mask) \
  49. do { \
  50. if ((ps)->magic & ~(mask)) \
  51. die("BUG:%s:%d: unsupported magic %x", \
  52. __FILE__, __LINE__, (ps)->magic & ~(mask)); \
  53. } while (0)
  54. /* parse_pathspec flags */
  55. #define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */
  56. #define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */
  57. #define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
  58. /* die if a symlink is part of the given path's directory */
  59. #define PATHSPEC_SYMLINK_LEADING_PATH (1<<3)
  60. #define PATHSPEC_PREFIX_ORIGIN (1<<4)
  61. #define PATHSPEC_KEEP_ORDER (1<<5)
  62. /*
  63. * For the callers that just need pure paths from somewhere else, not
  64. * from command line. Global --*-pathspecs options are ignored. No
  65. * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is
  66. * allowed, then it will automatically set for every pathspec.
  67. */
  68. #define PATHSPEC_LITERAL_PATH (1<<6)
  69. /*
  70. * Given command line arguments and a prefix, convert the input to
  71. * pathspec. die() if any magic in magic_mask is used.
  72. *
  73. * Any arguments used are copied. It is safe for the caller to modify
  74. * or free 'prefix' and 'args' after calling this function.
  75. */
  76. void parse_pathspec(struct pathspec *pathspec,
  77. unsigned magic_mask,
  78. unsigned flags,
  79. const char *prefix,
  80. const char **args);
  81. void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
  82. void clear_pathspec(struct pathspec *);
  83. static inline int ps_strncmp(const struct pathspec_item *item,
  84. const char *s1, const char *s2, size_t n)
  85. {
  86. if (item->magic & PATHSPEC_ICASE)
  87. return strncasecmp(s1, s2, n);
  88. else
  89. return strncmp(s1, s2, n);
  90. }
  91. static inline int ps_strcmp(const struct pathspec_item *item,
  92. const char *s1, const char *s2)
  93. {
  94. if (item->magic & PATHSPEC_ICASE)
  95. return strcasecmp(s1, s2);
  96. else
  97. return strcmp(s1, s2);
  98. }
  99. void add_pathspec_matches_against_index(const struct pathspec *pathspec,
  100. const struct index_state *istate,
  101. char *seen);
  102. char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
  103. const struct index_state *istate);
  104. int match_pathspec_attrs(const struct index_state *istate,
  105. const char *name, int namelen,
  106. const struct pathspec_item *item);
  107. #endif /* PATHSPEC_H */