list-objects-filter-options.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef LIST_OBJECTS_FILTER_OPTIONS_H
  2. #define LIST_OBJECTS_FILTER_OPTIONS_H
  3. #include "parse-options.h"
  4. #include "string-list.h"
  5. /*
  6. * The list of defined filters for list-objects.
  7. */
  8. enum list_objects_filter_choice {
  9. LOFC_DISABLED = 0,
  10. LOFC_BLOB_NONE,
  11. LOFC_BLOB_LIMIT,
  12. LOFC_TREE_DEPTH,
  13. LOFC_SPARSE_OID,
  14. LOFC_COMBINE,
  15. LOFC__COUNT /* must be last */
  16. };
  17. /*
  18. * Returns a configuration key suitable for describing the given object filter,
  19. * e.g.: "blob:none", "combine", etc.
  20. */
  21. const char *list_object_filter_config_name(enum list_objects_filter_choice c);
  22. struct list_objects_filter_options {
  23. /*
  24. * 'filter_spec' is the raw argument value given on the command line
  25. * or protocol request. (The part after the "--keyword=".) For
  26. * commands that launch filtering sub-processes, or for communication
  27. * over the network, don't use this value; use the result of
  28. * expand_list_objects_filter_spec() instead.
  29. * To get the raw filter spec given by the user, use the result of
  30. * list_objects_filter_spec().
  31. */
  32. struct string_list filter_spec;
  33. /*
  34. * 'choice' is determined by parsing the filter-spec. This indicates
  35. * the filtering algorithm to use.
  36. */
  37. enum list_objects_filter_choice choice;
  38. /*
  39. * Choice is LOFC_DISABLED because "--no-filter" was requested.
  40. */
  41. unsigned int no_filter : 1;
  42. /*
  43. * BEGIN choice-specific parsed values from within the filter-spec. Only
  44. * some values will be defined for any given choice.
  45. */
  46. char *sparse_oid_name;
  47. unsigned long blob_limit_value;
  48. unsigned long tree_exclude_depth;
  49. /* LOFC_COMBINE values */
  50. /* This array contains all the subfilters which this filter combines. */
  51. size_t sub_nr, sub_alloc;
  52. struct list_objects_filter_options *sub;
  53. /*
  54. * END choice-specific parsed values.
  55. */
  56. };
  57. /* Normalized command line arguments */
  58. #define CL_ARG__FILTER "filter"
  59. void list_objects_filter_die_if_populated(
  60. struct list_objects_filter_options *filter_options);
  61. /*
  62. * Parses the filter spec string given by arg and either (1) simply places the
  63. * result in filter_options if it is not yet populated or (2) combines it with
  64. * the filter already in filter_options if it is already populated. In the case
  65. * of (2), the filter specs are combined as if specified with 'combine:'.
  66. *
  67. * Dies and prints a user-facing message if an error occurs.
  68. */
  69. void parse_list_objects_filter(
  70. struct list_objects_filter_options *filter_options,
  71. const char *arg);
  72. int opt_parse_list_objects_filter(const struct option *opt,
  73. const char *arg, int unset);
  74. #define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
  75. OPT_CALLBACK(0, CL_ARG__FILTER, fo, N_("args"), \
  76. N_("object filtering"), \
  77. opt_parse_list_objects_filter)
  78. /*
  79. * Translates abbreviated numbers in the filter's filter_spec into their
  80. * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024").
  81. * Returns a string owned by the list_objects_filter_options object.
  82. *
  83. * This form should be used instead of the raw list_objects_filter_spec()
  84. * value when communicating with a remote process or subprocess.
  85. */
  86. const char *expand_list_objects_filter_spec(
  87. struct list_objects_filter_options *filter);
  88. /*
  89. * Returns the filter spec string more or less in the form as the user
  90. * entered it. This form of the filter_spec can be used in user-facing
  91. * messages. Returns a string owned by the list_objects_filter_options
  92. * object.
  93. */
  94. const char *list_objects_filter_spec(
  95. struct list_objects_filter_options *filter);
  96. void list_objects_filter_release(
  97. struct list_objects_filter_options *filter_options);
  98. static inline void list_objects_filter_set_no_filter(
  99. struct list_objects_filter_options *filter_options)
  100. {
  101. list_objects_filter_release(filter_options);
  102. filter_options->no_filter = 1;
  103. }
  104. void partial_clone_register(
  105. const char *remote,
  106. struct list_objects_filter_options *filter_options);
  107. void partial_clone_get_default_filter_spec(
  108. struct list_objects_filter_options *filter_options,
  109. const char *remote);
  110. #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */