Skip to content

Commit 3424c21

Browse files
authored
Merge pull request libgit2#5138 from libgit2/ethomson/cvar
configuration: cvar -> configmap
2 parents a33c0de + 3655851 commit 3424c21

28 files changed

+209
-194
lines changed

include/git2/config.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,20 @@ typedef struct git_config_iterator git_config_iterator;
9292
* Config var type
9393
*/
9494
typedef enum {
95-
GIT_CVAR_FALSE = 0,
96-
GIT_CVAR_TRUE = 1,
97-
GIT_CVAR_INT32,
98-
GIT_CVAR_STRING
99-
} git_cvar_t;
95+
GIT_CONFIGMAP_FALSE = 0,
96+
GIT_CONFIGMAP_TRUE = 1,
97+
GIT_CONFIGMAP_INT32,
98+
GIT_CONFIGMAP_STRING
99+
} git_configmap_t;
100100

101101
/**
102102
* Mapping from config variables to values.
103103
*/
104104
typedef struct {
105-
git_cvar_t cvar_type;
105+
git_configmap_t type;
106106
const char *str_match;
107107
int map_value;
108-
} git_cvar_map;
108+
} git_configmap;
109109

110110
/**
111111
* Locate the path to the global configuration file
@@ -623,7 +623,7 @@ GIT_EXTERN(int) git_config_foreach_match(
623623
*
624624
* A mapping array looks as follows:
625625
*
626-
* git_cvar_map autocrlf_mapping[] = {
626+
* git_configmap autocrlf_mapping[] = {
627627
* {GIT_CVAR_FALSE, NULL, GIT_AUTO_CRLF_FALSE},
628628
* {GIT_CVAR_TRUE, NULL, GIT_AUTO_CRLF_TRUE},
629629
* {GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT},
@@ -644,28 +644,28 @@ GIT_EXTERN(int) git_config_foreach_match(
644644
* @param out place to store the result of the mapping
645645
* @param cfg config file to get the variables from
646646
* @param name name of the config variable to lookup
647-
* @param maps array of `git_cvar_map` objects specifying the possible mappings
647+
* @param maps array of `git_configmap` objects specifying the possible mappings
648648
* @param map_n number of mapping objects in `maps`
649649
* @return 0 on success, error code otherwise
650650
*/
651651
GIT_EXTERN(int) git_config_get_mapped(
652652
int *out,
653653
const git_config *cfg,
654654
const char *name,
655-
const git_cvar_map *maps,
655+
const git_configmap *maps,
656656
size_t map_n);
657657

658658
/**
659659
* Maps a string value to an integer constant
660660
*
661661
* @param out place to store the result of the parsing
662-
* @param maps array of `git_cvar_map` objects specifying the possible mappings
662+
* @param maps array of `git_configmap` objects specifying the possible mappings
663663
* @param map_n number of mapping objects in `maps`
664664
* @param value value to parse
665665
*/
666666
GIT_EXTERN(int) git_config_lookup_map_value(
667667
int *out,
668-
const git_cvar_map *maps,
668+
const git_configmap *maps,
669669
size_t map_n,
670670
const char *value);
671671

include/git2/deprecated.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef INCLUDE_git_deprecated_h__
88
#define INCLUDE_git_deprecated_h__
99

10+
#include "config.h"
1011
#include "common.h"
1112
#include "blame.h"
1213
#include "buffer.h"
@@ -116,6 +117,19 @@ GIT_EXTERN(void) git_buf_free(git_buf *buffer);
116117

117118
/**@}*/
118119

