Debian Codegraph @

scripts/vlpatch

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Getopt::Long;
7
8 my $output;
9
10 GetOptions(
11 'output=s' => \$output,
12 );
13
14 if (!@ARGV) {
15 print <<END;
16
17 Usage: vlpatch.pl [--output outfile] original patch
18 vlpatch [--output outfile] original # take patch from stdin
19
20 if --output is not specified, the patched file is put in place of
21 the original, and the original is renamed to *.orig
22
23 END
24 exit;
25 }
26
27 my $orig = shift @ARGV;
28 my ($pat,$patsrc) = @ARGV ? ($ARGV[0],$ARGV[0]) : (\*STDIN,'-');
29 my $el1 = VCS::Lite->new($orig);
30 my $dt1 = VCS::Lite::Delta->new($patsrc,undef,$orig,$pat);
31
32 my $chg = $el1->patch($dt1) or die "Patch failed";
33
34 if (!$output) {
35 rename $orig, "$orig.orig";
36 $output = $orig;
37 }
38
39 open PAT,">$output" or die "Failed to write output, $!";
40 print PAT $chg->text;
41 close PAT;