Skip to content

Commit b64519b

Browse files
authored
patch: reduce Patch::Ed::apply()
* Split personality: I spawn an external ed command, but also I process ed diffs myself * On systems where ed is available, users have the option to apply an ed-diff using ed instead of patch * In my view the point of patch is to directly process edits from diff files, not act as a wrapper around an external editor * ed-diffs are also not very common so it's even less important to maintain this external-ed code within patch * This change will help to expose issues with processing ed-diffs, which would be masked by the code not being exercised
1 parent 676ccde commit b64519b

File tree

1 file changed

+0
-33
lines changed

1 file changed

+0
-33
lines changed

bin/patch

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -943,39 +943,6 @@ sub apply {
943943

944944
my $out = $self->{o_fh};
945945

946-
$self->{check} and goto PLAN_J;
947-
948-
# We start out by adding a magic line to our output. If this line
949-
# is still there after piping to ed, then ed failed. We do this
950-
# because win32 will silently fail if there is no ed program.
951-
my $magic = "#!/i/want/a/moogle/stuffy\n";
952-
print $out $magic;
953-
954-
# Pipe to ed.
955-
eval {
956-
open ED, '|-', 'ed', '-s', $self->{'i_file'} or die "Couldn't fork ed: $!";
957-
print ED map @$_, @cmd or die "Couldn't print ed: $!";
958-
print ED "wq $self->{o_file}\n" or die "Couldn't print ed: $!";
959-
close ED or die "Couldn't close ed: $?";
960-
};
961-
962-
# Did pipe to ed work?
963-
seek($out, 0, 0) or $self->throw("Couldn't seek OUT: $!");
964-
my $testline = <$out>;
965-
if (!$@ && $testline ne $magic) {
966-
$self->note("Hunk #$self->{hunk} succeeded at 1.\n");
967-
return 1;
968-
}
969-
970-
# Erase any trace of magic line.
971-
truncate($out, 0) or $self->throw("Couldn't truncate OUT: $!");
972-
seek($out, 0, 0) or $self->throw("Couldn't seek OUT: $!");
973-
974-
# Try to apply ed script by hand.
975-
$self->note("Pipe to ed failed. Switching to Plan J...\n");
976-
977-
PLAN_J:
978-
979946
# Pre-process each ed command. Ed diffs are reversed (so that each
980947
# command doesn't end up changing the line numbers of subsequent
981948
# commands). But we need to apply diffs in a forward direction because

0 commit comments

Comments
 (0)