120+
/** @name Deprecated Config Functions and Constants
121+
*/
122+
/**@{*/
123+
124+
#define GIT_CVAR_FALSE GIT_CONFIGMAP_FALSE
125+
#define GIT_CVAR_TRUE GIT_CONFIGMAP_TRUE
126+
#define GIT_CVAR_INT32 GIT_CONFIGMAP_INT32
127+
#define GIT_CVAR_STRING GIT_CONFIGMAP_STRING
128+
129+
typedef git_configmap git_cvar_map;
130+
131+
/**@}*/
132+
119133
/** @name Deprecated Error Functions and Constants
120134
*
121135
* These functions and enumeration values are retained for backward

src/checkout.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ static bool should_remove_existing(checkout_data *data)
13911391
{
13921392
int ignorecase;
13931393

1394-
if (git_repository__cvar(&ignorecase, data->repo, GIT_CVAR_IGNORECASE) < 0) {
1394+
if (git_repository__configmap_lookup(&ignorecase, data->repo, GIT_CONFIGMAP_IGNORECASE) < 0) {
13951395
ignorecase = 0;
13961396
}
13971397

@@ -2463,12 +2463,12 @@ static int checkout_data_init(
24632463

24642464
data->pfx = git_pathspec_prefix(&data->opts.paths);
24652465

2466-
if ((error = git_repository__cvar(
2467-
&data->can_symlink, repo, GIT_CVAR_SYMLINKS)) < 0)
2466+
if ((error = git_repository__configmap_lookup(
2467+
&data->can_symlink, repo, GIT_CONFIGMAP_SYMLINKS)) < 0)
24682468
goto cleanup;
24692469

2470-
if ((error = git_repository__cvar(
2471-
&data->respect_filemode, repo, GIT_CVAR_FILEMODE)) < 0)
2470+
if ((error = git_repository__configmap_lookup(
2471+
&data->respect_filemode, repo, GIT_CONFIGMAP_FILEMODE)) < 0)
24722472
goto cleanup;
24732473

24742474
if (!data->opts.baseline && !data->opts.baseline_index) {

src/config.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
661661
error = backend->set(backend, name, value);
662662

663663
if (!error && GIT_REFCOUNT_OWNER(cfg) != NULL)
664-
git_repository__cvar_cache_clear(GIT_REFCOUNT_OWNER(cfg));
664+
git_repository__configmap_lookup_cache_clear(GIT_REFCOUNT_OWNER(cfg));
665665

666666
return error;
667667
}
@@ -777,7 +777,7 @@ int git_config_get_mapped(
777777
int *out,
778778
const git_config *cfg,
779779
const char *name,
780-
const git_cvar_map *maps,
780+
const git_configmap *maps,
781781
size_t map_n)
782782
{
783783
git_config_entry *entry;
@@ -1223,7 +1223,7 @@ int git_config_unlock(git_config *cfg, int commit)
12231223

12241224
int git_config_lookup_map_value(
12251225
int *out,
1226-
const git_cvar_map *maps,
1226+
const git_configmap *maps,
12271227
size_t map_n,
12281228
const char *value)
12291229
{
@@ -1233,27 +1233,27 @@ int git_config_lookup_map_value(
12331233
goto fail_parse;
12341234

12351235
for (i = 0; i < map_n; ++i) {
1236-
const git_cvar_map *m = maps + i;
1236+
const git_configmap *m = maps + i;
12371237

1238-
switch (m->cvar_type) {
1239-
case GIT_CVAR_FALSE:
1240-
case GIT_CVAR_TRUE: {
1238+
switch (m->type) {
1239+
case GIT_CONFIGMAP_FALSE:
1240+
case GIT_CONFIGMAP_TRUE: {
12411241
int bool_val;
12421242

12431243
if (git__parse_bool(&bool_val, value) == 0 &&
1244-
bool_val == (int)m->cvar_type) {
1244+
bool_val == (int)m->type) {
12451245
*out = m->map_value;
12461246
return 0;
12471247
}
12481248
break;
12491249
}
12501250

1251-
case GIT_CVAR_INT32:
1251+
case GIT_CONFIGMAP_INT32:
12521252
if (git_config_parse_int32(out, value) == 0)
12531253
return 0;
12541254
break;
12551255

1256-
case GIT_CVAR_STRING:
1256+
case GIT_CONFIGMAP_STRING:
12571257
if (strcasecmp(value, m->str_match) == 0) {
12581258
*out = m->map_value;
12591259
return 0;
@@ -1267,18 +1267,18 @@ int git_config_lookup_map_value(
12671267
return -1;
12681268
}
12691269

1270-
int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
1271-
const git_cvar_map *maps, size_t map_n, int enum_val)
1270+
int git_config_lookup_map_enum(git_configmap_t *type_out, const char **str_out,
1271+
const git_configmap *maps, size_t map_n, int enum_val)
12721272
{
12731273
size_t i;
12741274

12751275
for (i = 0; i < map_n; i++) {
1276-
const git_cvar_map *m = &maps[i];
1276+
const git_configmap *m = &maps[i];
12771277

12781278
if (m->map_value != enum_val)
12791279
continue;
12801280

1281-
*type_out = m->cvar_type;
1281+
*type_out = m->type;
12821282
*str_out = m->str_match;
12831283
return 0;
12841284
}

src/config.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,19 @@ extern int git_config__get_bool_force(
6666
extern int git_config__get_int_force(
6767
const git_config *cfg, const char *key, int fallback_value);
6868

69-
/* API for repository cvar-style lookups from config - not cached, but
70-
* uses cvar value maps and fallbacks
69+
/* API for repository configmap-style lookups from config - not cached, but
70+
* uses configmap value maps and fallbacks
7171
*/
72-
extern int git_config__cvar(
73-
int *out, git_config *config, git_cvar_cached cvar);
72+
extern int git_config__configmap_lookup(
73+
int *out, git_config *config, git_configmap_item item);
7474

