From 4f5001b4d315404697d2324a400ebfd124626d49 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 14 Sep 2024 12:25:00 +0200 Subject: diff-parse.pl: don't force error message into register A following patch wants to use this script without wrapping it in an "evaluate-commands -save-regs e %{ ... }", so simply print the raw error message and set the register to the caller. This interface is a bit weird because the error is printed quoted but for now that just makes things a bit more convenient. --- rc/filetype/diff-parse.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rc/filetype/diff-parse.pl') diff --git a/rc/filetype/diff-parse.pl b/rc/filetype/diff-parse.pl index 203e9b19..7453b2b3 100755 --- a/rc/filetype/diff-parse.pl +++ b/rc/filetype/diff-parse.pl @@ -9,8 +9,8 @@ sub quote { } sub fail { my $reason = shift; - print "set-register e fail " . quote("diff-parse.pl: $reason"); - exit; + print quote("diff-parse.pl: $reason"); + exit 1; } my $begin; -- cgit v1.2.3 From 54992c08aecb2fc91aecacccc15d3a17ae7390dc Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 14 Sep 2024 12:25:02 +0200 Subject: rc git: teach "git apply" to work on content, not just diffs Staging/unstaging/reverting (parts of) the current buffer's file can be a common use case. Today "git apply" can do that based on a selection within a diff. When the selection is on uncommitted content, we can probably assume that the intent is to use the part of the selection that overlaps with the +-side of "git diff" (or "git diff --cached" for "git apply --cached"). Make "git apply" treat selections as content if the buffile is tracked by Git. This differentiator is not perfect but I don't know why anyone would want to use the existing "git apply" semantics on a tracked file. Maybe we should pick a different name. This feature couples well with "git show-diff", which shows all lines with unstaged changes (in future it should probably show staged changes as well). Whereas on diffs, "git apply" stages the entire hunk if the selection contains no newline, this does not happen when operating on content. I didn't yet try implementing that. I guess the hunks are not as explicit here. Closes #5225 --- rc/filetype/diff-parse.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'rc/filetype/diff-parse.pl') diff --git a/rc/filetype/diff-parse.pl b/rc/filetype/diff-parse.pl index 7453b2b3..5da4e349 100755 --- a/rc/filetype/diff-parse.pl +++ b/rc/filetype/diff-parse.pl @@ -45,13 +45,15 @@ our $version = "+"; eval $begin if defined $begin; -$in_file = "$directory/$in_file" if defined $in_file; +$in_file = "$directory/$in_file" if defined $in_file && $in_file ne ""; # Outputs our $diff_line = 0; our $commit; our $file; our $file_line; +our $other_file; +our $other_file_line; our $diff_line_text; my $other_version; @@ -63,8 +65,6 @@ if ($version eq "+") { my $is_recursive_diff = 0; my $state = "header"; my $fallback_file; -my $other_file; -my $other_file_line; sub strip { my $is_recursive_diff = shift; @@ -127,7 +127,7 @@ while () { $other_file_line++ if defined $other_file_line; } } - if (defined $in_file and defined $file and $file eq $in_file) { + if (defined $in_file and defined $file and ($in_file eq "" or $file eq $in_file)) { if (defined $in_file_line and defined $file_line and $file_line >= $in_file_line) { last; } -- cgit v1.2.3