From cf0c7ce3ce81b5c33cb149a7edc3efd99631a57d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 5 May 2021 10:46:37 +0000 Subject: lei rediff: regenerate diffs from stdin Sometimes a mailed patch is generated with non-ideal output, (lacking context, noisy whitespace changes, etc.), or a user wants to use the same external diff viewer they've configured git to use. Since we have SolverGit to regenerate arbitrary blobs from patches; this new command allows us to regenerate a diff with different options using the blobs SolverGit gives us. The amount of git-diff(1) options is mind numbing, so it's likely I missed some favorites or botched the getopt spec translation. This also fixes Inbox::base_url to check psgi.url_scheme before attempting to generate URLs and avoid uninitialized variable warnings. Oddly, the "lei blob" tests did not trigger these uninitialized warnings. Note: this will automatically import+index the message(s) it's regenerating, because solver relies on being able to lookup pre/postimage OIDs and read blobs. --- t/solver_git.t | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/solver_git.t b/t/solver_git.t index 75387b2a..e566efb3 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -32,7 +32,7 @@ my $v1_0_0_tag_short = substr($v1_0_0_tag, 0, 16); my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0'; my $non_existent = 'ee5e32211bf62ab6531bdf39b84b6920d0b6775a'; -test_lei({tmpdir => $tmpdir}, sub { +test_lei({tmpdir => "$tmpdir/blob"}, sub { lei_ok('blob', '--mail', $patch2_oid, '-I', $ibx->{inboxdir}, \'--mail works for existing oid'); is($lei_out, $patch2->as_string, 'blob matches'); @@ -64,6 +64,12 @@ test_lei({tmpdir => $tmpdir}, sub { lei_ok('blob', $v1_0_0_tag_short, '-I', $ibx->{inboxdir}); }); +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'); +}); + my $git = PublicInbox::Git->new($git_dir); $ibx->{-repo_objs} = [ $git ]; my $res; -- cgit v1.2.3-24-ge0c7