From c8a4111320aaed484deecbbc7d1f63f38f3dc57b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 18 Jan 2019 10:21:40 +0000 Subject: git: add git_quote It'll be helpful for displaying progress in SolverGit output. --- lib/PublicInbox/Git.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index a270180c..d0ac6b6c 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -13,7 +13,7 @@ use POSIX qw(dup2); require IO::Handle; use PublicInbox::Spawn qw(spawn popen_rd); use base qw(Exporter); -our @EXPORT_OK = qw(git_unquote); +our @EXPORT_OK = qw(git_unquote git_quote); my %GIT_ESC = ( a => "\a", @@ -26,6 +26,8 @@ my %GIT_ESC = ( '"' => '"', '\\' => '\\', ); +my %ESC_GIT = map { $GIT_ESC{$_} => $_ } keys %GIT_ESC; + # unquote pathnames used by git, see quote.c::unquote_c_style.c in git.git sub git_unquote ($) { @@ -36,6 +38,14 @@ sub git_unquote ($) { $_[0]; } +sub git_quote ($) { + if ($_[0] =~ s/([\\"\a\b\f\n\r\t\013]|[^[:print:]])/ + '\\'.($ESC_GIT{$1}||sprintf("%0o",ord($1)))/egs) { + return qq{"$_[0]"}; + } + $_[0]; +} + sub new { my ($class, $git_dir) = @_; my @st; -- cgit v1.2.3-24-ge0c7