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.

153 lines
4.6KB

  1. #ifndef REF_FILTER_H
  2. #define REF_FILTER_H
  3. #include "sha1-array.h"
  4. #include "refs.h"
  5. #include "commit.h"
  6. #include "parse-options.h"
  7. /* Quoting styles */
  8. #define QUOTE_NONE 0
  9. #define QUOTE_SHELL 1
  10. #define QUOTE_PERL 2
  11. #define QUOTE_PYTHON 4
  12. #define QUOTE_TCL 8
  13. #define FILTER_REFS_INCLUDE_BROKEN 0x0001
  14. #define FILTER_REFS_TAGS 0x0002
  15. #define FILTER_REFS_BRANCHES 0x0004
  16. #define FILTER_REFS_REMOTES 0x0008
  17. #define FILTER_REFS_OTHERS 0x0010
  18. #define FILTER_REFS_ALL (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \
  19. FILTER_REFS_REMOTES | FILTER_REFS_OTHERS)
  20. #define FILTER_REFS_DETACHED_HEAD 0x0020
  21. #define FILTER_REFS_KIND_MASK (FILTER_REFS_ALL | FILTER_REFS_DETACHED_HEAD)
  22. struct atom_value;
  23. struct ref_sorting {
  24. struct ref_sorting *next;
  25. int atom; /* index into used_atom array (internal) */
  26. unsigned reverse : 1,
  27. ignore_case : 1,
  28. version : 1;
  29. };
  30. struct ref_array_item {
  31. struct object_id objectname;
  32. int flag;
  33. unsigned int kind;
  34. const char *symref;
  35. struct commit *commit;
  36. struct atom_value *value;
  37. char refname[FLEX_ARRAY];
  38. };
  39. struct ref_array {
  40. int nr, alloc;
  41. struct ref_array_item **items;
  42. struct rev_info *revs;
  43. };
  44. struct ref_filter {
  45. const char **name_patterns;
  46. struct oid_array points_at;
  47. struct commit_list *with_commit;
  48. struct commit_list *no_commit;
  49. enum {
  50. REF_FILTER_MERGED_NONE = 0,
  51. REF_FILTER_MERGED_INCLUDE,
  52. REF_FILTER_MERGED_OMIT
  53. } merge;
  54. struct commit *merge_commit;
  55. unsigned int with_commit_tag_algo : 1,
  56. match_as_path : 1,
  57. ignore_case : 1,
  58. detached : 1;
  59. unsigned int kind,
  60. lines;
  61. int abbrev,
  62. verbose;
  63. };
  64. struct ref_format {
  65. /*
  66. * Set these to define the format; make sure you call
  67. * verify_ref_format() afterwards to finalize.
  68. */
  69. const char *format;
  70. int quote_style;
  71. int use_color;
  72. /* Internal state to ref-filter */
  73. int need_color_reset_at_eol;
  74. };
  75. #define REF_FORMAT_INIT { NULL, 0, -1 }
  76. /* Macros for checking --merged and --no-merged options */
  77. #define _OPT_MERGED_NO_MERGED(option, filter, h) \
  78. { OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
  79. PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
  80. parse_opt_merge_filter, (intptr_t) "HEAD" \
  81. }
  82. #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
  83. #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
  84. #define OPT_REF_SORT(var) \
  85. OPT_CALLBACK_F(0, "sort", (var), \
  86. N_("key"), N_("field name to sort on"), \
  87. PARSE_OPT_NONEG, parse_opt_ref_sorting)
  88. /*
  89. * API for filtering a set of refs. Based on the type of refs the user
  90. * has requested, we iterate through those refs and apply filters
  91. * as per the given ref_filter structure and finally store the
  92. * filtered refs in the ref_array structure.
  93. */
  94. int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type);
  95. /* Clear all memory allocated to ref_array */
  96. void ref_array_clear(struct ref_array *array);
  97. /* Used to verify if the given format is correct and to parse out the used atoms */
  98. int verify_ref_format(struct ref_format *format);
  99. /* Sort the given ref_array as per the ref_sorting provided */
  100. void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
  101. /* Based on the given format and quote_style, fill the strbuf */
  102. int format_ref_array_item(struct ref_array_item *info,
  103. const struct ref_format *format,
  104. struct strbuf *final_buf,
  105. struct strbuf *error_buf);
  106. /* Print the ref using the given format and quote_style */
  107. void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
  108. /* Parse a single sort specifier and add it to the list */
  109. void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
  110. /* Callback function for parsing the sort option */
  111. int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
  112. /* Default sort option based on refname */
  113. struct ref_sorting *ref_default_sorting(void);
  114. /* Function to parse --merged and --no-merged options */
  115. int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
  116. /* Get the current HEAD's description */
  117. char *get_head_description(void);
  118. /* Set up translated strings in the output. */
  119. void setup_ref_filter_porcelain_msg(void);
  120. /*
  121. * Print a single ref, outside of any ref-filter. Note that the
  122. * name must be a fully qualified refname.
  123. */
  124. void pretty_print_ref(const char *name, const struct object_id *oid,
  125. const struct ref_format *format);
  126. /*
  127. * Push a single ref onto the array; this can be used to construct your own
  128. * ref_array without using filter_refs().
  129. */
  130. struct ref_array_item *ref_array_push(struct ref_array *array,
  131. const char *refname,
  132. const struct object_id *oid);
  133. #endif /* REF_FILTER_H */