]> Sergey Matveev's repositories - public-inbox.git/commitdiff
solver: restore diagnostics and deal with CRLF
authorEric Wong <e@80x24.org>
Sat, 19 Jan 2019 21:57:26 +0000 (21:57 +0000)
committerEric Wong <e@80x24.org>
Sun, 20 Jan 2019 04:24:54 +0000 (04:24 +0000)
Apparently Email::MIME returns quoted-printable text
with CRLF.  So use --ignore-whitespace with git-apply(1)
and ensure we don't capture '\r' in pathnames from
those emails.

And restore "$@" dumping when we die while solving.

lib/PublicInbox/SolverGit.pm

index 13065348b1da882c23843df3268de017106f7f1a..8fde2329fa757a639aba76375c4ab63ffa55ab1b 100644 (file)
@@ -105,6 +105,11 @@ sub extract_diff ($$$$) {
 
                        my ($path_a, $path_b) = ($1, $2);
 
+                       # diff header lines won't have \r because git
+                       # will quote them, but Email::MIME gives CRLF
+                       # for quoted-printable:
+                       $path_b =~ tr/\r//d;
+
                        # don't care for leading 'a/' and 'b/'
                        my (undef, @a) = split(m{/}, git_unquote($path_a));
                        my (undef, @b) = split(m{/}, git_unquote($path_b));
@@ -248,8 +253,11 @@ sub do_apply_begin ($$$) {
 
        defined(my $err_fd = fileno($out)) or die "fileno(out): $!";
        my $rdr = { 0 => fileno($tmp), 1 => $err_fd, 2 => $err_fd };
+
+       # we need --ignore-whitespace because some patches are CRLF
        my $cmd = [ qw(git -C), $wt_dir,
-                   qw(apply --cached --whitespace=warn --verbose) ];
+                   qw(apply --cached --ignore-whitespace
+                      --whitespace=warn --verbose) ];
        spawn($cmd, undef, $rdr);
 }
 
@@ -425,8 +433,12 @@ sub solve ($$$$) {
        };
 
        while (1) {
-               my $ret = $cb->();
-               return $ret if (ref($ret) || !defined($ret));
+               my $ret = eval { $cb->() };
+               unless (defined($ret)) {
+                       print $out "E: $@\n" if $@;
+                       return;
+               }
+               return $ret if ref($ret);
                # $ret == ''; so continue looping here
        }
 }