Skip to content

Commit 7501847

Browse files
Kevin Willfordvdye
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 91bbdc4 commit 7501847

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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, void *data)
11+
{
12+
if (!strcmp(var, "core.gvfs"))
13+
core_gvfs = git_config_bool_or_int("core.gvfs", value, &core_gvfs_is_bool);
14+
return 0;
15+
}
16+
17+
void gvfs_load_config_value(const char *value)
18+
{
19+
if (gvfs_config_loaded)
20+
return;
21+
22+
if (value)
23+
core_gvfs = git_config_bool_or_int("core.gvfs", value, &core_gvfs_is_bool);
24+
else if (startup_info->have_repository == 0)
25+
read_early_config(early_core_gvfs_config, NULL);
26+
else
27+
git_config_get_bool_or_int("core.gvfs", &core_gvfs_is_bool, &core_gvfs);
28+
29+
/* Turn on all bits if a bool was set in the settings */
30+
if (core_gvfs_is_bool && core_gvfs)
31+
core_gvfs = -1;
32+
33+
gvfs_config_loaded = 1;
34+
}
35+
36+
int gvfs_config_is_set(int mask)
37+
{
38+
gvfs_load_config_value(NULL);
39+
return (core_gvfs & mask) == mask;
40+
}

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)