]> git.proxmox.com Git - libgit2.git/blame - src/config.h
patch: use strlen to mean string length
[libgit2.git] / src / config.h
CommitLineData
bb742ede 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
bb742ede
VM
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
6d7bb4e0
CMN
7#ifndef INCLUDE_config_h__
8#define INCLUDE_config_h__
9
c0335005 10#include "git2.h"
6d7bb4e0 11#include "git2/config.h"
c0335005 12#include "vector.h"
44daec42 13#include "repository.h"
6b45cb8a 14
8c7c5fa5 15#define GIT_CONFIG_FILENAME_PROGRAMDATA "config"
73b51450 16#define GIT_CONFIG_FILENAME_SYSTEM "gitconfig"
5540d947
RB
17#define GIT_CONFIG_FILENAME_GLOBAL ".gitconfig"
18#define GIT_CONFIG_FILENAME_XDG "config"
19
20#define GIT_CONFIG_FILENAME_INREPO "config"
01ad7b3a 21#define GIT_CONFIG_FILE_MODE 0666
8adbf2ed 22
5d4cd003 23struct git_config {
9462c471 24 git_refcount rc;
b0b527e0 25 git_vector files;
5d4cd003
CMN
26};
27
a4b75dcf
CMN
28extern int git_config__global_location(git_buf *buf);
29
aba70781 30extern int git_config_rename_section(
31 git_repository *repo,
32 const char *old_section_name, /* eg "branch.dummy" */
33 const char *new_section_name); /* NULL to drop the old section */
34
d36451c9 35/**
36 * Create a configuration file backend for ondisk files
37 *
38 * These are the normal `.gitconfig` files that Core Git
39 * processes. Note that you first have to add this file to a
40 * configuration object before you can query it for configuration
41 * variables.
42 *
43 * @param out the new backend
44 * @param path where the config file is located
45 */
5173ea92 46extern int git_config_file__ondisk(git_config_backend **out, const char *path);
d36451c9 47
f4be8209
CMN
48extern int git_config__normalize_name(const char *in, char **out);
49
9f77b3f6
RB
50/* internal only: does not normalize key and sets out to NULL if not found */
51extern int git_config__lookup_entry(
9a97f49e 52 git_config_entry **out,
9f77b3f6
RB
53 const git_config *cfg,
54 const char *key,
55 bool no_errors);
56
8286300a
RB
57/* internal only: update and/or delete entry string with constraints */
58extern int git_config__update_entry(
59 git_config *cfg,
60 const char *key,
61 const char *value,
62 bool overwrite_existing,
63 bool only_if_existing);
64
9f77b3f6
RB
65/*
66 * Lookup functions that cannot fail. These functions look up a config
67 * value and return a fallback value if the value is missing or if any
68 * failures occur while trying to access the value.
69 */
70
9a97f49e 71extern char *git_config__get_string_force(
9f77b3f6
RB
72 const git_config *cfg, const char *key, const char *fallback_value);
73
74extern int git_config__get_bool_force(
75 const git_config *cfg, const char *key, int fallback_value);
76
77extern int git_config__get_int_force(
78 const git_config *cfg, const char *key, int fallback_value);
f4be8209 79
2b52a0bf
RB
80/* API for repository cvar-style lookups from config - not cached, but
81 * uses cvar value maps and fallbacks
82 */
83extern int git_config__cvar(
84 int *out, git_config *config, git_cvar_cached cvar);
85
15c38103
CMN
86/**
87 * The opposite of git_config_lookup_map_value, we take an enum value
88 * and map it to the string or bool value on the config.
89 */
90int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
91 const git_cvar_map *maps, size_t map_n, int enum_val);
5340d63d
CMN
92
93/**
94 * Unlock the backend with the highest priority
95 *
96 * Unlocking will allow other writers to updat the configuration
97 * file. Optionally, any changes performed since the lock will be
98 * applied to the configuration.
99 *
100 * @param cfg the configuration
101 * @param commit boolean which indicates whether to commit any changes
102 * done since locking
103 * @return 0 or an error code
104 */
105GIT_EXTERN(int) git_config_unlock(git_config *cfg, int commit);
106
5d4cd003 107#endif