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-15 02:42:08 +0000
committerEric Wong <e@80x24.org>2019-01-15 20:57:06 +0000
commitfe20d568e82cdb3645b42f18f1691d64271aaf7b (patch)
treec88b7adffaedfed602f69f3c2ffd3d5998a19caf /lib/PublicInbox/Git.pm
parent50569c6e36d90689731d6519321920b4710b3e52 (diff)
downloadpublic-inbox-fe20d568e82cdb3645b42f18f1691d64271aaf7b.tar.gz
We'll be using it outside of searchidx...
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 16117277..8d3f87d5 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -12,6 +12,28 @@ use warnings;
 use POSIX qw(dup2);
 require IO::Handle;
 use PublicInbox::Spawn qw(spawn popen_rd);
+use base qw(Exporter);
+our @EXPORT_OK = qw(git_unquote);
+
+my %GIT_ESC = (
+        a => "\a",
+        b => "\b",
+        f => "\f",
+        n => "\n",
+        r => "\r",
+        t => "\t",
+        v => "\013",
+);
+
+# unquote pathnames used by git, see quote.c::unquote_c_style.c in git.git
+sub git_unquote ($) {
+        my ($s) = @_;
+        return $s unless ($s =~ /\A"(.*)"\z/);
+        $s = $1;
+        $s =~ s/\\([abfnrtv])/$GIT_ESC{$1}/g;
+        $s =~ s/\\([0-7]{1,3})/chr(oct($1))/ge;
+        $s;
+}
 
 sub new {
         my ($class, $git_dir) = @_;