user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH 0/2] minor prep for diff viewing enhancements
@ 2019-01-13  8:52 Eric Wong
  2019-01-13  8:52 ` [PATCH 1/2] searchidx: move git_unquote to PublicInbox::Git Eric Wong
  2019-01-13  8:52 ` [PATCH 2/2] git_unquote: perform modifications in-place Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2019-01-13  8:52 UTC (permalink / raw)
  To: meta

Eric Wong (2):
  searchidx: move git_unquote to PublicInbox::Git
  git_unquote: perform modifications in-place

 lib/PublicInbox/Git.pm       | 21 +++++++++++++++++++++
 lib/PublicInbox/SearchIdx.pm | 21 +--------------------
 t/git.t                      |  4 ++++
 3 files changed, 26 insertions(+), 20 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] searchidx: move git_unquote to PublicInbox::Git
  2019-01-13  8:52 [PATCH 0/2] minor prep for diff viewing enhancements Eric Wong
@ 2019-01-13  8:52 ` Eric Wong
  2019-01-13  8:52 ` [PATCH 2/2] git_unquote: perform modifications in-place Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2019-01-13  8:52 UTC (permalink / raw)
  To: meta

We'll be using it outside of searchidx...
---
 lib/PublicInbox/Git.pm       | 22 ++++++++++++++++++++++
 lib/PublicInbox/SearchIdx.pm | 21 +--------------------
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 1611727..8d3f87d 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) = @_;
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 8810fe7..db0495b 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -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/;
-- 
EW


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] git_unquote: perform modifications in-place
  2019-01-13  8:52 [PATCH 0/2] minor prep for diff viewing enhancements Eric Wong
  2019-01-13  8:52 ` [PATCH 1/2] searchidx: move git_unquote to PublicInbox::Git Eric Wong
@ 2019-01-13  8:52 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2019-01-13  8:52 UTC (permalink / raw)
  To: meta

This function doesn't have a lot of callers at the moment so
none of them are affected by this change.  But the plan is to
use this in our WWW code for things, so do it now before we
call it in more places.

Results from a Thinkpad X200 with a Core2Duo P8600 @ 2.4GHz:

Benchmark: timing 10 iterations of cp, ip...
        cp: 12.868 wallclock secs (12.86 usr +  0.00 sys = 12.86 CPU) @  0.78/s (n=10)
        ip: 10.9137 wallclock secs (10.91 usr +  0.00 sys = 10.91 CPU) @  0.92/s (n=10)

Note: I mainly care about unquoted performance because
that's the common case for the target audience of public-inbox.

Script used to get benchmark results against the Linux source tree:
==> bench_unquote.perl <==
use strict;
use warnings;
use Benchmark ':hireswallclock';
my $nr = 50;

my %GIT_ESC = (
	a => "\a",
	b => "\b",
	f => "\f",
	n => "\n",
	r => "\r",
	t => "\t",
	v => "\013",
);

sub git_unquote_ip ($) {
	return $_[0] unless ($_[0] =~ /\A"(.*)"\z/);
	$_[0] = $1;
	$_[0] =~ s/\\([abfnrtv])/$GIT_ESC{$1}/g;
	$_[0] =~ s/\\([0-7]{1,3})/chr(oct($1))/ge;
	$_[0];
}

sub git_unquote_cp ($) {
	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;
}

chomp(my @files = `git -C ~/linux ls-tree --name-only -r v4.19.13`);
timethese(10, {
	cp => sub { for (0..$nr) { git_unquote_cp($_) for @files } },
	ip => sub { for (0..$nr) { git_unquote_ip($_) for @files } },
});
---
 lib/PublicInbox/Git.pm | 11 +++++------
 t/git.t                |  4 ++++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 8d3f87d..4601f25 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -27,12 +27,11 @@ my %GIT_ESC = (
 
 # 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;
+	return $_[0] unless ($_[0] =~ /\A"(.*)"\z/);
+	$_[0] = $1;
+	$_[0] =~ s/\\([abfnrtv])/$GIT_ESC{$1}/g;
+	$_[0] =~ s/\\([0-7]{1,3})/chr(oct($1))/ge;
+	$_[0];
 }
 
 sub new {
diff --git a/t/git.t b/t/git.t
index 6538b6c..50ec4fb 100644
--- a/t/git.t
+++ b/t/git.t
@@ -144,4 +144,8 @@ if ('alternates reloaded') {
 	is($$found, $config, 'alternates reloaded');
 }
 
+use_ok 'PublicInbox::Git', qw(git_unquote);
+is("foo\nbar", git_unquote('"foo\\nbar"'.''), 'unquoted newline');
+is("Eléanor", git_unquote('"El\\303\\251anor"'.''), 'unquoted octal');
+
 done_testing();
-- 
EW


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-13  8:52 [PATCH 0/2] minor prep for diff viewing enhancements Eric Wong
2019-01-13  8:52 ` [PATCH 1/2] searchidx: move git_unquote to PublicInbox::Git Eric Wong
2019-01-13  8:52 ` [PATCH 2/2] git_unquote: perform modifications in-place Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox