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-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE 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 043C61F59D for ; Mon, 29 Aug 2022 09:26:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1661765208; bh=OQ9Itwy0l1ddwCrXDnFPu/z/mP8BKoEW9QGVna9MO8A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VlfLFpEIQ1TWp3m12wLWwm2hgUYIy7ilJzDJb2vGnfKhURTxOtY0rPE8dWwTOv4fd K3iPxK1P8bkw/V0RAxwQ+NQPEIWO6yvvnCiGuURrTweIkw8GsnCR+XtNfj5ZXn6XNb jzgSwudCnYAvizJGguskR2J1i/iBt3rFWUI7ULAM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 01/18] solver: create tmpdir lazily Date: Mon, 29 Aug 2022 09:26:30 +0000 Message-Id: <20220829092647.1512215-2-e@80x24.org> In-Reply-To: <20220829092647.1512215-1-e@80x24.org> References: <20220829092647.1512215-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: "lei blob" doesn't currently need it at all in some cases, and the next commit will allow viewvcs to share tmpdirs to show commits as HTML. --- lib/PublicInbox/SolverGit.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm index dbb9b739..52dfaf3d 100644 --- a/lib/PublicInbox/SolverGit.pm +++ b/lib/PublicInbox/SolverGit.pm @@ -106,6 +106,11 @@ sub solve_existing ($$) { scalar(@$try); } +sub _tmp { + $_[0]->{tmp} //= + File::Temp->newdir("solver.$_[0]->{oid_want}-XXXX", TMPDIR => 1); +} + sub extract_diff ($$) { my ($p, $arg) = @_; my ($self, $want, $smsg) = @$arg; @@ -193,8 +198,8 @@ sub extract_diff ($$) { my $path = ++$self->{tot}; $di->{n} = $path; - open(my $tmp, '>:utf8', $self->{tmp}->dirname . "/$path") or - die "open(tmp): $!"; + my $f = _tmp($self)->dirname."/$path"; + open(my $tmp, '>:utf8', $f) or die "open($f): $!"; print $tmp $di->{hdr_lines}, $patch or die "print(tmp): $!"; close $tmp or die "close(tmp): $!"; @@ -284,8 +289,7 @@ sub prepare_index ($) { # pure Perl "git init" sub do_git_init ($) { my ($self) = @_; - my $dir = $self->{tmp}->dirname; - my $git_dir = "$dir/git"; + my $git_dir = _tmp($self)->dirname.'/git'; foreach ('', qw(objects refs objects/info refs/heads)) { mkdir("$git_dir/$_") or die "mkdir $_: $!"; @@ -478,7 +482,6 @@ sub apply_result ($$) { sub do_git_apply ($) { my ($self) = @_; - my $dn = $self->{tmp}->dirname; my $patches = $self->{patches}; # we need --ignore-whitespace because some patches are CRLF @@ -501,7 +504,7 @@ sub do_git_apply ($) { } while (@$patches && $len < $ARG_SIZE_MAX && !oids_same_ish($patches->[0]->{oid_b}, $prv_oid_b)); - my $opt = { 2 => 1, -C => $dn, quiet => 1 }; + my $opt = { 2 => 1, -C => _tmp($self)->dirname, quiet => 1 }; my $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env}, $opt); $self->{-cur_di} = $di; $qsp->{qsp_err} = \($self->{-qsp_err} = ''); @@ -683,7 +686,6 @@ sub solve ($$$$$) { $self->{todo} = [ { %$hints, oid_b => $oid_want } ]; $self->{patches} = []; # [ $di, $di, ... ] $self->{found} = {}; # { abbr => [ ::Git, oid, type, size, $di ] } - $self->{tmp} = File::Temp->newdir("solver.$oid_want-XXXX", TMPDIR => 1); dbg($self, "solving $oid_want ..."); if (my $async = $env->{'pi-httpd.async'}) {