Skip to content

Commit 0a3896d

Browse files
Kevin Willforddscho
authored andcommitted
gvfs: refactor loading the core.gvfs config value
This code change makes sure that the config value for core_gvfs is always loaded before checking it. Signed-off-by: Kevin Willford <kewillf@microsoft.com>
1 parent d3de4b1 commit 0a3896d

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ LIB_OBJS += git-zlib.o
10421042
LIB_OBJS += gpg-interface.o
10431043
LIB_OBJS += graph.o
10441044
LIB_OBJS += grep.o
1045+
LIB_OBJS += gvfs.o
10451046
LIB_OBJS += hash-lookup.o
10461047
LIB_OBJS += hashmap.o
10471048
LIB_OBJS += help.o

gvfs.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "git-compat-util.h"
2+
#include "environment.h"
3+
#include "gvfs.h"
4+
#include "setup.h"
5+
#include "config.h"
6+
7+
static int gvfs_config_loaded;
8+
static int core_gvfs_is_bool;
9+
10+
static int early_core_gvfs_config(const char *var, const char *value,
11+
const struct config_context *ctx, void *cb)
12+
{
13+
if (!strcmp(var, "core.gvfs"))
14+
core_gvfs = git_config_bool_or_int("core.gvfs", value, ctx->kvi,
15+
&core_gvfs_is_bool);
16+
return 0;
17+
}
18+
19+
void gvfs_load_config_value(const char *value)
20+
{
21+
if (gvfs_config_loaded)
22+
return;
23+
24+
if (value) {
25+
struct key_value_info default_kvi = KVI_INIT;
26+
core_gvfs = git_config_bool_or_int("core.gvfs", value, &default_kvi, &core_gvfs_is_bool);
27+
} else if (startup_info->have_repository == 0)
28+
read_early_config(early_core_gvfs_config, NULL);
29+
else
30+
repo_config_get_bool_or_int(the_repository, "core.gvfs",
31+
&core_gvfs_is_bool, &core_gvfs);
32+
33+
/* Turn on all bits if a bool was set in the settings */
34+
if (core_gvfs_is_bool && core_gvfs)
35+
core_gvfs = -1;
36+
37+
gvfs_config_loaded = 1;
38+
}
39+
40+
int gvfs_config_is_set(int mask)
41+
{
42+
gvfs_load_config_value(NULL);
43+
return (core_gvfs & mask) == mask;
44+
}

gvfs.h

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef GVFS_H
22
#define GVFS_H
33

4-
#include "environment.h"
5-
#include "config.h"
64

75
/*
86
* This file is for the specific settings and methods
@@ -19,32 +17,7 @@
1917
#define GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK (1 << 4)
2018
#define GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS (1 << 6)
2119

22-
static inline int gvfs_config_is_set(int mask) {
23-
return (core_gvfs & mask) == mask;
24-
}
25-
26-
static inline int gvfs_config_is_set_any(void) {
27-
return core_gvfs > 0;
28-
}
29-
30-
static inline void gvfs_load_config_value(const char *value) {
31-
int is_bool = 0;
32-
33-
if (value)
34-
core_gvfs = git_config_bool_or_int("core.gvfs", value, &is_bool);
35-
else
36-
git_config_get_bool_or_int("core.gvfs", &is_bool, &core_gvfs);
37-
38-
/* Turn on all bits if a bool was set in the settings */
39-
if (is_bool && core_gvfs)
40-
core_gvfs = -1;
41-
}
42-
43-
44-
static inline int gvfs_config_load_and_is_set(int mask) {
45-
gvfs_load_config_value(0);
46-
return gvfs_config_is_set(mask);
47-
}
48-
20+
void gvfs_load_config_value(const char *value);
21+
int gvfs_config_is_set(int mask);
4922

5023
#endif /* GVFS_H */

0 commit comments

Comments
 (0)