]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import: init_bare: use pure Perl
authorEric Wong <e@yhbt.net>
Sun, 19 Apr 2020 23:19:35 +0000 (23:19 +0000)
committerEric Wong <e@yhbt.net>
Mon, 20 Apr 2020 20:18:18 +0000 (20:18 +0000)
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

index 351bc660e19b862424e474de545beba50d26719b..95d654f667221711de6897ffd632b197bd6d10cf 100644 (file)
@@ -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 {