Alt-App-makepatch
view release on metacpan or search on metacpan
Applypatch
* The generated patch kit is the concatenation of
- a shell preamble;
- the actual 'patch' input;
- a data section for 'applypatch'.
* When applied through 'applypatch', the patch kit will be
extensively verified for integrity. Heuristics are applied to the
current directory to verify that it is indeed the expected source
directory. This directory is prepared for the patching, i.e. new
files and directories are created if required. Next, the patch data
is passed to the 'patch' program for the actual patching. Finally
file modes and timestamps are adjusted.
Example:
applypatch -d src-1.0 the-patch
* When the patch kit is run as a shell script, it will prepare the
current directory by creating / removing files and directories as
Traditionally, source trees are updated with the 'patch' program,
processing patch information that is generated by the 'diff' program.
Although 'diff' and 'patch' do a very good job at patching file
contents, most versions do not handle creating and deleting files and
directories, and adjusting of file modes and time stamps. Newer
versions of 'diff' and 'patch' seem to be able to create files, and
very new versions of 'patch' can remove files. But that's about it.
Another typical problem is that patch kits are typically downloaded
from the Internet, or transmitted via electronic mail. It is often
desirable to verify the correctness of a patch kit before even
attempting to apply it.
The makepatch package is designed to overcome these limitations.
DESCRIPTION
The makepatch package contains two programs, both written in Perl:
'makepatch' and 'applypatch'.
'makepatch' will generate a patch kit from two source trees.
Moreover, 'makepatch' prepends a small shell script in front of the
patch kit that creates the necessary files and directories for the
patch process. By running the patch kit as a shell script your source
directory is prepared for the patching process.
But that is not it! 'makepatch' also inserts some additional
information in the patch kit for use by the 'applypatch' program.
The 'applypatch' program will do the following:
- It will extensively verify that the patch kit is complete and not
corrupted during transfer.
- It will apply some heuristics to verify that the directory in
which the patch will be applied does indeed contain the expected
sources.
- It creates files and directories as necessary.
- It applies the patch by running the 'patch' program.
- Upon completion, obsolete files, directories and .orig files are
removed, file modes of new files are set, and the timestamps of
all patched files are adjusted.
Note that 'applypatch' only requires the 'patch' program. It does not
rely on a shell or shell tools. This makes it possible to apply
makepatch.spec view on Meta::CPAN
Moreover, 'makepatch' prepends a small shell script in front of the
patch kit that creates the necessary files and directories for the
patch process. By running the patch kit as a shell script your source
directory is prepared for the patching process.
But that is not it! 'makepatch' also inserts some additional
information in the patch kit for use by the 'applypatch' program.
The 'applypatch' program will do the following:
- It will extensively verify that the patch kit is complete and not
corrupted during transfer.
- It will apply some heuristics to verify that the directory in
which the patch will be applied does indeed contain the expected
sources.
- It creates files and directories as necessary.
- It applies the patch by running the 'patch' program.
- Upon completion, obsolete files, directories and .orig files are
removed, file modes of new files are set, and the timestamps of
all patched files are adjusted.
Note that 'applypatch' only requires the 'patch' program. It does not
rely on a shell or shell tools. This makes it possible to apply
script/applypatch view on Meta::CPAN
my @workq = (); # work queue
## Subroutine prototypes
sub app_options ();
sub app_usage ($);
sub copy_input ();
sub execute_patch ();
sub post_patch ();
sub pre_patch ();
sub verify_files ();
################ Program parameters ################
app_options();
$trace ||= $debug;
$verbose ||= $trace;
################ Presets ################
$patch .= " -s" unless $verbose;
script/applypatch view on Meta::CPAN
################ The Process ################
# Validate input and copy to temp file.
copy_input ();
# Change dir if requested.
(defined $dir) && (chdir ($dir) || die ("Cannot change to $dir: $!\n"));
# Verify that we are in the right place.
verify_files ();
# Exit if just checking.
die ("Okay\n") if $test && $check;
exit (0) if $check;
# Pre patch: create directories and files.
pre_patch ();
# Run the patch program.
execute_patch ();
script/applypatch view on Meta::CPAN
}
}
print STDERR ($applypatch == 3 ? "Apply" : "",
"Patch kit apparently okay.\n") if $verbose;
# Reset file to start of patch data.
$tmpfile->setpos ($pos);
}
sub verify_files () {
my $fail = 0;
print STDERR ("Verify source directory.\n") if $verbose;
foreach ( @workq ) {
my ($op, $fn, @args) = @$_;
if ( $op eq 'c' ) {
if ( -f $fn || -d _ ) {
script/applypatch view on Meta::CPAN
=head1 DESCRIPTION
B<Applypatch> applies a patch kit as generated by the B<makepatch>
program. It performs the following actions:
=over 4
=item *
First, it will extensively verify that the patch kit is complete and
did not get corrupted during transfer.
=item *
Then it will apply some heuristics to verify that the directory in
which the patch will be applied does indeed contain the expected
sources.
If a corruption or verification error is detected, B<applypatch> exits
without making changes.
=item *
If the kit is okay, and the directory seems to be the right one: it
creates new files and directories as necessary.
script/makepatch view on Meta::CPAN
Traditionally, source trees are updated with the B<patch> program,
processing patch information that is generated by the B<diff> program.
Although B<diff> and B<patch> do a very good job at patching file
contents, most versions do not handle creating and deleting files and
directories, and adjusting of file modes and time stamps. Newer
versions of B<diff> and B<patch> seem to be able to create files, and
very new versions of B<patch> can remove files. But that's about it.
Another typical problem is that patch kits are typically downloaded
from the Internet, or transmitted via electronic mail. It is often
desirable to verify the correctness of a patch kit before even
attempting to apply it.
The B<makepatch> package is designed to overcome these limitations.
=head1 DESCRIPTION
The B<makepatch> package contains two Perl programs:
B<makepatch> and B<applypatch>.
B<makepatch> will generate a patch kit from two source trees. It
script/makepatch view on Meta::CPAN
patch process. If you can not run B<applypatch> for some reason, you
can run the patch kit I<as a shell script> to prepare the source
directory for the patching process.
The B<applypatch> program will do the following:
=over 4
=item *
It will extensively verify that the patch kit is complete and not
corrupted during transfer.
=item *
It will apply some heuristics to verify that the directory in
which the patch will be applied does indeed contain the expected
sources.
=item *
It creates files and directories as necessary.
=item *
It applies the patch by running the B<patch> program.
script/makepatch view on Meta::CPAN
versions:
makepatch pkg-1.6.tar.gz pkg-1.7 > pkg-1.6-1.7.patch
To apply this script, go to the directory containing the 1.6 sources
and feed the script to B<applypatch>:
cd old/pkg-1.6
applypatch pkg-1.6-1.7.patch
B<applypatch> will verify that it is executing in the right place and
make all necessary updates.
By default, B<makepatch> will provide a few lines of progress
information, for example:
Extracting pkg-1.6.tar.gz to /tmp/mp21575.d/old...
Manifest MANIFEST for pkg-1.6 contains 1083 files.
Manifest MANIFEST for pkg-1.7 contains 1292 files.
Processing the filelists ...
Collecting patches ...
script/makepatch view on Meta::CPAN
versions:
makepatch pkg-1.6 pkg-1.7 > pkg-1.6-1.7.patch
To apply this script, go to the pkg-1.6 directory and feed the
script to B<applypatch>:
cd old/pkg-1.6
applypatch pkg-1.6-1.7.patch
B<applypatch> will verify that it is executing in the right place and
make all necessary updates.
This is one way to generate and use manifest files:
(cd pkg-1.6; find . -type f -print > OLDMANIFEST)
(cd pkg-1.7; find . -type f -print > NEWMANIFEST)
makepatch \
-oldmanifest pkg-1.6/OLDMANIFEST \
( run in 0.509 second using v1.01-cache-2.11-cpan-5467b0d2c73 )