7575
/**
7676
* The opposite of git_config_lookup_map_value, we take an enum value
7777
* and map it to the string or bool value on the config.
7878
*/
79-
int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
80-
const git_cvar_map *maps, size_t map_n, int enum_val);
79+
int git_config_lookup_map_enum(git_configmap_t *type_out,
80+
const char **str_out, const git_configmap *maps,
81+
size_t map_n, int enum_val);
8182

8283
/**
8384
* Unlock the backend with the highest priority

src/config_cache.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include "filter.h"
1616

1717
struct map_data {
18-
const char *cvar_name;
19-
git_cvar_map *maps;
18+
const char *name;
19+
git_configmap *maps;
2020
size_t map_count;
2121
int default_value;
2222
};
@@ -29,11 +29,11 @@ struct map_data {
2929
* value is native. See gitattributes(5) for more information on
3030
* end-of-line conversion.
3131
*/
32-
static git_cvar_map _cvar_map_eol[] = {
33-
{GIT_CVAR_FALSE, NULL, GIT_EOL_UNSET},
34-
{GIT_CVAR_STRING, "lf", GIT_EOL_LF},
35-
{GIT_CVAR_STRING, "crlf", GIT_EOL_CRLF},
36-
{GIT_CVAR_STRING, "native", GIT_EOL_NATIVE}
32+
static git_configmap _configmap_eol[] = {
33+
{GIT_CONFIGMAP_FALSE, NULL, GIT_EOL_UNSET},
34+
{GIT_CONFIGMAP_STRING, "lf", GIT_EOL_LF},
35+
{GIT_CONFIGMAP_STRING, "crlf", GIT_EOL_CRLF},
36+
{GIT_CONFIGMAP_STRING, "native", GIT_EOL_NATIVE}
3737
};
3838

3939
/*
@@ -46,55 +46,55 @@ static git_cvar_map _cvar_map_eol[] = {
4646
* does not have normalized line endings. This variable can be set to input,
4747
* in which case no output conversion is performed.
4848
*/
49-
static git_cvar_map _cvar_map_autocrlf[] = {
50-
{GIT_CVAR_FALSE, NULL, GIT_AUTO_CRLF_FALSE},
51-
{GIT_CVAR_TRUE, NULL, GIT_AUTO_CRLF_TRUE},
52-
{GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT}
49+
static git_configmap _configmap_autocrlf[] = {
50+
{GIT_CONFIGMAP_FALSE, NULL, GIT_AUTO_CRLF_FALSE},
51+
{GIT_CONFIGMAP_TRUE, NULL, GIT_AUTO_CRLF_TRUE},
52+
{GIT_CONFIGMAP_STRING, "input", GIT_AUTO_CRLF_INPUT}
5353
};
5454

55-
static git_cvar_map _cvar_map_safecrlf[] = {
56-
{GIT_CVAR_FALSE, NULL, GIT_SAFE_CRLF_FALSE},
57-
{GIT_CVAR_TRUE, NULL, GIT_SAFE_CRLF_FAIL},
58-
{GIT_CVAR_STRING, "warn", GIT_SAFE_CRLF_WARN}
55+
static git_configmap _configmap_safecrlf[] = {
56+
{GIT_CONFIGMAP_FALSE, NULL, GIT_SAFE_CRLF_FALSE},
57+
{GIT_CONFIGMAP_TRUE, NULL, GIT_SAFE_CRLF_FAIL},
58+
{GIT_CONFIGMAP_STRING, "warn", GIT_SAFE_CRLF_WARN}
5959
};
6060

61-
static git_cvar_map _cvar_map_logallrefupdates[] = {
62-
{GIT_CVAR_FALSE, NULL, GIT_LOGALLREFUPDATES_FALSE},
63-
{GIT_CVAR_TRUE, NULL, GIT_LOGALLREFUPDATES_TRUE},
64-
{GIT_CVAR_STRING, "always", GIT_LOGALLREFUPDATES_ALWAYS},
61+
static git_configmap _configmap_logallrefupdates[] = {
62+
{GIT_CONFIGMAP_FALSE, NULL, GIT_LOGALLREFUPDATES_FALSE},
63+
{GIT_CONFIGMAP_TRUE, NULL, GIT_LOGALLREFUPDATES_TRUE},
64+
{GIT_CONFIGMAP_STRING, "always", GIT_LOGALLREFUPDATES_ALWAYS},
6565
};
6666

6767
/*
6868
* Generic map for integer values
6969
*/
70-
static git_cvar_map _cvar_map_int[] = {
71-
{GIT_CVAR_INT32, NULL, 0},
70+
static git_configmap _configmap_int[] = {
71+
{GIT_CONFIGMAP_INT32, NULL, 0},
7272
};
7373

74-
static struct map_data _cvar_maps[] = {
75-
{"core.autocrlf", _cvar_map_autocrlf, ARRAY_SIZE(_cvar_map_autocrlf), GIT_AUTO_CRLF_DEFAULT},
76-
{"core.eol", _cvar_map_eol, ARRAY_SIZE(_cvar_map_eol), GIT_EOL_DEFAULT},
74+
static struct map_data _configmaps[] = {
75+
{"core.autocrlf", _configmap_autocrlf, ARRAY_SIZE(_configmap_autocrlf), GIT_AUTO_CRLF_DEFAULT},
76+
{"core.eol", _configmap_eol, ARRAY_SIZE(_configmap_eol), GIT_EOL_DEFAULT},
7777
{"core.symlinks", NULL, 0, GIT_SYMLINKS_DEFAULT },
7878
{"core.ignorecase", NULL, 0, GIT_IGNORECASE_DEFAULT },
7979
{"core.filemode", NULL, 0, GIT_FILEMODE_DEFAULT },
8080
{"core.ignorestat", NULL, 0, GIT_IGNORESTAT_DEFAULT },
8181
{"core.trustctime", NULL, 0, GIT_TRUSTCTIME_DEFAULT },
82-
{"core.abbrev", _cvar_map_int, 1, GIT_ABBREV_DEFAULT },
82+
{"core.abbrev", _configmap_int, 1, GIT_ABBREV_DEFAULT },
8383
{"core.precomposeunicode", NULL, 0, GIT_PRECOMPOSE_DEFAULT },
84-
{"core.safecrlf", _cvar_map_safecrlf, ARRAY_SIZE(_cvar_map_safecrlf), GIT_SAFE_CRLF_DEFAULT},
85-
{"core.logallrefupdates", _cvar_map_logallrefupdates, ARRAY_SIZE(_cvar_map_logallrefupdates), GIT_LOGALLREFUPDATES_DEFAULT},
84+
{"core.safecrlf", _configmap_safecrlf, ARRAY_SIZE(_configmap_safecrlf), GIT_SAFE_CRLF_DEFAULT},
85+
{"core.logallrefupdates", _configmap_logallrefupdates, ARRAY_SIZE(_configmap_logallrefupdates), GIT_LOGALLREFUPDATES_DEFAULT},
8686
{"core.protecthfs", NULL, 0, GIT_PROTECTHFS_DEFAULT },
8787
{"core.protectntfs", NULL, 0, GIT_PROTECTNTFS_DEFAULT },
8888
{"core.fsyncobjectfiles", NULL, 0, GIT_FSYNCOBJECTFILES_DEFAULT },
8989
};
9090

91-
int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar)
91+
int git_config__configmap_lookup(int *out, git_config *config, git_configmap_item item)
9292
{
9393
int error = 0;
94-
struct map_data *data = &_cvar_maps[(int)cvar];
94+
struct map_data *data = &_configmaps[(int)item];
9595
git_config_entry *entry;
9696

97-
if ((error = git_config__lookup_entry(&entry, config, data->cvar_name, false)) < 0)
97+
if ((error = git_config__lookup_entry(&entry, config, data->name, false)) < 0)
9898
return error;
9999

100100
if (!entry)
@@ -109,29 +109,29 @@ int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar)
109109
return error;
110110
}
111111

112-
int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar)
112+
int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item)
113113
{
114-
*out = repo->cvar_cache[(int)cvar];
114+
*out = repo->configmap_cache[(int)item];
115115

116-
if (*out == GIT_CVAR_NOT_CACHED) {
116+
if (*out == GIT_CONFIGMAP_NOT_CACHED) {
117117
int error;
118118
git_config *config;
119119

120120
if ((error = git_repository_config__weakptr(&config, repo)) < 0 ||
121-
(error = git_config__cvar(out, config, cvar)) < 0)
121+
(error = git_config__configmap_lookup(out, config, item)) < 0)
122122
return error;
123123

124-
repo->cvar_cache[(int)cvar] = *out;
124+
repo->configmap_cache[(int)item] = *out;
125125
}
126126

127127
return 0;
128128
}
129129

130-
void git_repository__cvar_cache_clear(git_repository *repo)
130+
void git_repository__configmap_lookup_cache_clear(git_repository *repo)
131131
{
132132
int i;
133133

134-
for (i = 0; i < GIT_CVAR_CACHE_MAX; ++i)
135-
repo->cvar_cache[i] = GIT_CVAR_NOT_CACHED;
134+
for (i = 0; i < GIT_CONFIGMAP_CACHE_MAX; ++i)
135+
repo->configmap_cache[i] = GIT_CONFIGMAP_NOT_CACHED;
136136
}
137137

0 commit comments

Comments
 (0)