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.

281 lines
10KB

  1. #ifndef CONFIG_H
  2. #define CONFIG_H
  3. #include "hashmap.h"
  4. #include "string-list.h"
  5. struct object_id;
  6. /* git_config_parse_key() returns these negated: */
  7. #define CONFIG_INVALID_KEY 1
  8. #define CONFIG_NO_SECTION_OR_NAME 2
  9. /* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
  10. #define CONFIG_NO_LOCK -1
  11. #define CONFIG_INVALID_FILE 3
  12. #define CONFIG_NO_WRITE 4
  13. #define CONFIG_NOTHING_SET 5
  14. #define CONFIG_INVALID_PATTERN 6
  15. #define CONFIG_GENERIC_ERROR 7
  16. #define CONFIG_REGEX_NONE ((void *)1)
  17. struct git_config_source {
  18. unsigned int use_stdin:1;
  19. const char *file;
  20. const char *blob;
  21. };
  22. enum config_origin_type {
  23. CONFIG_ORIGIN_BLOB,
  24. CONFIG_ORIGIN_FILE,
  25. CONFIG_ORIGIN_STDIN,
  26. CONFIG_ORIGIN_SUBMODULE_BLOB,
  27. CONFIG_ORIGIN_CMDLINE
  28. };
  29. enum config_event_t {
  30. CONFIG_EVENT_SECTION,
  31. CONFIG_EVENT_ENTRY,
  32. CONFIG_EVENT_WHITESPACE,
  33. CONFIG_EVENT_COMMENT,
  34. CONFIG_EVENT_EOF,
  35. CONFIG_EVENT_ERROR
  36. };
  37. /*
  38. * The parser event function (if not NULL) is called with the event type and
  39. * the begin/end offsets of the parsed elements.
  40. *
  41. * Note: for CONFIG_EVENT_ENTRY (i.e. config variables), the trailing newline
  42. * character is considered part of the element.
  43. */
  44. typedef int (*config_parser_event_fn_t)(enum config_event_t type,
  45. size_t begin_offset, size_t end_offset,
  46. void *event_fn_data);
  47. struct config_options {
  48. unsigned int respect_includes : 1;
  49. unsigned int ignore_repo : 1;
  50. unsigned int ignore_worktree : 1;
  51. unsigned int ignore_cmdline : 1;
  52. unsigned int system_gently : 1;
  53. const char *commondir;
  54. const char *git_dir;
  55. config_parser_event_fn_t event_fn;
  56. void *event_fn_data;
  57. enum config_error_action {
  58. CONFIG_ERROR_UNSET = 0, /* use source-specific default */
  59. CONFIG_ERROR_DIE, /* die() on error */
  60. CONFIG_ERROR_ERROR, /* error() on error, return -1 */
  61. CONFIG_ERROR_SILENT, /* return -1 */
  62. } error_action;
  63. };
  64. typedef int (*config_fn_t)(const char *, const char *, void *);
  65. int git_default_config(const char *, const char *, void *);
  66. int git_config_from_file(config_fn_t fn, const char *, void *);
  67. int git_config_from_file_with_options(config_fn_t fn, const char *,
  68. void *,
  69. const struct config_options *);
  70. int git_config_from_mem(config_fn_t fn,
  71. const enum config_origin_type,
  72. const char *name,
  73. const char *buf, size_t len,
  74. void *data, const struct config_options *opts);
  75. int git_config_from_blob_oid(config_fn_t fn, const char *name,
  76. const struct object_id *oid, void *data);
  77. void git_config_push_parameter(const char *text);
  78. int git_config_from_parameters(config_fn_t fn, void *data);
  79. void read_early_config(config_fn_t cb, void *data);
  80. void read_very_early_config(config_fn_t cb, void *data);
  81. void git_config(config_fn_t fn, void *);
  82. int config_with_options(config_fn_t fn, void *,
  83. struct git_config_source *config_source,
  84. const struct config_options *opts);
  85. int git_parse_ssize_t(const char *, ssize_t *);
  86. int git_parse_ulong(const char *, unsigned long *);
  87. int git_parse_maybe_bool(const char *);
  88. int git_config_int(const char *, const char *);
  89. int64_t git_config_int64(const char *, const char *);
  90. unsigned long git_config_ulong(const char *, const char *);
  91. ssize_t git_config_ssize_t(const char *, const char *);
  92. int git_config_bool_or_int(const char *, const char *, int *);
  93. int git_config_bool(const char *, const char *);
  94. int git_config_string(const char **, const char *, const char *);
  95. int git_config_pathname(const char **, const char *, const char *);
  96. int git_config_expiry_date(timestamp_t *, const char *, const char *);
  97. int git_config_color(char *, const char *, const char *);
  98. int git_config_set_in_file_gently(const char *, const char *, const char *);
  99. void git_config_set_in_file(const char *, const char *, const char *);
  100. int git_config_set_gently(const char *, const char *);
  101. void git_config_set(const char *, const char *);
  102. int git_config_parse_key(const char *, char **, int *);
  103. int git_config_key_is_valid(const char *key);
  104. int git_config_set_multivar_gently(const char *, const char *, const char *, int);
  105. void git_config_set_multivar(const char *, const char *, const char *, int);
  106. int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
  107. void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
  108. int git_config_rename_section(const char *, const char *);
  109. int git_config_rename_section_in_file(const char *, const char *, const char *);
  110. int git_config_copy_section(const char *, const char *);
  111. int git_config_copy_section_in_file(const char *, const char *, const char *);
  112. const char *git_etc_gitconfig(void);
  113. int git_env_bool(const char *, int);
  114. unsigned long git_env_ulong(const char *, unsigned long);
  115. int git_config_system(void);
  116. int config_error_nonbool(const char *);
  117. #if defined(__GNUC__)
  118. #define config_error_nonbool(s) (config_error_nonbool(s), const_error())
  119. #endif
  120. int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
  121. enum config_scope {
  122. CONFIG_SCOPE_UNKNOWN = 0,
  123. CONFIG_SCOPE_SYSTEM,
  124. CONFIG_SCOPE_GLOBAL,
  125. CONFIG_SCOPE_REPO,
  126. CONFIG_SCOPE_CMDLINE,
  127. };
  128. enum config_scope current_config_scope(void);
  129. const char *current_config_origin_type(void);
  130. const char *current_config_name(void);
  131. struct config_include_data {
  132. int depth;
  133. config_fn_t fn;
  134. void *data;
  135. const struct config_options *opts;
  136. };
  137. #define CONFIG_INCLUDE_INIT { 0 }
  138. int git_config_include(const char *name, const char *value, void *data);
  139. /*
  140. * Match and parse a config key of the form:
  141. *
  142. * section.(subsection.)?key
  143. *
  144. * (i.e., what gets handed to a config_fn_t). The caller provides the section;
  145. * we return -1 if it does not match, 0 otherwise. The subsection and key
  146. * out-parameters are filled by the function (and *subsection is NULL if it is
  147. * missing).
  148. *
  149. * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
  150. * there is no subsection at all.
  151. */
  152. int parse_config_key(const char *var,
  153. const char *section,
  154. const char **subsection, int *subsection_len,
  155. const char **key);
  156. struct config_set_element {
  157. struct hashmap_entry ent;
  158. char *key;
  159. struct string_list value_list;
  160. };
  161. struct configset_list_item {
  162. struct config_set_element *e;
  163. int value_index;
  164. };
  165. /*
  166. * the contents of the list are ordered according to their
  167. * position in the config files and order of parsing the files.
  168. * (i.e. key-value pair at the last position of .git/config will
  169. * be at the last item of the list)
  170. */
  171. struct configset_list {
  172. struct configset_list_item *items;
  173. unsigned int nr, alloc;
  174. };
  175. struct config_set {
  176. struct hashmap config_hash;
  177. int hash_initialized;
  178. struct configset_list list;
  179. };
  180. void git_configset_init(struct config_set *cs);
  181. int git_configset_add_file(struct config_set *cs, const char *filename);
  182. const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
  183. void git_configset_clear(struct config_set *cs);
  184. /*
  185. * These functions return 1 if not found, and 0 if found, leaving the found
  186. * value in the 'dest' pointer.
  187. */
  188. int git_configset_get_value(struct config_set *cs, const char *key, const char **dest);
  189. int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
  190. int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
  191. int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
  192. int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
  193. int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
  194. int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
  195. int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
  196. int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
  197. /* Functions for reading a repository's config */
  198. struct repository;
  199. void repo_config(struct repository *repo, config_fn_t fn, void *data);
  200. int repo_config_get_value(struct repository *repo,
  201. const char *key, const char **value);
  202. const struct string_list *repo_config_get_value_multi(struct repository *repo,
  203. const char *key);
  204. int repo_config_get_string_const(struct repository *repo,
  205. const char *key, const char **dest);
  206. int repo_config_get_string(struct repository *repo,
  207. const char *key, char **dest);
  208. int repo_config_get_int(struct repository *repo,
  209. const char *key, int *dest);
  210. int repo_config_get_ulong(struct repository *repo,
  211. const char *key, unsigned long *dest);
  212. int repo_config_get_bool(struct repository *repo,
  213. const char *key, int *dest);
  214. int repo_config_get_bool_or_int(struct repository *repo,
  215. const char *key, int *is_bool, int *dest);
  216. int repo_config_get_maybe_bool(struct repository *repo,
  217. const char *key, int *dest);
  218. int repo_config_get_pathname(struct repository *repo,
  219. const char *key, const char **dest);
  220. int git_config_get_value(const char *key, const char **value);
  221. const struct string_list *git_config_get_value_multi(const char *key);
  222. void git_config_clear(void);
  223. int git_config_get_string_const(const char *key, const char **dest);
  224. int git_config_get_string(const char *key, char **dest);
  225. int git_config_get_int(const char *key, int *dest);
  226. int git_config_get_ulong(const char *key, unsigned long *dest);
  227. int git_config_get_bool(const char *key, int *dest);
  228. int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
  229. int git_config_get_maybe_bool(const char *key, int *dest);
  230. int git_config_get_pathname(const char *key, const char **dest);
  231. int git_config_get_index_threads(int *dest);
  232. int git_config_get_untracked_cache(void);
  233. int git_config_get_split_index(void);
  234. int git_config_get_max_percent_split_change(void);
  235. int git_config_get_fsmonitor(void);
  236. /* This dies if the configured or default date is in the future */
  237. int git_config_get_expiry(const char *key, const char **output);
  238. /* parse either "this many days" integer, or "5.days.ago" approxidate */
  239. int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
  240. struct key_value_info {
  241. const char *filename;
  242. int linenr;
  243. enum config_origin_type origin_type;
  244. enum config_scope scope;
  245. };
  246. NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
  247. NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
  248. #define LOOKUP_CONFIG(mapping, var) \
  249. lookup_config(mapping, ARRAY_SIZE(mapping), var)
  250. int lookup_config(const char **mapping, int nr_mapping, const char *var);
  251. #endif /* CONFIG_H */