about summary refs log tree commit homepage
path: root/lib/PublicInbox/SolverGit.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-01-18 11:17:58 +0000
committerEric Wong <e@80x24.org>2019-01-19 03:34:54 +0000
commit2a292e40b0150f9b2d14fb3c400044047b93a151 (patch)
tree85dc01e9f7f64b284e9886a4775b07ea66eee94b /lib/PublicInbox/SolverGit.pm
parent77d9f14ee83324afc5961c0115480baa5ff5b475 (diff)
downloadpublic-inbox-2a292e40b0150f9b2d14fb3c400044047b93a151.tar.gz
No need to incur extra I/O traffic with a working-tree and
uncompressed files on the filesystem.  git can handle patch
application in memory and we rely on exact blob matching
anyways, so no need for 3way patch application.
Diffstat (limited to 'lib/PublicInbox/SolverGit.pm')
-rw-r--r--lib/PublicInbox/SolverGit.pm23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index d7209e65..8dfc52e1 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -215,7 +215,7 @@ sub reap ($$) {
         $? == 0 or die "$msg failed: $?";
 }
 
-sub prepare_wt ($$$$) {
+sub prepare_index ($$$$) {
         my ($out, $wt_dir, $existing, $di) = @_;
         my $oid_full = $existing->[1];
         my ($r, $w);
@@ -232,10 +232,7 @@ sub prepare_wt ($$$$) {
         close $w or die "close update-index: $!";
         reap($pid, 'update-index -z --index-info');
 
-        $pid = spawn([@git, qw(checkout-index -a -f -u)]);
-        reap($pid, 'checkout-index -a -f -u');
-
-        print $out "Working tree prepared:\n",
+        print $out "index prepared:\n",
                 "$mode_a $oid_full\t", git_quote($path_a), "\n";
 }
 
@@ -250,7 +247,7 @@ sub do_apply ($$$$) {
         defined(my $err_fd = fileno($out)) or die "fileno(out): $!";
         my $rdr = { 0 => fileno($tmp), 1 => $err_fd, 2 => $err_fd };
         my $cmd = [ qw(git -C), $wt_dir,
-                    qw(apply --whitespace=warn -3 --verbose) ];
+                    qw(apply --cached --whitespace=warn --verbose) ];
         reap(spawn($cmd, undef, $rdr), 'apply');
 
         local $/ = "\0";
@@ -267,11 +264,12 @@ sub do_apply ($$$$) {
 
         $file eq $di->{path_b} or
                 die "index mismatch: file=$file != path_b=$di->{path_b}";
-        my $abs_path = "$wt_dir/$file";
-        -r $abs_path or die "WT_DIR/$file not readable";
-        my $size = -s _;
 
-        print $out "OK $mode_b $oid_b_full $stage\t$file\n";
+        my (undef, undef, $size) = $wt_git->check($oid_b_full);
+
+        defined($size) or die "failed to read_size from $oid_b_full";
+
+        print $out "$mode_b $oid_b_full\t$file\n";
         [ $wt_git, $oid_b_full, 'blob', $size, $di ];
 }
 
@@ -308,10 +306,7 @@ sub apply_patches ($$$$$) {
 
                 # prepare the worktree for patch application:
                 if ($i == 1 && $existing) {
-                        prepare_wt($out, $wt_dir, $existing, $di);
-                }
-                if (!$empty_oid && ! -f "$wt_dir/$di->{path_a}") {
-                        die "missing $di->{path_a} at [$i/$tot] ", di_url($di);
+                        prepare_index($out, $wt_dir, $existing, $di);
                 }
 
                 print $out "\napplying [$i/$tot] ", di_url($di), "\n",