unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20210505174944.69155-3-e@80x24.org> (raw)
In-Reply-To: <20210505174944.69155-1-e@80x24.org>

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 {

  parent reply	other threads:[~2021-05-05 17:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 17:49 [PATCH 0/3] lei rediff fixes Eric Wong
2021-05-05 17:49 ` [PATCH 1/3] script/public-inbox-extindex: chmod +x Eric Wong
2021-05-05 17:49 ` Eric Wong [this message]
2021-05-05 17:49 ` [PATCH 3/3] lei rediff: do not automatically store patches/mails Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210505174944.69155-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).