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.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 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 16F8C1F9E5 for ; Wed, 5 May 2021 17:49:46 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] lei rediff: capture and regenerate file modes Date: Wed, 5 May 2021 17:49:43 +0000 Message-Id: <20210505174944.69155-3-e@80x24.org> In-Reply-To: <20210505174944.69155-1-e@80x24.org> References: <20210505174944.69155-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Don't lose file mode information when regenerating a diff. --- MANIFEST | 1 + lib/PublicInbox/LeiRediff.pm | 19 +++++++++++++++---- t/solve/bare.patch | 8 ++++++++ t/solver_git.t | 13 +++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 t/solve/bare.patch diff --git a/MANIFEST b/MANIFEST index 7be07aa5..a6d94c77 100644 --- a/MANIFEST +++ b/MANIFEST @@ -480,6 +480,7 @@ t/shared_kv.t t/sigfd.t t/solve/0001-simple-mod.patch t/solve/0002-rename-with-modifications.patch +t/solve/bare.patch t/solver_git.t t/spamcheck_spamc.t t/spawn.t diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm index 6c734bef..d73e3e28 100644 --- a/lib/PublicInbox/LeiRediff.pm +++ b/lib/PublicInbox/LeiRediff.pm @@ -16,6 +16,8 @@ use PublicInbox::Import; use PublicInbox::LEI; use PublicInbox::SolverGit; +my $MODE = '(100644|120000|100755|160000)'; + sub rediff_user_cb { # called by solver when done my ($res, $self) = @_; my $lei = $self->{lei}; @@ -69,7 +71,7 @@ EOM $tb =~ tr!A!B!; my $lei = $self->{lei}; my $wait = delete($self->{-do_done}) ? $lei->{sto}->ipc_do('done') : 0; - while (my ($oid_a, $oid_b, $pa, $pb) = splice(@$ctxq, 0, 4)) { + while (my ($oid_a, $oid_b, $pa, $pb, $ma, $mb) = splice(@$ctxq, 0, 6)) { my $xa = $blob->{$oid_a} //= solve_1($self, $oid_a, { path_b => $pa }); my $xb = $blob->{$oid_b} //= solve_1($self, $oid_b, { @@ -77,8 +79,8 @@ EOM path_a => $pa, path_b => $pb }); - $ta .= "M 100644 $xa ".git_quote($pa)."\n" if $xa; - $tb .= "M 100644 $xb ".git_quote($pb)."\n" if $xb; + $ta .= "M $ma $xa ".git_quote($pa)."\n" if $xa; + $tb .= "M $mb $xb ".git_quote($pb)."\n" if $xb; } my $rw = $self->{gits}->[-1]; # has all known alternates if (!$rw->{-tmp}) { @@ -148,6 +150,15 @@ sub extract_oids { # Eml each_part callback if (scalar(@top) >= 4 && $top[1] =~ $PublicInbox::ViewDiff::IS_OID && $top[0] =~ $PublicInbox::ViewDiff::IS_OID) { + my ($ma, $mb); + $x =~ /^old mode $MODE/sm and $ma = $1; + $x =~ /^new mode $MODE/sm and $mb = $1; + if (!defined($ma) && $x =~ + /^index [a-z0-9]+\.\.[a-z0-9]+ $MODE/sm) { + $ma = $mb = $1; + } + $ma //= '100644'; + $mb //= $ma; my ($oid_a, $oid_b, $pa, $pb) = splice(@top, 0, 4); $pa eq '/dev/null' or $pa = (split(m'/', git_unquote($pa), 2))[1]; @@ -155,7 +166,7 @@ sub extract_oids { # Eml each_part callback $pb = (split(m'/', git_unquote($pb), 2))[1]; $blobs->{$oid_a} //= undef; $blobs->{$oid_b} //= undef; - push @$ctxq, $oid_a, $oid_b, $pa, $pb; + push @$ctxq, $oid_a, $oid_b, $pa, $pb, $ma, $mb; } elsif ($ctxq) { my @out; for (split(/^/sm, $x)) { diff --git a/t/solve/bare.patch b/t/solve/bare.patch new file mode 100644 index 00000000..25d7f344 --- /dev/null +++ b/t/solve/bare.patch @@ -0,0 +1,8 @@ +diff --git a/script/public-inbox-extindex b/script/public-inbox-extindex +old mode 100644 +new mode 100755 +index 15ac20eb..771486c4 +--- a/script/public-inbox-extindex ++++ b/script/public-inbox-extindex +@@ -4 +3,0 @@ +-# Basic tool to create a Xapian search index for a public-inbox. diff --git a/t/solver_git.t b/t/solver_git.t index 44cbbfdb..ad0c295b 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -73,6 +73,19 @@ test_lei({tmpdir => "$tmpdir/rediff"}, sub { lei_ok(qw(rediff -q -U9 t/solve/0001-simple-mod.patch)); like($lei_out, qr!^\Q+++\E b/TODO\n@@ -103,9 \+103,11 @@!sm, 'got more context with -U9'); + lei_ok(qw(rediff -q -U9 t/solve/bare.patch)); + my $exp = <<'EOM'; +diff --git a/script/public-inbox-extindex b/script/public-inbox-extindex +old mode 100644 +new mode 100755 +index 15ac20eb..771486c4 +--- a/script/public-inbox-extindex ++++ b/script/public-inbox-extindex +@@ -1,13 +1,12 @@ + #!perl -w +EOM + ok(index($lei_out, $exp) >= 0, + 'preserve mode, regen header + context from -U0 patch'); }); test_lei({tmpdir => "$tmpdir/index-eml-only"}, sub {