File tree Expand file tree Collapse file tree 3 files changed +61
-43
lines changed Expand file tree Collapse file tree 3 files changed +61
-43
lines changed Original file line number Diff line number Diff line change 3
3
use 5.008;
4
4
use strict;
5
5
use warnings;
6
- use Git;
6
+ use Git qw( unquote_path ) ;
7
7
use Git::I18N;
8
8
9
9
binmode (STDOUT , " :raw" );
@@ -175,47 +175,6 @@ sub run_cmd_pipe {
175
175
}
176
176
chomp ($GIT_DIR );
177
177
178
- my %cquote_map = (
179
- " b" => chr (8),
180
- " t" => chr (9),
181
- " n" => chr (10),
182
- " v" => chr (11),
183
- " f" => chr (12),
184
- " r" => chr (13),
185
- " \\ " => " \\ " ,
186
- " \042 " => " \042 " ,
187
- );
188
-
189
- sub unquote_path {
190
- local ($_ ) = @_ ;
191
- my ($retval , $remainder );
192
- if (!/^\042(.*)\042$/ ) {
193
- return $_ ;
194
- }
195
- ($_ , $retval ) = ($1 , " " );
196
- while (/ ^([^\\ ]*)\\ (.*)$ / ) {
197
- $remainder = $2 ;
198
- $retval .= $1 ;
199
- for ($remainder ) {
200
- if (/ ^([0-3][0-7][0-7])(.*)$ / ) {
201
- $retval .= chr (oct ($1 ));
202
- $_ = $2 ;
203
- last ;
204
- }
205
- if (/ ^([\\\042 btnvfr])(.*)$ / ) {
206
- $retval .= $cquote_map {$1 };
207
- $_ = $2 ;
208
- last ;
209
- }
210
- # This is malformed -- just return it as-is for now.
211
- return $_ [0];
212
- }
213
- $_ = $remainder ;
214
- }
215
- $retval .= $_ ;
216
- return $retval ;
217
- }
218
-
219
178
sub refresh {
220
179
my $fh ;
221
180
open $fh , ' git update-index --refresh |'
Original file line number Diff line number Diff line change @@ -61,7 +61,8 @@ require Exporter;
61
61
remote_refs prompt
62
62
get_tz_offset get_record
63
63
credential credential_read credential_write
64
- temp_acquire temp_is_locked temp_release temp_reset temp_path) ;
64
+ temp_acquire temp_is_locked temp_release temp_reset temp_path
65
+ unquote_path) ;
65
66
66
67
67
68
=head1 DESCRIPTION
@@ -1451,6 +1452,57 @@ sub prefix_lines {
1451
1452
return $string ;
1452
1453
}
1453
1454
1455
+ =item unquote_path ( PATH )
1456
+
1457
+ Unquote a quoted path containing c-escapes as returned by ls-files etc.
1458
+ when not using -z or when parsing the output of diff -u.
1459
+
1460
+ =cut
1461
+
1462
+ {
1463
+ my %cquote_map = (
1464
+ " a" => chr (7),
1465
+ " b" => chr (8),
1466
+ " t" => chr (9),
1467
+ " n" => chr (10),
1468
+ " v" => chr (11),
1469
+ " f" => chr (12),
1470
+ " r" => chr (13),
1471
+ " \\ " => " \\ " ,
1472
+ " \042 " => " \042 " ,
1473
+ );
1474
+
1475
+ sub unquote_path {
1476
+ local ($_ ) = @_ ;
1477
+ my ($retval , $remainder );
1478
+ if (!/^\042(.*)\042$/ ) {
1479
+ return $_ ;
1480
+ }
1481
+ ($_ , $retval ) = ($1 , " " );
1482
+ while (/ ^([^\\ ]*)\\ (.*)$ / ) {
1483
+ $remainder = $2 ;
1484
+ $retval .= $1 ;
1485
+ for ($remainder ) {
1486
+ if (/ ^([0-3][0-7][0-7])(.*)$ / ) {
1487
+ $retval .= chr (oct ($1 ));
1488
+ $_ = $2 ;
1489
+ last ;
1490
+ }
1491
+ if (/ ^([\\\042 abtnvfr])(.*)$ / ) {
1492
+ $retval .= $cquote_map {$1 };
1493
+ $_ = $2 ;
1494
+ last ;
1495
+ }
1496
+ # This is malformed
1497
+ throw Error::Simple(" invalid quoted path $_ [0]" );
1498
+ }
1499
+ $_ = $remainder ;
1500
+ }
1501
+ $retval .= $_ ;
1502
+ return $retval ;
1503
+ }
1504
+ }
1505
+
1454
1506
=item get_comment_line_char ( )
1455
1507
1456
1508
Gets the core.commentchar configuration value.
Original file line number Diff line number Diff line change @@ -133,6 +133,13 @@ sub adjust_dirsep {
133
133
unlink $tmpfile3 ;
134
134
chdir ($abs_repo_dir );
135
135
136
+ # unquoting paths
137
+ is(Git::unquote_path(' abc' ), ' abc' , ' unquote unquoted path' );
138
+ is(Git::unquote_path(' "abc def"' ), ' abc def' , ' unquote simple quoted path' );
139
+ is(Git::unquote_path(' "abc\"\\\\ \a\b\t\n\v\f\r\001\040"' ),
140
+ " abc\"\\ \x07\x08\x09\x0a\x0b\x0c\x0d\x01 " ,
141
+ ' unquote escape sequences' );
142
+
136
143
printf " 1..%d \n " , Test::More-> builder-> current_test;
137
144
138
145
my $is_passing = eval { Test::More-> is_passing };
You can’t perform that action at this time.
0 commit comments