package VCP::Patch ; =head1 NAME VCP::Patch - Apply the (almost) unified diffs used in RevML =head1 SYNOPSIS use VCP::Patch ; vcp_patch( \$patch, $source_file_name, $result_file_name ) ; =head1 DESCRIPTION Applies a patch (in $patch) to $source_file in order to build $result_file. The patches are in a "unified diff" format, but without the filename headers (these are passed as other data fields in VCP and the actual filenames are just working files and are not important). Some example patches: =item * For a one line file: @@ -1 +1 @@ -a/deeply/buried/file, revision 1, char 0x01="<char code="0x01" />" +a/deeply/buried/file, revision 2, char 0x09=" " =item * For a several line file with multiple changes: Here are the source and result files side-by-side: Source Result ====== ====== 1 1 2 2 3 3 4 4 5d 5a 6 6 7 7 8 8 9 9 10 9a 11 10 11d 11 12 12 13 13 The "patch" to transform the source in to the result can be expressed in several ways, depending on the amount of context. VCP requires no context since the result is checked with an MD5 checksum. Context is, however, sometimes used to make the RevML a bit more human readable, though this can vary. =over =item 0 context (C<diff -U 0>): @@ -5 +5 @@ -5d +5a @@ -9,0 +10 @@ +9a @@ -12 +12,0 @@ -11d =item 1 line of context (C<diff -U 1>): --- A Sat Aug 25 00:05:26 2001 +++ B Sat Aug 25 00:05:26 2001 @@ -4,3 +4,3 @@ 4 -5d +5a 6 @@ -9,5 +9,5 @@ 9 +9a 10 11 -11d 12 =item 3 lines of context (C<diff -U 3 ...> or C<diff -u ...>) --- A Sat Aug 25 00:05:26 2001 +++ B Sat Aug 25 00:05:26 2001 @@ -2,13 +2,13 @@ 2 3 4 -5d +5a 6 7 8 9 +9a 10 11 -11d 12 13 =back =back =head1 Functions =over =cut @ISA = qw( Exporter ) ; @EXPORT = qw( vcp_patch ) ; use strict ; use Carp ; use VCP::Debug ':debug' ; use Exporter ; =item vcp_patch Takes a patch, a source file name, and a result file name and performs the patch. Called from VCP::Source::revml to reconstitute revisions given by delta records. The patch is passed by reference in order to not copy it, it is not altered. Will die on error, always returns true. =cut sub vcp_patch { my ( $patch_ref, $source_fn, $result_fn ) = @_ ; debug "patching $source_fn -> $result_fn" if debugging ; open SOURCE, "<$source_fn" or croak "$!: $source_fn" ; open RESULT, ">$result_fn" or croak "$!: $result_fn" ; ## FUDGE print RESULT <SOURCE> ; close SOURCE or croak "$!: $source_fn" ; close RESULT or croak "$!: $result_fn" ; return 1 ; } =head1 COPYRIGHT Copyright 2000, Perforce Software, Inc. All Rights Reserved. This module and the VCP package are licensed according to the terms given in the file LICENSE accompanying this distribution, a copy of which is included in L<vcp>. =head1 AUTHOR Sean McCune <sean@sean-mccune.com> =cut 1 ;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#9 | 3133 | Barrie Slaymaker |
Make destinations call back to sources to check out files to simplify the architecture (is_metadata_only() no longer needed) and make it more optimizable (checkouts can be batched). |
||
#8 | 2753 | John Fetkovich | POD fixes | ||
#7 | 2320 | Barrie Slaymaker | tweak debug output | ||
#6 | 2015 | Barrie Slaymaker | submit changes | ||
#5 | 1809 | Barrie Slaymaker | VCP::Patch should ignore lineends | ||
#4 | 1755 | Barrie Slaymaker | Silence annoying leftover patch debug messages. | ||
#3 | 1358 | Barrie Slaymaker | Win32 changes | ||
#2 | 1175 | Barrie Slaymaker | Implement VCP::Patch, roll 0.26 release. | ||
#1 | 1066 | Barrie Slaymaker | Added framework for patch code. |