10
#include "help.h"
11
#include "pkt-line.h"
12
#include "write-or-die.h"
13
+#include "urlmatch.h"
14
15
struct keyword_entry {
16
/*
28
};
29
30
static enum {
30
- ALLOW_NO_CONTROL_CHARACTERS = 0,
31
- ALLOW_ANSI_COLOR_SEQUENCES = 1<<0,
32
- ALLOW_ANSI_CURSOR_MOVEMENTS = 1<<1,
33
- ALLOW_ANSI_ERASE = 1<<2,
34
- ALLOW_DEFAULT_ANSI_SEQUENCES = ALLOW_ANSI_COLOR_SEQUENCES,
35
- ALLOW_ALL_CONTROL_CHARACTERS = 1<<3,
36
-} allow_control_characters = ALLOW_DEFAULT_ANSI_SEQUENCES;
31
+ ALLOW_CONTROL_SEQUENCES_UNSET = -1,
32
+ ALLOW_NO_CONTROL_CHARACTERS = 0,
33
+ ALLOW_ANSI_COLOR_SEQUENCES = 1<<0,
34
+ ALLOW_ANSI_CURSOR_MOVEMENTS = 1<<1,
35
+ ALLOW_ANSI_ERASE = 1<<2,
36
+ ALLOW_DEFAULT_ANSI_SEQUENCES = ALLOW_ANSI_COLOR_SEQUENCES,
37
+ ALLOW_ALL_CONTROL_CHARACTERS = 1<<3,
38
+} allow_control_characters = ALLOW_CONTROL_SEQUENCES_UNSET;
39
40
static inline int skip_prefix_in_csv(const char *value, const char *prefix,
41
const char **out)
47
return 1;
48
}
49
48
-static void parse_allow_control_characters(const char *value)
50
+int sideband_allow_control_characters_config(const char *var, const char *value)
51
{
52
+ switch (git_parse_maybe_bool(value)) {
53
+ case 0:
54
+ allow_control_characters = ALLOW_NO_CONTROL_CHARACTERS;
55
+ return 0;
56
+ case 1:
57
+ allow_control_characters = ALLOW_ALL_CONTROL_CHARACTERS;
58
+ return 0;
59
+ default:
60
+ break;
61
+ }
62
+
63
allow_control_characters = ALLOW_NO_CONTROL_CHARACTERS;
64
while (*value) {
65
if (skip_prefix_in_csv(value, "default", &value))
75
else if (skip_prefix_in_csv(value, "false", &value))
76
allow_control_characters = ALLOW_NO_CONTROL_CHARACTERS;
77
else
65
- warning(_("unrecognized value for `sideband."
66
- "allowControlCharacters`: '%s'"), value);
78
+ warning(_("unrecognized value for '%s': '%s'"), var, value);
79
}
80
+ return 0;
81
+}
82
+
83
+static int sideband_config_callback(const char *var, const char *value,
84
+ const struct config_context *ctx UNUSED,
85
+ void *data UNUSED)
86
+{
87
+ if (!strcmp(var, "sideband.allowcontrolcharacters"))
88
+ return sideband_allow_control_characters_config(var, value);
89
+
90
+ return 0;
91
+}
92
+
93
+void sideband_apply_url_config(const char *url)
94
+{
95
+ struct urlmatch_config config = URLMATCH_CONFIG_INIT;
96
+ char *normalized_url;
97
+
98
+ if (!url)
99
+ BUG("must not call sideband_apply_url_config(NULL)");
100
+
101
+ config.section = "sideband";
102
+ config.collect_fn = sideband_config_callback;
103
+
104
+ normalized_url = url_normalize(url, &config.url);
105
+ repo_config(the_repository, urlmatch_config_entry, &config);
106
+ free(normalized_url);
107
+ string_list_clear(&config.vars, 1);
108
+ urlmatch_config_release(&config);
109
}
110
111
/* Returns a color setting (GIT_COLOR_NEVER, etc). */
121
if (use_sideband_colors_cached != GIT_COLOR_UNKNOWN)
122
return use_sideband_colors_cached;
123
83
- switch (repo_config_get_maybe_bool(the_repository, "sideband.allowcontrolcharacters", &i)) {
84
- case 0: /* Boolean value */
85
- allow_control_characters = i ? ALLOW_ALL_CONTROL_CHARACTERS :
86
- ALLOW_NO_CONTROL_CHARACTERS;
87
- break;
88
- case -1: /* non-Boolean value */
89
- if (repo_config_get_string_tmp(the_repository, "sideband.allowcontrolcharacters",
90
- &value))
91
- ; /* huh? `get_maybe_bool()` returned -1 */
92
- else
93
- parse_allow_control_characters(value);
94
- break;
95
- default:
96
- break; /* not configured */
124
+ if (allow_control_characters == ALLOW_CONTROL_SEQUENCES_UNSET) {
125
+ if (!repo_config_get_value(the_repository, "sideband.allowcontrolcharacters", &value))
126
+ sideband_allow_control_characters_config("sideband.allowcontrolcharacters", value);
127
+
128
+ if (allow_control_characters == ALLOW_CONTROL_SEQUENCES_UNSET)
129
+ allow_control_characters = ALLOW_DEFAULT_ANSI_SEQUENCES;
130
}
131
132
if (!repo_config_get_string_tmp(the_repository, key, &value))