about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-04-19 23:19:34 +0000
committerEric Wong <e@yhbt.net>2020-04-20 20:18:16 +0000
commitd55abcc42bde846d9047491125dd2b32645dafd8 (patch)
treea7dd9274b4790732aaa401757490919d3e8296b7
parentb3a04ae18a42ed960c89cc81c209633da6976380 (diff)
downloadpublic-inbox-d55abcc42bde846d9047491125dd2b32645dafd8.tar.gz
Allowing ->init_bare to be used as a method saves some
keystrokes, and we can save a little bit of time on systems with
our vfork(2)-enabled spawn().

This also sets us up for future improvements where we can
avoid spawning a process at all.
-rw-r--r--lib/PublicInbox/Import.pm3
-rw-r--r--lib/PublicInbox/V2Writable.pm5
-rw-r--r--t/admin.t3
-rw-r--r--t/altid.t2
-rw-r--r--t/cgi.t3
-rw-r--r--t/config.t3
-rw-r--r--t/convert-compact.t3
-rw-r--r--t/feed.t2
-rw-r--r--t/git.t5
-rw-r--r--t/html_index.t2
-rw-r--r--t/import.t3
-rw-r--r--t/mda.t3
-rw-r--r--t/nulsubject.t2
-rw-r--r--t/psgi_attach.t2
-rw-r--r--t/psgi_mount.t2
-rw-r--r--t/psgi_text.t2
-rw-r--r--t/search-thr-index.t3
-rw-r--r--t/solver_git.t3
-rw-r--r--t/v1-add-remove-add.t2
-rw-r--r--t/v1reindex.t2
-rw-r--r--t/watch_maildir.t3
-rw-r--r--t/watch_maildir_v2.t3
-rw-r--r--t/www_listing.t5
23 files changed, 37 insertions, 29 deletions
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index c72c1e92..351bc660 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -441,7 +441,8 @@ sub run_die ($;$$) {
 }
 
 sub init_bare {
-        my ($dir) = @_;
+        my ($dir) = @_; # or self
+        $dir = $dir->{git}->{git_dir} if ref($dir);
         my @cmd = (qw(git init --bare -q), $dir);
         run_die(\@cmd);
         # set a reasonable default:
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 1c78ef24..ca5f4f1b 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -730,9 +730,8 @@ sub fill_alternates ($$) {
 sub git_init {
         my ($self, $epoch) = @_;
         my $git_dir = "$self->{-inbox}->{inboxdir}/git/$epoch.git";
-        my @cmd = (qw(git init --bare -q), $git_dir);
-        PublicInbox::Import::run_die(\@cmd);
-        @cmd = (qw/git config/, "--file=$git_dir/config",
+        PublicInbox::Import::init_bare($git_dir);
+        my @cmd = (qw/git config/, "--file=$git_dir/config",
                         'include.path', '../../all.git/config');
         PublicInbox::Import::run_die(\@cmd);
         fill_alternates($self, $epoch);
diff --git a/t/admin.t b/t/admin.t
index 41aebe46..a9d67d25 100644
--- a/t/admin.t
+++ b/t/admin.t
@@ -4,13 +4,14 @@ use strict;
 use warnings;
 use Test::More;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 use_ok 'PublicInbox::Admin', qw(resolve_repo_dir);
 my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/v1";
 my $v2_dir = "$tmpdir/v2";
 my ($res, $err, $v);
 
-is(0, system(qw(git init -q --bare), $git_dir), 'git init v1');
+PublicInbox::Import::init_bare($git_dir);
 
 # v1
 is(resolve_repo_dir($git_dir), $git_dir, 'top-level GIT_DIR resolved');
diff --git a/t/altid.t b/t/altid.t
index 6c34cdd6..3134e627 100644
--- a/t/altid.t
+++ b/t/altid.t
@@ -23,9 +23,9 @@ my $ibx;
 }
 
 {
-        is(system(qw(git init -q --bare), $git_dir), 0, 'git init ok');
         my $git = PublicInbox::Git->new($git_dir);
         my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
+        $im->init_bare;
         $im->add(Email::MIME->create(
                 header => [
                         From => 'a@example.com',
diff --git a/t/cgi.t b/t/cgi.t
index 97bdebd9..52f80e88 100644
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -7,6 +7,7 @@ use warnings;
 use Test::More;
 use Email::MIME;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 require_mods(qw(Plack::Handler::CGI Plack::Util));
 my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/pi-home";
@@ -18,7 +19,7 @@ my $addr = 'test-public@example.com';
 {
         is(1, mkdir($home, 0755), "setup ~/ for testing");
         is(1, mkdir($pi_home, 0755), "setup ~/.public-inbox");
-        is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
+        PublicInbox::Import::init_bare($maindir);
 
         open my $fh, '>', "$maindir/description" or die "open: $!\n";
         print $fh "test for public-inbox\n";
diff --git a/t/config.t b/t/config.t
index d08c3b9c..0db12359 100644
--- a/t/config.t
+++ b/t/config.t
@@ -5,10 +5,11 @@ use warnings;
 use Test::More;
 use PublicInbox::Config;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 my ($tmpdir, $for_destroy) = tmpdir();
 
 {
-        is(system(qw(git init -q --bare), $tmpdir), 0, "git init successful");
+        PublicInbox::Import::init_bare($tmpdir);
         my @cmd = ('git', "--git-dir=$tmpdir", qw(config foo.bar), "hi\nhi");
         is(system(@cmd), 0, "set config");
 
diff --git a/t/convert-compact.t b/t/convert-compact.t
index 70609c7d..af16b701 100644
--- a/t/convert-compact.t
+++ b/t/convert-compact.t
@@ -20,8 +20,7 @@ my $ibx = {
         -primary_address => 'test@example.com',
 };
 
-ok(PublicInbox::Import::run_die([qw(git init --bare -q), $ibx->{inboxdir}]),
-        'initialized v1 repo');
+PublicInbox::Import::init_bare($ibx->{inboxdir});
 ok(umask(077), 'set restrictive umask');
 ok(PublicInbox::Import::run_die([qw(git) , "--git-dir=$ibx->{inboxdir}",
         qw(config core.sharedRepository 0644)]), 'set sharedRepository');
diff --git a/t/feed.t b/t/feed.t
index cfa09a7c..ffd5ca7e 100644
--- a/t/feed.t
+++ b/t/feed.t
@@ -34,7 +34,7 @@ my $git = $ibx->git;
 my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
 
 {
-        is(0, system(qw(git init -q --bare), $git_dir), "git init");
+        $im->init_bare;
         local $ENV{GIT_DIR} = $git_dir;
 
         foreach my $i (1..6) {
diff --git a/t/git.t b/t/git.t
index 8224969d..0936ac5e 100644
--- a/t/git.t
+++ b/t/git.t
@@ -6,11 +6,12 @@ use Test::More;
 use PublicInbox::TestCommon;
 my ($dir, $for_destroy) = tmpdir();
 use PublicInbox::Spawn qw(popen_rd);
+use PublicInbox::Import;
 
 use_ok 'PublicInbox::Git';
 
 {
-        is(system(qw(git init -q --bare), $dir), 0, 'created git directory');
+        PublicInbox::Import::init_bare($dir);
         my $fi_data = './t/git.fast-import-data';
         ok(-r $fi_data, "fast-import data readable (or run test at top level)");
         local $ENV{GIT_DIR} = $dir;
@@ -90,7 +91,7 @@ if (1) {
 if ('alternates reloaded') {
         my ($alt, $alt_obj) = tmpdir();
         my @cmd = ('git', "--git-dir=$alt", qw(hash-object -w --stdin));
-        is(system(qw(git init -q --bare), $alt), 0, 'create alt directory');
+        PublicInbox::Import::init_bare($alt);
         open my $fh, '<', "$alt/config" or die "open failed: $!\n";
         my $rd = popen_rd(\@cmd, {}, { 0 => $fh } );
         close $fh or die "close failed: $!";
diff --git a/t/html_index.t b/t/html_index.t
index 158a7862..fda3962a 100644
--- a/t/html_index.t
+++ b/t/html_index.t
@@ -22,7 +22,7 @@ my $im = PublicInbox::Import->new($git, 'tester', 'test@example');
 
 # setup
 {
-        is(0, system(qw(git init -q --bare), $git_dir), "git init");
+        $im->init_bare;
         my $prev = "";
 
         foreach my $i (1..6) {
diff --git a/t/import.t b/t/import.t
index 703aa362..79af9846 100644
--- a/t/import.t
+++ b/t/import.t
@@ -12,10 +12,9 @@ use File::Temp qw/tempfile/;
 use PublicInbox::TestCommon;
 my ($dir, $for_destroy) = tmpdir();
 
-is(system(qw(git init -q --bare), $dir), 0, 'git init successful');
 my $git = PublicInbox::Git->new($dir);
-
 my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
+$im->init_bare;
 my $mime = PublicInbox::MIME->create(
         header => [
                 From => 'a@example.com',
diff --git a/t/mda.t b/t/mda.t
index ec09cf69..af5e1931 100644
--- a/t/mda.t
+++ b/t/mda.t
@@ -9,6 +9,7 @@ use PublicInbox::MID qw(mid2path);
 use PublicInbox::Git;
 use PublicInbox::InboxWritable;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/pi-home";
 my $pi_home = "$home/.public-inbox";
@@ -48,7 +49,7 @@ my $fail_bad_header = sub ($$$) {
                 "spamc mock found (run in top of source tree");
         is(1, mkdir($home, 0755), "setup ~/ for testing");
         is(1, mkdir($pi_home, 0755), "setup ~/.public-inbox");
-        is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
+        PublicInbox::Import::init_bare($maindir);
 
         open my $fh, '>>', $pi_config or die;
         print $fh <<EOF or die;
diff --git a/t/nulsubject.t b/t/nulsubject.t
index fec6c1ae..b21507c2 100644
--- a/t/nulsubject.t
+++ b/t/nulsubject.t
@@ -11,9 +11,9 @@ my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/a.git";
 
 {
-        is(system(qw(git init -q --bare), $git_dir), 0, 'git init ok');
         my $git = PublicInbox::Git->new($git_dir);
         my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
+        $im->init_bare;
         $im->add(Email::MIME->create(
                 header => [
                         From => 'a@example.com',
diff --git a/t/psgi_attach.t b/t/psgi_attach.t
index 297e92e1..a47f3754 100644
--- a/t/psgi_attach.t
+++ b/t/psgi_attach.t
@@ -21,9 +21,9 @@ my $config = PublicInbox::Config->new(\<<EOF);
 $cfgpfx.address=$addr
 $cfgpfx.inboxdir=$maindir
 EOF
-is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
 my $git = PublicInbox::Git->new($maindir);
 my $im = PublicInbox::Import->new($git, 'test', $addr);
+$im->init_bare;
 
 {
         open my $fh, '<', '/dev/urandom' or die "unable to open urandom: $!\n";
diff --git a/t/psgi_mount.t b/t/psgi_mount.t
index 8cac3502..3afb1fb5 100644
--- a/t/psgi_mount.t
+++ b/t/psgi_mount.t
@@ -21,9 +21,9 @@ my $config = PublicInbox::Config->new(\<<EOF);
 $cfgpfx.address=$addr
 $cfgpfx.inboxdir=$maindir
 EOF
-is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
 my $git = PublicInbox::Git->new($maindir);
 my $im = PublicInbox::Import->new($git, 'test', $addr);
+$im->init_bare;
 {
         my $mime = Email::MIME->new(<<EOF);
 From: Me <me\@example.com>
diff --git a/t/psgi_text.t b/t/psgi_text.t
index 6d8a518d..77fc9ee2 100644
--- a/t/psgi_text.t
+++ b/t/psgi_text.t
@@ -21,7 +21,7 @@ my $config = PublicInbox::Config->new(\<<EOF);
 $cfgpfx.address=$addr
 $cfgpfx.inboxdir=$maindir
 EOF
-is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
+PublicInbox::Import::init_bare($maindir);
 my $www = PublicInbox::WWW->new($config);
 
 test_psgi(sub { $www->call(@_) }, sub {
diff --git a/t/search-thr-index.t b/t/search-thr-index.t
index f073304a..6c564b19 100644
--- a/t/search-thr-index.t
+++ b/t/search-thr-index.t
@@ -11,10 +11,11 @@ require_mods(qw(DBD::SQLite Search::Xapian));
 require PublicInbox::SearchIdx;
 require PublicInbox::Smsg;
 require PublicInbox::Inbox;
+use PublicInbox::Import;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/a.git";
 
-is(0, system(qw(git init -q --bare), $git_dir), "git init (main)");
+PublicInbox::Import::init_bare($git_dir);
 my $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
 ok($rw, "search indexer created");
diff --git a/t/solver_git.t b/t/solver_git.t
index 7f0cd999..b5231d2c 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -109,7 +109,8 @@ SKIP: {
         require_mods(@psgi, 7 + scalar(@psgi));
         use_ok($_) for @psgi;
         my $binfoo = "$inboxdir/binfoo.git";
-        system(qw(git init --bare -q), $binfoo) == 0 or die "git init: $?";
+        require PublicInbox::Import;
+        PublicInbox::Import::init_bare($binfoo);
         require_ok 'PublicInbox::ViewVCS';
         my $big_size = do {
                 no warnings 'once';
diff --git a/t/v1-add-remove-add.t b/t/v1-add-remove-add.t
index 736e414e..fdf06a96 100644
--- a/t/v1-add-remove-add.t
+++ b/t/v1-add-remove-add.t
@@ -9,7 +9,6 @@ use PublicInbox::TestCommon;
 require_mods(qw(DBD::SQLite Search::Xapian));
 require PublicInbox::SearchIdx;
 my ($inboxdir, $for_destroy) = tmpdir();
-is(system(qw(git init --bare -q), $inboxdir), 0);
 my $ibx = {
         inboxdir => $inboxdir,
         name => 'test-add-remove-add',
@@ -27,6 +26,7 @@ my $mime = PublicInbox::MIME->create(
         body => "hello world\n",
 );
 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
+$im->init_bare;
 ok($im->add($mime), 'message added');
 ok($im->remove($mime), 'message removed');
 ok($im->add($mime), 'message added again');
diff --git a/t/v1reindex.t b/t/v1reindex.t
index 240e28f9..378c8efb 100644
--- a/t/v1reindex.t
+++ b/t/v1reindex.t
@@ -12,7 +12,6 @@ require_mods(qw(DBD::SQLite Search::Xapian));
 use_ok 'PublicInbox::SearchIdx';
 use_ok 'PublicInbox::Import';
 my ($inboxdir, $for_destroy) = tmpdir();
-is(system(qw(git init -q --bare), $inboxdir), 0);
 my $ibx_config = {
         inboxdir => $inboxdir,
         name => 'test-v1reindex',
@@ -35,6 +34,7 @@ my ($mark1, $mark2, $mark3, $mark4);
         my %config = %$ibx_config;
         my $ibx = PublicInbox::Inbox->new(\%config);
         my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
+        $im->init_bare;
         foreach my $i (1..10) {
                 $mime->header_set('Message-Id', "<$i\@example.com>");
                 ok($im->add($mime), "message $i added");
diff --git a/t/watch_maildir.t b/t/watch_maildir.t
index 5fb908fb..9ed04cab 100644
--- a/t/watch_maildir.t
+++ b/t/watch_maildir.t
@@ -6,6 +6,7 @@ use Email::MIME;
 use Cwd;
 use PublicInbox::Config;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 require_mods(qw(Filesys::Notify::Simple));
 my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/test.git";
@@ -15,7 +16,7 @@ use_ok 'PublicInbox::WatchMaildir';
 use_ok 'PublicInbox::Emergency';
 my $cfgpfx = "publicinbox.test";
 my $addr = 'test-public@example.com';
-is(system(qw(git init -q --bare), $git_dir), 0, 'initialized git dir');
+PublicInbox::Import::init_bare($git_dir);
 
 my $msg = <<EOF;
 From: user\@example.com
diff --git a/t/watch_maildir_v2.t b/t/watch_maildir_v2.t
index 685cd6ed..dd5030ea 100644
--- a/t/watch_maildir_v2.t
+++ b/t/watch_maildir_v2.t
@@ -6,6 +6,7 @@ use PublicInbox::MIME;
 use Cwd;
 use PublicInbox::Config;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 require_git(2.6);
 require_mods(qw(Search::Xapian DBD::SQLite Filesys::Notify::Simple));
 require PublicInbox::V2Writable;
@@ -141,7 +142,7 @@ More majordomo info at  http://vger.kernel.org/majordomo-info.html\n);
         my $v1repo = "$tmpdir/v1";
         my $v1pfx = "publicinbox.v1";
         my $v1addr = 'v1-public@example.com';
-        is(system(qw(git init -q --bare), $v1repo), 0, 'v1 init OK');
+        PublicInbox::Import::init_bare($v1repo);
         my $cfg2 = <<EOF;
 $orig$v1pfx.address=$v1addr
 $v1pfx.inboxdir=$v1repo
diff --git a/t/www_listing.t b/t/www_listing.t
index 9230329c..c132edbc 100644
--- a/t/www_listing.t
+++ b/t/www_listing.t
@@ -6,6 +6,7 @@ use warnings;
 use Test::More;
 use PublicInbox::Spawn qw(which);
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 require_mods(qw(URI::Escape Plack::Builder Digest::SHA
                 IO::Compress::Gzip IO::Uncompress::Gunzip HTTP::Tiny));
 require PublicInbox::WwwListing;
@@ -18,7 +19,7 @@ use_ok 'PublicInbox::Git';
 
 my ($tmpdir, $for_destroy) = tmpdir();
 my $bare = PublicInbox::Git->new("$tmpdir/bare.git");
-is(system(qw(git init -q --bare), $bare->{git_dir}), 0, 'git init --bare');
+PublicInbox::Import::init_bare($bare->{git_dir});
 is(PublicInbox::WwwListing::fingerprint($bare), undef,
         'empty repo has no fingerprint');
 {
@@ -77,7 +78,7 @@ SKIP: {
         my @clone = qw(git clone -q -s --bare);
         is(system(@clone, $bare->{git_dir}, $alt), 0, 'clone shared repo');
 
-        system(qw(git init --bare -q), "$v2/all.git") == 0 or die;
+        PublicInbox::Import::init_bare("$v2/all.git");
         for my $i (0..2) {
                 is(system(@clone, $alt, "$v2/git/$i.git"), 0, "clone epoch $i");
         }