From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 78BE41F934 for ; Thu, 31 Dec 2020 13:51:54 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 01/36] import: respect init.defaultBranch Date: Thu, 31 Dec 2020 13:51:19 +0000 Message-Id: <20201231135154.6070-2-e@80x24.org> In-Reply-To: <20201231135154.6070-1-e@80x24.org> References: <20201231135154.6070-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This matches git v2.28.0+ behavior in case users prefer a different name. --- lib/PublicInbox/Import.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 079afc5f..7258e848 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -19,13 +19,21 @@ use PublicInbox::MDA; use PublicInbox::Eml; use POSIX qw(strftime); +sub default_branch () { + state $default_branch = do { + my $r = popen_rd([qw(git config --global init.defaultBranch)]); + chomp(my $h = <$r> // ''); + $h eq '' ? 'refs/heads/master' : $h; + } +} + sub new { # we can't change arg order, this is documented in POD # and external projects may rely on it: my ($class, $git, $name, $email, $ibx) = @_; - my $ref = 'refs/heads/master'; + my $ref; if ($ibx) { - $ref = $ibx->{ref_head} // 'refs/heads/master'; + $ref = $ibx->{ref_head}; $name //= $ibx->{name}; $email //= $ibx->{-primary_address}; $git //= $ibx->git; @@ -34,7 +42,7 @@ sub new { git => $git, ident => "$name <$email>", mark => 1, - ref => $ref, + ref => $ref // default_branch, ibx => $ibx, path_type => '2/38', # or 'v2' lock_path => "$git->{git_dir}/ssoma.lock", # v2 changes this @@ -441,7 +449,7 @@ sub run_die ($;$$) { $? == 0 or die join(' ', @$cmd) . " failed: $?\n"; } -my @INIT_FILES = ('HEAD' => "ref: refs/heads/master\n", +my @INIT_FILES = ('HEAD' => undef, # filled in at runtime 'description' => <{git}->{git_dir} if ref($dir); require File::Path; File::Path::mkpath([ map { "$dir/$_" } qw(objects/info refs/heads) ]); + $INIT_FILES[1] //= 'ref: '.default_branch."\n"; for (my $i = 0; $i < @INIT_FILES; $i++) { my $f = $dir.'/'.$INIT_FILES[$i++]; next if -f $f;