diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-07-10 13:42:50 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-07-10 13:42:50 -0700 |
commit | 9bf8e0c73d28eeede51f8d5cb75865eb544e7d47 (patch) | |
tree | 856327a74e516198a9999ac23466c48816b6657a /perl | |
parent | c4f70d2c9025b6dad34d0833a87d8ac24c221956 (diff) | |
parent | 3f9c637ec7c28dc9de5937b45334ee11875e9fe8 (diff) | |
download | git-9bf8e0c73d28eeede51f8d5cb75865eb544e7d47.tar.gz |
Merge branch 'pw/unquote-path-in-git-pm'
Code refactoring.
* pw/unquote-path-in-git-pm:
t9700: add tests for Git::unquote_path()
Git::unquote_path(): throw an exception on bad path
Git::unquote_path(): handle '\a'
add -i: move unquote_path() to Git.pm
Diffstat (limited to 'perl')
-rw-r--r-- | perl/Git.pm | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/perl/Git.pm b/perl/Git.pm index bfce1f795d..f4b56e6d4d 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -61,7 +61,8 @@ require Exporter; remote_refs prompt get_tz_offset get_record credential credential_read credential_write - temp_acquire temp_is_locked temp_release temp_reset temp_path); + temp_acquire temp_is_locked temp_release temp_reset temp_path + unquote_path); =head1 DESCRIPTION @@ -1451,6 +1452,57 @@ sub prefix_lines { return $string; } +=item unquote_path ( PATH ) + +Unquote a quoted path containing c-escapes as returned by ls-files etc. +when not using -z or when parsing the output of diff -u. + +=cut + +{ + my %cquote_map = ( + "a" => chr(7), + "b" => chr(8), + "t" => chr(9), + "n" => chr(10), + "v" => chr(11), + "f" => chr(12), + "r" => chr(13), + "\\" => "\\", + "\042" => "\042", + ); + + sub unquote_path { + local ($_) = @_; + my ($retval, $remainder); + if (!/^\042(.*)\042$/) { + return $_; + } + ($_, $retval) = ($1, ""); + while (/^([^\\]*)\\(.*)$/) { + $remainder = $2; + $retval .= $1; + for ($remainder) { + if (/^([0-3][0-7][0-7])(.*)$/) { + $retval .= chr(oct($1)); + $_ = $2; + last; + } + if (/^([\\\042abtnvfr])(.*)$/) { + $retval .= $cquote_map{$1}; + $_ = $2; + last; + } + # This is malformed + throw Error::Simple("invalid quoted path $_[0]"); + } + $_ = $remainder; + } + $retval .= $_; + return $retval; + } +} + =item get_comment_line_char ( ) Gets the core.commentchar configuration value. |