about summary refs log tree commit homepage
path: root/lib/PublicInbox/Git.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-01-18 10:21:40 +0000
committerEric Wong <e@80x24.org>2019-01-19 03:34:54 +0000
commitc8a4111320aaed484deecbbc7d1f63f38f3dc57b (patch)
treefb4928c875a279ac14ebf7c675907bc6472d051a /lib/PublicInbox/Git.pm
parent8d1766ef6c1ed2a390fe0313f9b8e34475c1d874 (diff)
downloadpublic-inbox-c8a4111320aaed484deecbbc7d1f63f38f3dc57b.tar.gz
It'll be helpful for displaying progress in SolverGit
output.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm12
1 files changed, 11 insertions, 1 deletions
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;