about summary refs log tree commit homepage
path: root/lib/PublicInbox/SolverGit.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-29 09:26:30 +0000
committerEric Wong <e@80x24.org>2022-08-29 19:05:42 +0000
commit1a8bb5fb6263cb2a709687267ecc684862ce7768 (patch)
tree4f39f666225a7ca87a650296c1224afa5b31c697 /lib/PublicInbox/SolverGit.pm
parent105a1da9cf6d091e2b1978d3dbe3cde2fce1a2cb (diff)
downloadpublic-inbox-1a8bb5fb6263cb2a709687267ecc684862ce7768.tar.gz
"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.
Diffstat (limited to 'lib/PublicInbox/SolverGit.pm')
-rw-r--r--lib/PublicInbox/SolverGit.pm16
1 files 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'}) {