unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 2/4] import: init_bare: use pure Perl
Date: Sun, 19 Apr 2020 23:19:35 +0000	[thread overview]
Message-ID: <20200419231937.56365-3-e@yhbt.net> (raw)
In-Reply-To: <20200419231937.56365-1-e@yhbt.net>

Even on systems with Inline::C spawn(), this cuts a primed
"make check-run" time by 2-3% on Linux, and roughly 5-7% on
FreeBSD when using vfork-enabled spawn.

I doubt anybody cares: this omits the sample hooks and some
empty and useless-for-us or obsolete directories created by
git-init(1).
---
 lib/PublicInbox/Import.pm | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 351bc660..95d654f6 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -440,15 +440,31 @@ sub run_die ($;$$) {
 	$? == 0 or die join(' ', @$cmd) . " failed: $?\n";
 }
 
+my @INIT_FILES = ('HEAD' => "ref: refs/heads/master\n",
+		'description' => <<EOD,
+Unnamed repository; edit this file 'description' to name the repository.
+EOD
+		'config' => <<EOC);
+[core]
+	repositoryFormatVersion = 0
+	filemode = true
+	bare = true
+[repack]
+	writeBitmaps = true
+EOC
+
 sub init_bare {
 	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:
-	@cmd = (qw/git config/, "--file=$dir/config",
-		'repack.writeBitmaps', 'true');
-	run_die(\@cmd);
+	require File::Path;
+	File::Path::mkpath([ map { "$dir/$_" } qw(objects/info refs/heads) ]);
+	for (my $i = 0; $i < @INIT_FILES; $i++) {
+		my $f = $dir.'/'.$INIT_FILES[$i++];
+		next if -f $f;
+		open my $fh, '>', $f or die "open $f: $!";
+		print $fh $INIT_FILES[$i] or die "print $f: $!";
+		close $fh or die "close $f: $!";
+	}
 }
 
 sub done {

  parent reply	other threads:[~2020-04-19 23:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-19 23:19 [PATCH 0/4] test speedups for FreeBSD Eric Wong
2020-04-19 23:19 ` [PATCH 1/4] import: init_bare: allow use as method, use in tests Eric Wong
2020-04-19 23:19 ` Eric Wong [this message]
2020-04-19 23:19 ` [PATCH 3/4] t/ds-leak: use BSD::Resource Eric Wong
2020-04-19 23:19 ` [PATCH 4/4] testcommon: spawn-aware system() and qx[] workalikes Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200419231937.56365-3-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).