Typedef git_config_level_t and use it everywhere The GIT_CONFIG_LEVEL constants actually work well as an enum because they are mutually exclusive, so this adds a typedef to the enum and uses that everywhere that one of these constants are expected, instead of the old code that typically used an unsigned int.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
diff --git a/include/git2/config.h b/include/git2/config.h
index 8d1a1a5..518dcaf 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -27,18 +27,33 @@ GIT_BEGIN_DECL
* git_config_open_default() and git_repository_config() honor those
* priority levels as well.
*/
-enum {
- GIT_CONFIG_LEVEL_SYSTEM = 1, /**< System-wide configuration file. */
- GIT_CONFIG_LEVEL_XDG = 2, /**< XDG compatible configuration file (.config/git/config). */
- GIT_CONFIG_LEVEL_GLOBAL = 3, /**< User-specific configuration file, also called Global configuration file. */
- GIT_CONFIG_LEVEL_LOCAL = 4, /**< Repository specific configuration file. */
- GIT_CONFIG_HIGHEST_LEVEL = -1, /**< Represents the highest level of a config file. */
-};
+typedef enum {
+ /** System-wide configuration file; /etc/gitconfig on Linux systems */
+ GIT_CONFIG_LEVEL_SYSTEM = 1,
+
+ /** XDG compatible configuration file; typically ~/.config/git/config */
+ GIT_CONFIG_LEVEL_XDG = 2,
+
+ /** User-specific configuration file (also called Global configuration
+ * file); typically ~/.gitconfig
+ */
+ GIT_CONFIG_LEVEL_GLOBAL = 3,
+
+ /** Repository specific configuration file; $WORK_DIR/.git/config on
+ * non-bare repos
+ */
+ GIT_CONFIG_LEVEL_LOCAL = 4,
+
+ /** Represents the highest level available config file (i.e. the most
+ * specific config file available that actually is loaded)
+ */
+ GIT_CONFIG_HIGHEST_LEVEL = -1,
+} git_config_level_t;
typedef struct {
const char *name;
const char *value;
- unsigned int level;
+ git_config_level_t level;
} git_config_entry;
typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
@@ -155,7 +170,7 @@ GIT_EXTERN(int) git_config_new(git_config **out);
GIT_EXTERN(int) git_config_add_file_ondisk(
git_config *cfg,
const char *path,
- unsigned int level,
+ git_config_level_t level,
int force);
/**
@@ -192,7 +207,7 @@ GIT_EXTERN(int) git_config_open_ondisk(git_config **out, const char *path);
GIT_EXTERN(int) git_config_open_level(
git_config **out,
const git_config *parent,
- unsigned int level);
+ git_config_level_t level);
/**
* Open the global/XDG configuration file according to git's rules
@@ -241,7 +256,7 @@ GIT_EXTERN(void) git_config_free(git_config *cfg);
* @return 0 or an error code
*/
GIT_EXTERN(int) git_config_get_entry(
- const git_config_entry **out,
+ const git_config_entry **out,
const git_config *cfg,
const char *name);
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index 1c9deba..11e59cf 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -29,7 +29,7 @@ struct git_config_backend {
struct git_config *cfg;
/* Open means open the file/database and parse if necessary */
- int (*open)(struct git_config_backend *, unsigned int level);
+ int (*open)(struct git_config_backend *, git_config_level_t level);
int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
int (*set)(struct git_config_backend *, const char *key, const char *value);
@@ -63,7 +63,7 @@ struct git_config_backend {
GIT_EXTERN(int) git_config_add_backend(
git_config *cfg,
git_config_backend *file,
- unsigned int level,
+ git_config_level_t level,
int force);
/** @} */
diff --git a/src/config.c b/src/config.c
index e436a31..9491d26 100644
--- a/src/config.c
+++ b/src/config.c
@@ -23,7 +23,7 @@ typedef struct {
git_refcount rc;
git_config_backend *file;
- unsigned int level;
+ git_config_level_t level;
} file_internal;
static void file_internal_free(file_internal *internal)
@@ -87,7 +87,7 @@ int git_config_new(git_config **out)
int git_config_add_file_ondisk(
git_config *cfg,
const char *path,
- unsigned int level,
+ git_config_level_t level,
int force)
{
git_config_backend *file = NULL;
@@ -138,11 +138,11 @@ int git_config_open_ondisk(git_config **out, const char *path)
static int find_internal_file_by_level(
file_internal **internal_out,
const git_config *cfg,
- int level)
+ git_config_level_t level)
{
int pos = -1;
file_internal *internal;
- unsigned int i;
+ size_t i;
/* when passing GIT_CONFIG_HIGHEST_LEVEL, the idea is to get the config file
* which has the highest level. As config files are stored in a vector
@@ -153,14 +153,14 @@ static int find_internal_file_by_level(
pos = 0;
} else {
git_vector_foreach(&cfg->files, i, internal) {
- if (internal->level == (unsigned int)level)
+ if (internal->level == level)
pos = i;
}
}
if (pos == -1) {
giterr_set(GITERR_CONFIG,
- "No config file exists for the given level '%i'", level);
+ "No config file exists for the given level '%i'", (int)level);
return GIT_ENOTFOUND;
}
@@ -175,17 +175,17 @@ static int duplicate_level(void **old_raw, void *new_raw)
GIT_UNUSED(new_raw);
- giterr_set(GITERR_CONFIG, "A file with the same level (%i) has already been added to the config", (*old)->level);
+ giterr_set(GITERR_CONFIG, "A file with the same level (%i) has already been added to the config", (int)(*old)->level);
return GIT_EEXISTS;
}
static void try_remove_existing_file_internal(
git_config *cfg,
- unsigned int level)
+ git_config_level_t level)
{
int pos = -1;
file_internal *internal;
- unsigned int i;
+ size_t i;
git_vector_foreach(&cfg->files, i, internal) {
if (internal->level == level)
@@ -206,7 +206,7 @@ static void try_remove_existing_file_internal(
static int git_config__add_internal(
git_config *cfg,
file_internal *internal,
- unsigned int level,
+ git_config_level_t level,
int force)
{
int result;
@@ -238,7 +238,7 @@ int git_config_open_global(git_config **cfg_out, git_config *cfg)
int git_config_open_level(
git_config **cfg_out,
const git_config *cfg_parent,
- unsigned int level)
+ git_config_level_t level)
{
git_config *cfg;
file_internal *internal;
@@ -263,7 +263,7 @@ int git_config_open_level(
int git_config_add_backend(
git_config *cfg,
git_config_backend *file,
- unsigned int level,
+ git_config_level_t level,
int force)
{
file_internal *internal;
diff --git a/src/config_file.c b/src/config_file.c
index e57cd1e..dec9521 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -81,10 +81,10 @@ typedef struct {
time_t file_mtime;
size_t file_size;
- unsigned int level;
+ git_config_level_t level;
} diskfile_backend;
-static int config_parse(diskfile_backend *cfg_file, unsigned int level);
+static int config_parse(diskfile_backend *cfg_file, git_config_level_t level);
static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_value);
static int config_write(diskfile_backend *cfg, const char *key, const regex_t *preg, const char *value);
static char *escape_value(const char *ptr);
@@ -181,7 +181,7 @@ static void free_vars(git_strmap *values)
git_strmap_free(values);
}
-static int config_open(git_config_backend *cfg, unsigned int level)
+static int config_open(git_config_backend *cfg, git_config_level_t level)
{
int res;
diskfile_backend *b = (diskfile_backend *)cfg;
@@ -965,7 +965,7 @@ static int strip_comments(char *line, int in_quotes)
return quote_count;
}
-static int config_parse(diskfile_backend *cfg_file, unsigned int level)
+static int config_parse(diskfile_backend *cfg_file, git_config_level_t level)
{
int c;
char *current_section = NULL;