Skip to content

Commit 0ca8b9d

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Winansi: Drop pre-Vista workaround (#6109)
1edeb9a (Win32: warn if the console font doesn't support Unicode, 2014-06-10) introduced both code to detect the current console font on Windows Vista and newer and a fallback for older systems to detect the default console font and issue a warning if that font doesn't support unicode. Since we haven't supported any Windows older than Vista in almost a decade, we don't need to keep the workaround. This more or less fell out of #6108, but didn't quite fit into that PR. There are also some other version specific hacks and workarounds I considered dropping, but decided against: * 492f709 * I'm unsure if this regression has ever been fixed or just become the new normal. * #5042 * So far this hasn't been an issue on Windows 8.1, but officially Go 1.21 and newer only support Windows 10 and newer. So this might become a problem at any point.
2 parents ebac26f + 44760f1 commit 0ca8b9d

10 files changed

Lines changed: 147 additions & 6 deletions

Documentation/config.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ include::config/sequencer.adoc[]
525525

526526
include::config/showbranch.adoc[]
527527

528+
include::config/sideband.adoc[]
529+
528530
include::config/sparse.adoc[]
529531

530532
include::config/splitindex.adoc[]

Documentation/config/sideband.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sideband.allowControlCharacters::
2+
By default, control characters that are delivered via the sideband
3+
are masked, except ANSI color sequences. This prevents potentially
4+
unwanted ANSI escape sequences from being sent to the terminal. Use
5+
this config setting to override this behavior:
6+
+
7+
--
8+
color::
9+
Allow ANSI color sequences, line feeds and horizontal tabs,
10+
but mask all other control characters. This is the default.
11+
false::
12+
Mask all control characters other than line feeds and
13+
horizontal tabs.
14+
true::
15+
Allow all control characters to be sent to the terminal.
16+
--

Documentation/git-svn.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
'git svn' <command> [<options>] [<arguments>]
12+
(UNSUPPORTED!)
1213

1314
DESCRIPTION
1415
-----------

git-svn.perl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,19 @@ sub term_init {
305305
: new Term::ReadLine 'git-svn';
306306
}
307307

308+
sub deprecated_warning {
309+
my @lines = @_;
310+
if (-t STDERR) {
311+
@lines = map { "\e[33m$_\e[0m" } @lines;
312+
}
313+
warn join("\n", @lines), "\n";
314+
}
315+
316+
deprecated_warning(
317+
"WARNING: \`git svn\` is no longer supported by the Git for Windows project.",
318+
"See https://github.com/git-for-windows/git/issues/5405 for details."
319+
);
320+
308321
my $cmd;
309322
for (my $i = 0; $i < @ARGV; $i++) {
310323
if (defined $cmd{$ARGV[$i]}) {

http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ static long http_retry_after = 0;
162162
static long http_max_retries = 0;
163163
static long http_max_retry_time = 300;
164164

165+
165166
/*
166167
* With the backend being set to `schannel`, setting sslCAinfo would override
167168
* the Certificate Store in cURL v7.60.0 and later, which is not what we want

sideband.c

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ static struct keyword_entry keywords[] = {
2626
{ "error", GIT_COLOR_BOLD_RED },
2727
};
2828

29+
static enum {
30+
ALLOW_NO_CONTROL_CHARACTERS = 0,
31+
ALLOW_ALL_CONTROL_CHARACTERS = 1,
32+
ALLOW_ANSI_COLOR_SEQUENCES = 2
33+
} allow_control_characters = ALLOW_ANSI_COLOR_SEQUENCES;
34+
2935
/* Returns a color setting (GIT_COLOR_NEVER, etc). */
3036
static enum git_colorbool use_sideband_colors(void)
3137
{
@@ -39,6 +45,25 @@ static enum git_colorbool use_sideband_colors(void)
3945
if (use_sideband_colors_cached != GIT_COLOR_UNKNOWN)
4046
return use_sideband_colors_cached;
4147

48+
switch (repo_config_get_maybe_bool(the_repository, "sideband.allowcontrolcharacters", &i)) {
49+
case 0: /* Boolean value */
50+
allow_control_characters = i ? ALLOW_ALL_CONTROL_CHARACTERS :
51+
ALLOW_NO_CONTROL_CHARACTERS;
52+
break;
53+
case -1: /* non-Boolean value */
54+
if (repo_config_get_string_tmp(the_repository, "sideband.allowcontrolcharacters",
55+
&value))
56+
; /* huh? `get_maybe_bool()` returned -1 */
57+
else if (!strcmp(value, "color"))
58+
allow_control_characters = ALLOW_ANSI_COLOR_SEQUENCES;
59+
else
60+
warning(_("unrecognized value for `sideband."
61+
"allowControlCharacters`: '%s'"), value);
62+
break;
63+
default:
64+
break; /* not configured */
65+
}
66+
4267
if (!repo_config_get_string_tmp(the_repository, key, &value))
4368
use_sideband_colors_cached = git_config_colorbool(key, value);
4469
else if (!repo_config_get_string_tmp(the_repository, "color.ui", &value))
@@ -66,6 +91,55 @@ void list_config_color_sideband_slots(struct string_list *list, const char *pref
6691
list_config_item(list, prefix, keywords[i].keyword);
6792
}
6893

94+
static int handle_ansi_color_sequence(struct strbuf *dest, const char *src, int n)
95+
{
96+
int i;
97+
98+
/*
99+
* Valid ANSI color sequences are of the form
100+
*
101+
* ESC [ [<n> [; <n>]*] m
102+
*/
103+
104+
if (allow_control_characters != ALLOW_ANSI_COLOR_SEQUENCES ||
105+
n < 3 || src[0] != '\x1b' || src[1] != '[')
106+
return 0;
107+
108+
for (i = 2; i < n; i++) {
109+
if (src[i] == 'm') {
110+
strbuf_add(dest, src, i + 1);
111+
return i;
112+
}
113+
if (!isdigit(src[i]) && src[i] != ';')
114+
break;
115+
}
116+
117+
return 0;
118+
}
119+
120+
static void strbuf_add_sanitized(struct strbuf *dest, const char *src, int n)
121+
{
122+
int i;
123+
124+
if (allow_control_characters == ALLOW_ALL_CONTROL_CHARACTERS) {
125+
strbuf_add(dest, src, n);
126+
return;
127+
}
128+
129+
strbuf_grow(dest, n);
130+
for (; n && *src; src++, n--) {
131+
if (!iscntrl(*src) || *src == '\t' || *src == '\n')
132+
strbuf_addch(dest, *src);
133+
else if ((i = handle_ansi_color_sequence(dest, src, n))) {
134+
src += i;
135+
n -= i;
136+
} else {
137+
strbuf_addch(dest, '^');
138+
strbuf_addch(dest, 0x40 + *src);
139+
}
140+
}
141+
}
142+
69143
/*
70144
* Optionally highlight one keyword in remote output if it appears at the start
71145
* of the line. This should be called for a single line only, which is
@@ -81,7 +155,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
81155
int i;
82156

83157
if (!want_color_stderr(use_sideband_colors())) {
84-
strbuf_add(dest, src, n);
158+
strbuf_add_sanitized(dest, src, n);
85159
return;
86160
}
87161

@@ -114,7 +188,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
114188
}
115189
}
116190

117-
strbuf_add(dest, src, n);
191+
strbuf_add_sanitized(dest, src, n);
118192
}
119193

120194

t/t5409-colorize-remote-messages.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,34 @@ test_expect_success 'fallback to color.ui' '
9898
grep "<BOLD;RED>error<RESET>: error" decoded
9999
'
100100

101+
test_expect_success 'disallow (color) control sequences in sideband' '
102+
write_script .git/color-me-surprised <<-\EOF &&
103+
printf "error: Have you \\033[31mread\\033[m this?\\a\\n" >&2
104+
exec "$@"
105+
EOF
106+
test_config_global uploadPack.packObjectshook ./color-me-surprised &&
107+
test_commit need-at-least-one-commit &&
108+
109+
git clone --no-local . throw-away 2>stderr &&
110+
test_decode_color <stderr >decoded &&
111+
test_grep RED decoded &&
112+
test_grep "\\^G" stderr &&
113+
tr -dc "\\007" <stderr >actual &&
114+
test_must_be_empty actual &&
115+
116+
rm -rf throw-away &&
117+
git -c sideband.allowControlCharacters=false \
118+
clone --no-local . throw-away 2>stderr &&
119+
test_decode_color <stderr >decoded &&
120+
test_grep ! RED decoded &&
121+
test_grep "\\^G" stderr &&
122+
123+
rm -rf throw-away &&
124+
git -c sideband.allowControlCharacters clone --no-local . throw-away 2>stderr &&
125+
test_decode_color <stderr >decoded &&
126+
test_grep RED decoded &&
127+
tr -dc "\\007" <stderr >actual &&
128+
test_file_not_empty actual
129+
'
130+
101131
test_done

t/t9108-git-svn-glob.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ test_expect_success 'test disallow multi-globs' '
110110
svn_cmd commit -m "try to try"
111111
) &&
112112
test_must_fail git svn fetch three 2> stderr.three &&
113-
test_cmp expect.three stderr.three
113+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.three >stderr.three.clean &&
114+
test_cmp expect.three stderr.three.clean
114115
'
115116

116117
test_done

t/t9109-git-svn-multi-glob.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ test_expect_success 'test disallow multiple globs' '
161161
svn_cmd commit -m "try to try"
162162
) &&
163163
test_must_fail git svn fetch three 2> stderr.three &&
164-
test_cmp expect.three stderr.three
164+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.three >stderr.three.clean &&
165+
test_cmp expect.three stderr.three.clean
165166
'
166167

167168
test_done

t/t9168-git-svn-partially-globbed-names.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ test_expect_success 'test disallow prefixed multi-globs' '
155155
svn_cmd commit -m "try to try"
156156
) &&
157157
test_must_fail git svn fetch four 2>stderr.four &&
158-
test_cmp expect.four stderr.four &&
158+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.four >stderr.four.clean &&
159+
test_cmp expect.four stderr.four.clean &&
159160
git config --unset svn-remote.four.branches &&
160161
git config --unset svn-remote.four.tags
161162
'
@@ -223,7 +224,8 @@ test_expect_success 'test disallow multiple asterisks in one word' '
223224
svn_cmd commit -m "try to try"
224225
) &&
225226
test_must_fail git svn fetch six 2>stderr.six &&
226-
test_cmp expect.six stderr.six
227+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.six >stderr.six.clean &&
228+
test_cmp expect.six stderr.six.clean
227229
'
228230

229231
test_done

0 commit comments

Comments
 (0)