3
3
use strict;
4
4
use Git;
5
5
6
+ binmode (STDOUT , " :raw" );
7
+
6
8
my $repo = Git-> repository();
7
9
8
10
my $menu_use_color = $repo -> get_colorbool(' color.interactive' );
@@ -91,6 +93,47 @@ sub run_cmd_pipe {
91
93
}
92
94
chomp ($GIT_DIR );
93
95
96
+ my %cquote_map = (
97
+ " b" => chr (8),
98
+ " t" => chr (9),
99
+ " n" => chr (10),
100
+ " v" => chr (11),
101
+ " f" => chr (12),
102
+ " r" => chr (13),
103
+ " \\ " => " \\ " ,
104
+ " \042 " => " \042 " ,
105
+ );
106
+
107
+ sub unquote_path {
108
+ local ($_ ) = @_ ;
109
+ my ($retval , $remainder );
110
+ if (!/^\042(.*)\042$/ ) {
111
+ return $_ ;
112
+ }
113
+ ($_ , $retval ) = ($1 , " " );
114
+ while (/ ^([^\\ ]*)\\ (.*)$ / ) {
115
+ $remainder = $2 ;
116
+ $retval .= $1 ;
117
+ for ($remainder ) {
118
+ if (/ ^([0-3][0-7][0-7])(.*)$ / ) {
119
+ $retval .= chr (oct ($1 ));
120
+ $_ = $2 ;
121
+ last ;
122
+ }
123
+ if (/ ^([\\\042 btnvfr])(.*)$ / ) {
124
+ $retval .= $cquote_map {$1 };
125
+ $_ = $2 ;
126
+ last ;
127
+ }
128
+ # This is malformed -- just return it as-is for now.
129
+ return $_ [0];
130
+ }
131
+ $_ = $remainder ;
132
+ }
133
+ $retval .= $_ ;
134
+ return $retval ;
135
+ }
136
+
94
137
sub refresh {
95
138
my $fh ;
96
139
open $fh , ' git update-index --refresh |'
@@ -104,7 +147,7 @@ sub refresh {
104
147
sub list_untracked {
105
148
map {
106
149
chomp $_ ;
107
- $_ ;
150
+ unquote_path( $_ ) ;
108
151
}
109
152
run_cmd_pipe(qw( git ls-files --others --exclude-standard --) , @ARGV );
110
153
}
@@ -141,7 +184,8 @@ sub list_modified {
141
184
142
185
if (@ARGV ) {
143
186
@tracked = map {
144
- chomp $_ ; $_ ;
187
+ chomp $_ ;
188
+ unquote_path($_ );
145
189
} run_cmd_pipe(qw( git ls-files --exclude-standard --) , @ARGV );
146
190
return if (!@tracked );
147
191
}
@@ -153,6 +197,7 @@ sub list_modified {
153
197
if (($add , $del , $file ) =
154
198
/ ^([-\d ]+) ([-\d ]+) (.*)/ ) {
155
199
my ($change , $bin );
200
+ $file = unquote_path($file );
156
201
if ($add eq ' -' && $del eq ' -' ) {
157
202
$change = ' binary' ;
158
203
$bin = 1;
@@ -168,13 +213,15 @@ sub list_modified {
168
213
}
169
214
elsif (($adddel , $file ) =
170
215
/ ^ (create|delete) mode [0-7]+ (.*)$ / ) {
216
+ $file = unquote_path($file );
171
217
$data {$file }{INDEX_ADDDEL } = $adddel ;
172
218
}
173
219
}
174
220
175
221
for (run_cmd_pipe(qw( git diff-files --numstat --summary --) , @tracked )) {
176
222
if (($add , $del , $file ) =
177
223
/ ^([-\d ]+) ([-\d ]+) (.*)/ ) {
224
+ $file = unquote_path($file );
178
225
if (!exists $data {$file }) {
179
226
$data {$file } = +{
180
227
INDEX => ' unchanged' ,
@@ -196,6 +243,7 @@ sub list_modified {
196
243
}
197
244
elsif (($adddel , $file ) =
198
245
/ ^ (create|delete) mode [0-7]+ (.*)$ / ) {
246
+ $file = unquote_path($file );
199
247
$data {$file }{FILE_ADDDEL } = $adddel ;
200
248
}
201
249
}
@@ -302,7 +350,8 @@ sub find_unique_prefixes {
302
350
}
303
351
%search = %{$search {$letter }};
304
352
}
305
- if ($soft_limit && $j + 1 > $soft_limit ) {
353
+ if (ord ($letters [0]) > 127 ||
354
+ ($soft_limit && $j + 1 > $soft_limit )) {
306
355
$prefix = undef ;
307
356
$remainder = $ret ;
308
357
}
0 commit comments