add -i: move unquote_path() to Git.pm
Move unquote_path() from git-add--interactive to Git.pm so it can be used by other scripts. Note this is a straight copy, it does not handle '\a'. That will be fixed in the next commit. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Jun 30, 2017 at 10:49 UTC
1d542a5487f788874f18cca0d23b7b680fa04119
2 files changed
+53
-43
git-add--interactive.perl
+1
-42
@@ -3,7 +3,7 @@
3
use 5.008;
4
use strict;
5
use warnings;
6
-use Git;
6
+use Git qw(unquote_path);
7
use Git::I18N;
8
9
binmode(STDOUT, ":raw");
@@ -175,47 +175,6 @@ if (!defined $GIT_DIR) {
175
}
176
chomp($GIT_DIR);
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 (/^([\\\042btnvfr])(.*)$/) {
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
-
178
sub refresh {
179
my $fh;
180
open $fh, 'git update-index --refresh |'
perl/Git.pm
+52
-1
@@ -61,7 +61,8 @@ require Exporter;
61
remote_refs prompt
62
get_tz_offset get_record
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);
66
67
68
=head1 DESCRIPTION
@@ -1451,6 +1452,56 @@ sub prefix_lines {
1452
return $string;
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
+ "b" => chr(8),
1465
+ "t" => chr(9),
1466
+ "n" => chr(10),
1467
+ "v" => chr(11),
1468
+ "f" => chr(12),
1469
+ "r" => chr(13),
1470
+ "\\" => "\\",
1471
+ "\042" => "\042",
1472
+ );
1473
+
1474
+ sub unquote_path {
1475
+ local ($_) = @_;
1476
+ my ($retval, $remainder);
1477
+ if (!/^\042(.*)\042$/) {
1478
+ return $_;
1479
+ }
1480
+ ($_, $retval) = ($1, "");
1481
+ while (/^([^\\]*)\\(.*)$/) {
1482
+ $remainder = $2;
1483
+ $retval .= $1;
1484
+ for ($remainder) {
1485
+ if (/^([0-3][0-7][0-7])(.*)$/) {
1486
+ $retval .= chr(oct($1));
1487
+ $_ = $2;
1488
+ last;
1489
+ }
1490
+ if (/^([\\\042btnvfr])(.*)$/) {
1491
+ $retval .= $cquote_map{$1};
1492
+ $_ = $2;
1493
+ last;
1494
+ }
1495
+ # This is malformed -- just return it as-is for now.
1496
+ return $_[0];
1497
+ }
1498
+ $_ = $remainder;
1499
+ }
1500
+ $retval .= $_;
1501
+ return $retval;
1502
+ }
1503
+}
1504
+
1505
=item get_comment_line_char ( )
1506
1507
Gets the core.commentchar configuration value.