@matheusbsbs / matheus-bagliano / commits / 9378c16135
Fork 0

Add core.quotepath configuration variable.

We always quote "unusual" byte values in a pathname using C-string style, to make it safer for parsing scripts that do not handle NUL separated records well (or just too lazy to bother). The absolute minimum bytes that need to be quoted for this purpose are TAB, LF (and other control characters), double quote and backslash. However, we have also always quoted the bytes in high 8-bit range; this was partly because we were lazy and partly because we were being cautious. This introduces an internal "quote_path_fully" variable, and core.quotepath configuration variable to control it. When set to false, it does not quote bytes in high 8-bit range anymore but passes them intact. The variable defaults to "true" to retain the traditional behaviour for now. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 24, 2007 at 15:11 UTC 9378c16135100fb65ad575cd35074af166de1cab
6 files changed +148 -2
Documentation/config.txt
+12
@@ -117,6 +117,18 @@ core.fileMode::
117 the working copy are ignored; useful on broken filesystems like FAT.
118 See gitlink:git-update-index[1]. True by default.
119
120 +core.quotepath::
121 + The commands that output paths (e.g. `ls-files`,
122 + `diff`), when not given the `-z` option, will quote
123 + "unusual" characters in the pathname by enclosing the
124 + pathname in a double-quote pair and with backslashes the
125 + same way strings in C source code are quoted. If this
126 + variable is set to false, the bytes higher than 0x80 are
127 + not quoted but output as verbatim. Note that double
128 + quote, backslash and control characters are always
129 + quoted without `-z` regardless of the setting of this
130 + variable.
131 +
132 core.autocrlf::
133 If true, makes git convert `CRLF` at the end of lines in text files to
134 `LF` when reading from the filesystem, and convert in reverse when
cache.h
+1
@@ -292,6 +292,7 @@ extern int delete_ref(const char *, const unsigned char *sha1);
292
293 /* Environment bits from configuration mechanism */
294 extern int trust_executable_bit;
295 +extern int quote_path_fully;
296 extern int has_symlinks;
297 extern int assume_unchanged;
298 extern int prefer_symlink_refs;
config.c
+5
@@ -271,6 +271,11 @@ int git_default_config(const char *var, const char *value)
271 return 0;
272 }
273
274 + if (!strcmp(var, "core.quotepath")) {
275 + quote_path_fully = git_config_bool(var, value);
276 + return 0;
277 + }
278 +
279 if (!strcmp(var, "core.symlinks")) {
280 has_symlinks = git_config_bool(var, value);
281 return 0;
environment.c
+1
@@ -12,6 +12,7 @@
12 char git_default_email[MAX_GITNAME];
13 char git_default_name[MAX_GITNAME];
14 int trust_executable_bit = 1;
15 +int quote_path_fully = 1;
16 int has_symlinks = 1;
17 int assume_unchanged;
18 int prefer_symlink_refs;
quote.c
+3 -2
@@ -188,7 +188,8 @@ static int quote_c_style_counted(const char *name, int namelen,
188 #define EMITQ() EMIT('\\')
189
190 const char *sp;
191 - int ch, count = 0, needquote = 0;
191 + unsigned char ch;
192 + int count = 0, needquote = 0;
193
194 if (!no_dq)
195 EMIT('"');
@@ -197,7 +198,7 @@ static int quote_c_style_counted(const char *name, int namelen,
198 if (!ch)
199 break;
200 if ((ch < ' ') || (ch == '"') || (ch == '\\') ||
200 - (ch >= 0177)) {
201 + (quote_path_fully && (ch >= 0177))) {
202 needquote = 1;
203 switch (ch) {
204 case '\a': EMITQ(); ch = 'a'; break;
t/t3902-quoted.sh new
+126
@@ -0,0 +1,126 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2006 Junio C Hamano
4 +#
5 +
6 +test_description='quoted output'
7 +
8 +. ./test-lib.sh
9 +
10 +FN='濱野'
11 +GN='純'
12 +HT=' '
13 +LF='
14 +'
15 +DQ='"'
16 +
17 +for_each_name () {
18 + for name in \
19 + Name "Name and a${LF}LF" "Name and an${HT}HT" "Name${DQ}" \
20 + "$FN$HT$GN" "$FN$LF$GN" "$FN $GN" "$FN$GN" "$FN$DQ$GN" \
21 + "With SP in it"
22 + do
23 + eval "$1"
24 + done
25 +}
26 +
27 +test_expect_success setup '
28 +
29 + for_each_name "echo initial >\"\$name\""
30 + git add . &&
31 + git commit -q -m Initial &&
32 +
33 + for_each_name "echo second >\"\$name\"" &&
34 + git commit -a -m Second
35 +
36 + for_each_name "echo modified >\"\$name\""
37 +
38 +'
39 +
40 +cat >expect.quoted <<\EOF
41 +Name
42 +"Name and a\nLF"
43 +"Name and an\tHT"
44 +"Name\""
45 +With SP in it
46 +"\346\277\261\351\207\216\t\347\264\224"
47 +"\346\277\261\351\207\216\n\347\264\224"
48 +"\346\277\261\351\207\216 \347\264\224"
49 +"\346\277\261\351\207\216\"\347\264\224"
50 +"\346\277\261\351\207\216\347\264\224"
51 +EOF
52 +
53 +cat >expect.raw <<\EOF
54 +Name
55 +"Name and a\nLF"
56 +"Name and an\tHT"
57 +"Name\""
58 +With SP in it
59 +"濱野\t純"
60 +"濱野\n純"
61 +濱野 純
62 +"濱野\"純"
63 +濱野純
64 +EOF
65 +
66 +test_expect_success 'check fully quoted output from ls-files' '
67 +
68 + git ls-files >current && diff -u expect.quoted current
69 +
70 +'
71 +
72 +test_expect_success 'check fully quoted output from diff-files' '
73 +
74 + git diff --name-only >current &&
75 + diff -u expect.quoted current
76 +
77 +'
78 +
79 +test_expect_success 'check fully quoted output from diff-index' '
80 +
81 + git diff --name-only HEAD >current &&
82 + diff -u expect.quoted current
83 +
84 +'
85 +
86 +test_expect_success 'check fully quoted output from diff-tree' '
87 +
88 + git diff --name-only HEAD^ HEAD >current &&
89 + diff -u expect.quoted current
90 +
91 +'
92 +
93 +test_expect_success 'setting core.quotepath' '
94 +
95 + git config --bool core.quotepath false
96 +
97 +'
98 +
99 +test_expect_success 'check fully quoted output from ls-files' '
100 +
101 + git ls-files >current && diff -u expect.raw current
102 +
103 +'
104 +
105 +test_expect_success 'check fully quoted output from diff-files' '
106 +
107 + git diff --name-only >current &&
108 + diff -u expect.raw current
109 +
110 +'
111 +
112 +test_expect_success 'check fully quoted output from diff-index' '
113 +
114 + git diff --name-only HEAD >current &&
115 + diff -u expect.raw current
116 +
117 +'
118 +
119 +test_expect_success 'check fully quoted output from diff-tree' '
120 +
121 + git diff --name-only HEAD^ HEAD >current &&
122 + diff -u expect.raw current
123 +
124 +'
125 +
126 +test_done