From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: 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.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4AB9D1FAE7 for ; Thu, 15 Feb 2018 11:08:45 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [WIP 05/17] import: begin supporting this without ssoma.lock Date: Thu, 15 Feb 2018 11:08:28 +0000 Message-Id: <20180215110840.30413-6-e@80x24.org> In-Reply-To: <20180215110840.30413-1-e@80x24.org> References: <20180215105509.GA22409@dcvr> <20180215110840.30413-1-e@80x24.org> List-Id: We'll reuse this class in v2, but won't be utilizing per-git-repository ssoma.lock files. Meanwhile, stop treating ::Inbox objects as an afterthought and allow importing name and email into them. --- lib/PublicInbox/Import.pm | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 299329b..56633a8 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -13,13 +13,20 @@ use PublicInbox::MID qw(mid_mime mid2path); use PublicInbox::Address; sub new { - my ($class, $git, $name, $email, $inbox) = @_; + my ($class, $git, $name, $email, $ibx) = @_; + my $ref = 'refs/heads/master'; + if ($ibx) { + $ref = $ibx->{ref_head} || 'refs/heads/master'; + $name ||= $ibx->{name}; + $email ||= $ibx->{-primary_address}; + } bless { git => $git, ident => "$name <$email>", mark => 1, - ref => 'refs/heads/master', - inbox => $inbox, + ref => $ref, + inbox => $ibx, + ssoma_lock => 1, # disable for v2 }, $class } @@ -34,12 +41,16 @@ sub gfi_start { pipe($out_r, $out_w) or die "pipe failed: $!"; my $git = $self->{git}; my $git_dir = $git->{git_dir}; - my $lockpath = "$git_dir/ssoma.lock"; - sysopen(my $lockfh, $lockpath, O_WRONLY|O_CREAT) or - die "failed to open lock $lockpath: $!"; - # wait for other processes to be done - flock($lockfh, LOCK_EX) or die "lock failed: $!\n"; + my $lockfh; + if ($self->{ssoma_lock}) { + my $lockpath = "$git_dir/ssoma.lock"; + sysopen($lockfh, $lockpath, O_WRONLY|O_CREAT) or + die "failed to open lock $lockpath: $!"; + # wait for other processes to be done + flock($lockfh, LOCK_EX) or die "lock failed: $!\n"; + } + local $/ = "\n"; chomp($self->{tip} = $git->qx(qw(rev-parse --revs-only), $self->{ref})); @@ -247,6 +258,7 @@ sub done { eval { run_die([@cmd, qw(gc --auto)], undef) }; } + $self->{ssoma_lock} or return; my $lockfh = delete $self->{lockfh} or die "BUG: not locked: $!"; flock($lockfh, LOCK_UN) or die "unlock failed: $!"; close $lockfh or die "close lock failed: $!"; -- EW