Alt-App-makepatch
view release on metacpan or search on metacpan
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
patches on non-Unix systems.
REQUIREMENTS
- Perl 5.004 standard installation.
- For 'makepatch': the 'diff' program.
- For 'applypatch': the 'patch' program.
--------------------------------------------------------------------------
Johan Vromans jvromans@squirrel.nl
Squirrel Consultancy Haarlem, the Netherlands
makepatch.spec view on Meta::CPAN
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
patches on non-Unix systems.
%prep
%setup
#%patch -p0 -b .opt
%build
perl Makefile.PL
make all
make test
script/makepatch view on Meta::CPAN
my $exclude_pat; # regex to exclude
my @workq = (); # pre/post work
# Try to find a temp location.
my $TMPDIR = (File::Spec->can('tmpdir') && File::Spec->tmpdir)
|| $ENV{TMPDIR}
|| $ENV{TEMP}
|| '/usr/tmp';
my $dot_u = File::Spec::Unix->curdir; # UNIX current dir
my $dot = File::Spec->curdir; # current dir
my $dotdot = File::Spec->updir; # parent dir
# Try to find something home-ish.
my $HOME = $ENV{HOME}
|| ( ($^O eq 'MSWin32')
&& ( $ENV{APPDATA}
|| $ENV{USERPROFILE}
|| $ENV{HOMEDRIVE} && $ENV{HOMEPATH}
&& $ENV{HOMEDRIVE}.$ENV{HOMEPATH}
script/makepatch view on Meta::CPAN
$arg->{root} = $tmp;
$arg->{base} = $arg->{name};
}
sub catfile ($$) {
File::Spec->canonpath(File::Spec->catfile(@_));
}
sub dot_file_u ($) {
$_[0] =~ s,\\,/,g if $^O =~ /^MSWin/i;
File::Spec::Unix->catfile($dot_u, File::Spec::Unix->canonpath(@_));
}
sub dodiff ($$$$) {
my ($newdir, $new, $olddir, $old) = @_;
my $fh = new IO::File;
my $oldfn = catfile ($olddir, $old);
my $newfn = catfile ($newdir, $new);
# Check for binary files.
if ( -s $oldfn && -B _ ) {
script/makepatch view on Meta::CPAN
my %dir_ok = ();
foreach ( @workq ) {
my ($op, $fn) = @$_;
push (@newcomers, $fn) if $op eq 'c';
push (@goners, $fn) if $op eq 'r';
$patched++ if $op eq 'p';
}
$created = @newcomers;
$removed = @goners;
foreach ( sort @goners ) {
# WARNING: This code assumes you are running some Unix.
my @p = split (/\//, $_);
pop (@p);
foreach my $i ( (1-@p)..0 ) {
my $dir = join('/',@p[0..-$i]);
unless ( defined $dir_gone{$dir} ) {
unless ( -d catfile($new->{root},$dir) ) {
$dremoved++;
$dir_gone{$dir} = 1;
}
}
}
}
foreach ( reverse sort keys %dir_gone ) {
push (@workq, [ 'R', $_ ]);
}
foreach ( sort @newcomers ) {
# Explicitly create the new files since not all patch versions
# can handle creating new files.
# Create intermediate directories first.
# WARNING: This code assumes you are running some Unix.
my @p = split (/\//, $_);
pop (@p);
foreach my $i ( 0..(@p-1) ) {
my $dir = join('/',@p[0..$i]);
unless ( defined $dir_ok{$dir} ) {
unless ( -d catfile($old->{root},$dir) ) {
push (@workq, [ 'C', $dir, 0,
(stat(catfile($new->{root},$dir)))[9],
(stat(_))[2] ]);
$dcreated++;
script/makepatch view on Meta::CPAN
warn ("Error in MAKEPATCHINIT\n");
app_usage (1);
}
else {
trace ("+ INIT: $init\n");
}
}
unless ( $opt_test ) {
# Process ini file options.
# First, try system wide file. Unix specific.
app_parse_rc ("/etc/makepatchrc", 1, \@o);
my $rcname = ".".$my_name."rc";
# Then, try HOME .rc.
app_parse_rc (catfile ($HOME, $rcname), 1, \@o);
# Then try --rcfile, defaulting to .rc in current dir.
if ( defined $opt_rcfile ) {
app_parse_rc ($opt_rcfile, 0, \@o);
}
else {
app_parse_rc (catfile ($dot, $rcname), 1, \@o);
script/makepatch view on Meta::CPAN
=item *
Upon completion, obsolete files, directories and C<.orig> files are
removed, file modes of new files are set, and the timestamps of
all patched files are adjusted.
=back
Note that B<applypatch> only requires the B<patch> program. It does not
rely on a shell or shell tools. This makes it possible to apply
patches on non-Unix systems.
=head1 General usage
Suppose you have an archive `C<pkg-1.6.tar.gz>' containing the sources
for package `C<pkg>' version 1.6, and a directory tree `C<pkg-1.7>'
containing the sources for version 1.7. The following command will
generate a patch kit that updates the 1.6 sources into their 1.7
versions:
makepatch pkg-1.6.tar.gz pkg-1.7 > pkg-1.6-1.7.patch
script/makepatch view on Meta::CPAN
When this environment variable is set its contents are considered to
be command line options that are processed upon startup. All normal
options are allowed, plus one: B<-rcfile >I<filename>. Option
B<-rcfile> can be used to specify an alternate option file, see below.
=item *
Options files.
B<makepatch> first tries to process a file named B</etc/makepatchrc>.
(This is a Unix-ism.)
It is okay if this file is missing.
Next, B<makepatch> will process a file named B<.makepatchrc> in
the user's home directory, if it exists.
After processing this file, B<makepatch> will process a file named
B<.makepatchrc> in the current directory, if it exists. An alternative
name for this file can be specified with option B<-rcfile> in
environment variable B<MAKEPATCHINIT>. This is the only way to specify
an alternative options file name.
script/makepatch view on Meta::CPAN
string:
makepatch -filelist -prefix pkg-1.7/ pkg-1.7/MANIFEST | \
tar -cvf - -T -Op | gzip > pkg-1.7.tar.gz
=end comment
=head1 Bugs and restrictions
Much of the job of B<makepatch> is processing file names. B<makepatch>
has been tested extensively on Unix systems, but it is not guaranteed
to work on other systems.
B<applypatch> is repeatedly reported to correctly process B<makepatch>
generated patch kits on modern 32-bit Windows systems as well.
B<makepatch> does not know about symbolic links.
These will be treated like plain files.
Wrong results can be generated if the file lists that are used or
generated use different path separators.
( run in 1.296 second using v1.01-cache-2.11-cpan-39bf76dae61 )