File: vlpatch

package info (click to toggle)
libvcs-lite-perl 0.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: perl: 988; makefile: 2
file content (41 lines) | stat: -rwxr-xr-x 785 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Long;

my $output;

GetOptions(
	'output=s' => \$output,
	);

if (!@ARGV) {
	print <<END;

Usage:  vlpatch.pl [--output outfile] original patch
	vlpatch [--output outfile] original	# take patch from stdin

if --output is not specified, the patched file is put in place of
the original, and the original is renamed to *.orig

END
	exit;
}

my $orig = shift @ARGV;
my ($pat,$patsrc) = @ARGV ? ($ARGV[0],$ARGV[0]) : (\*STDIN,'-');
my $el1 = VCS::Lite->new($orig);
my $dt1 = VCS::Lite::Delta->new($patsrc,undef,$orig,$pat);

my $chg = $el1->patch($dt1) or die "Patch failed";

if (!$output) {
	rename $orig, "$orig.orig";
	$output = $orig;
}

open PAT,">$output" or die "Failed to write output, $!";
print PAT $chg->text;
close PAT;