]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchidx: move git_unquote to PublicInbox::Git
authorEric Wong <e@80x24.org>
Tue, 15 Jan 2019 02:42:08 +0000 (02:42 +0000)
committerEric Wong <e@80x24.org>
Tue, 15 Jan 2019 20:57:06 +0000 (20:57 +0000)
We'll be using it outside of searchidx...

lib/PublicInbox/Git.pm
lib/PublicInbox/SearchIdx.pm

index 16117277079e86b6aecfc4291a3cf90e25928c0a..8d3f87d577565ea2f07123d890cde23a043185a5 100644 (file)
@@ -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) = @_;
index 8810fe76450dde64728d715e4e63f14b3c6bb741..db0495bcd8a90d313c1ea08cafab564d16baf541 100644 (file)
@@ -18,7 +18,7 @@ use Carp qw(croak);
 use POSIX qw(strftime);
 use PublicInbox::OverIdx;
 use PublicInbox::Spawn qw(spawn);
-require PublicInbox::Git;
+use PublicInbox::Git qw(git_unquote);
 use Compress::Zlib qw(compress);
 
 use constant {
@@ -29,25 +29,6 @@ use constant {
 
 my $xapianlevels = qr/\A(?:full|medium)\z/;
 
-my %GIT_ESC = (
-       a => "\a",
-       b => "\b",
-       f => "\f",
-       n => "\n",
-       r => "\r",
-       t => "\t",
-       v => "\013",
-);
-
-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, $ibx, $creat, $part) = @_;
        my $levels = qr/\A(?:full|medium|basic)\z/;