Skip to content

Commit

Permalink
Item13759: PatchFoswikContrib 2.0 compatibiltiy
Browse files Browse the repository at this point in the history
It's a bit of ugliness, but Foswiki 2.0 moved some functions around, and
renamed them.  Monkey patch the available methods.

Unit tests pass.  Still needs real testing.

Also updated Text::Diff to the latest cpan.
  • Loading branch information
gac410 committed Oct 2, 2015
1 parent 49b661e commit 8093c4b
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 68 deletions.
5 changes: 3 additions & 2 deletions PatchFoswikiContrib/data/System/PatchFoswikiContrib.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1398214712" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1443815948" format="1.1" version="1"}%
<!--
One line description, required for extensions repository catalog.
* Set SHORTDESCRIPTION = File patch tool for Foswiki
Expand Down Expand Up @@ -66,11 +66,12 @@ To build a patch file,
---++ Info

| Author: | GeorgeClark |
| Copyright &copy;: | Foswiki Contributors |
| Copyright &copy;: | 2012-2015 Foswiki Contributors |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Dependencies: | %$DEPENDENCIES% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 2.1 (02 Oct 2015) | Foswikitask:Item13759: Restructure to support internal changes in Foswiki 2.0. Update to latest CPAN libs. |
| 2.0 (22 Apr 2014) | Foswikitask:Item12863: Restructure PatchFoswikiContrib to remove obsolete patches originally shipped with the extension. |
| 1.5 (26 Dec 2012) | Foswikitask:Item12312: Add reporting of patch status,%BR%\
Foswikitask:Item12314: Add feature to reverse a patch.%BR%\
Expand Down
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1398214712" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1443815948" format="1.1" version="1"}%
<!--
One line description, required for extensions repository catalog.
* Set SHORTDESCRIPTION = File patch tool for Foswiki
Expand Down Expand Up @@ -44,6 +44,7 @@ See PatchFoswikiContrib
| Dependencies: | %$DEPENDENCIES% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 2.1 (02 Oct 2015) | Foswikitask:Item13759: Restructure to support internal changes in Foswiki 2.0. Update to latest CPAN libs. |
| 2.0 (22 Apr 2014) | Foswikitask:Item12863: Restructure PatchFoswikiContrib to remove obsolete patches originally shipped with the extension. |
| 1.5 (26 Dec 2012) | Foswikitask:Item12312: Add reporting of patch status,%BR%\
Foswikitask:Item12314: Add feature to reverse a patch.%BR%\
Expand Down
81 changes: 53 additions & 28 deletions PatchFoswikiContrib/lib/CPAN/lib/Text/Diff.pm
@@ -1,16 +1,15 @@
package Text::Diff;

use 5.00503;
use 5.006;
use strict;
use Carp;
use warnings;
use Carp qw/ croak confess /;
use Exporter ();
use Algorithm::Diff ();
use vars qw{$VERSION @ISA @EXPORT};
BEGIN {
$VERSION = '1.41';
@ISA = 'Exporter';
@EXPORT = 'diff';
};

our $VERSION = '1.43';
our @ISA = qw/ Exporter /;
our @EXPORT = qw/ diff /;

## Hunks are made of ops. An op is the starting index for each
## sequence and the opcode:
Expand All @@ -32,14 +31,14 @@ sub diff {

for my $i ( 0 .. 1 ) {
my $seq = $seqs[$i];
my $type = ref $seq;
my $type = ref $seq;

while ( $type eq "CODE" ) {
$seqs[$i] = $seq = $seq->( $options );
$type = ref $seq;
}
$seqs[$i] = $seq = $seq->( $options );
$type = ref $seq;
}

my $AorB = !$i ? "A" : "B";
my $AorB = !$i ? "A" : "B";

if ( $type eq "ARRAY" ) {
## This is most efficient :)
Expand All @@ -54,13 +53,13 @@ sub diff {
elsif ( ! $type ) {
$options->{"OFFSET_$AorB"} = 1
unless defined $options->{"OFFSET_$AorB"};
$options->{"FILENAME_$AorB"} = $seq
unless defined $options->{"FILENAME_$AorB"};
$options->{"MTIME_$AorB"} = (stat($seq))[9]
unless defined $options->{"MTIME_$AorB"};
$options->{"FILENAME_$AorB"} = $seq
unless defined $options->{"FILENAME_$AorB"};
$options->{"MTIME_$AorB"} = (stat($seq))[9]
unless defined $options->{"MTIME_$AorB"};

local $/ = "\n";
open F, "<$seq" or carp "$!: $seq";
open F, "<$seq" or croak "$!: $seq";
$seqs[$i] = [<F>];
close F;

Expand Down Expand Up @@ -108,11 +107,10 @@ sub diff {
$style = "Text::Diff::$style" if exists $internal_styles{$style};

if ( ! $style->can( "hunk" ) ) {
eval "require $style; 1" or die $@;
eval "require $style; 1" or die $@;
}

$style = $style->new
if ! ref $style && $style->can( "new" );
$style = $style->new if ! ref $style && $style->can( "new" );

my $ctx_lines = $options->{CONTEXT};
$ctx_lines = 3 unless defined $ctx_lines;
Expand All @@ -130,7 +128,7 @@ sub diff {

my $emit_ops = sub {
$output_handler->( $style->file_header( @seqs, $options ) )
unless $hunks++;
unless $hunks++;
$output_handler->( $style->hunk_header( @seqs, @_, $options ) );
$output_handler->( $style->hunk ( @seqs, @_, $options ) );
$output_handler->( $style->hunk_footer( @seqs, @_, $options ) );
Expand All @@ -152,8 +150,8 @@ sub diff {
push @ops, [@_[0,1]," "];

if ( $diffs && ++$ctx > $ctx_lines * 2 ) {
$emit_ops->( [ splice @ops, 0, $#ops - $ctx_lines ] );
$ctx = $diffs = 0;
$emit_ops->( [ splice @ops, 0, $#ops - $ctx_lines ] );
$ctx = $diffs = 0;
}

## throw away context lines that aren't needed any more
Expand Down Expand Up @@ -246,7 +244,7 @@ SCOPE: {

sub new {
my $proto = shift;
return bless { @_ }, ref $proto || $proto;
return bless { @_ }, ref $proto || $proto;
}

sub file_header { return "" }
Expand Down Expand Up @@ -432,6 +430,10 @@ following:
require Text::Diff;
That's a pretty rare occurence, so C<diff()> is exported by default.
If you pass a filename, but the file can't be read,
then C<diff()> will C<croak>.
=head1 OPTIONS
diff() takes two parameters from which to draw input and a set of
Expand Down Expand Up @@ -472,8 +474,9 @@ If the package indicated by the STYLE has no hunk() method, c<diff()> will
load it automatically (lazy loading). Since all such packages should inherit
from Text::Diff::Base, this should be marvy.
Styles may be specified as class names (C<STYLE => "Foo"), in which case they
will be C<new()>ed with no parameters, or as objects (C<STYLE => Foo->new>).
Styles may be specified as class names (C<STYLE =E<gt> 'Foo'>),
in which case they will be C<new()>ed with no parameters,
or as objects (C<STYLE =E<gt> Foo-E<gt>new>).
=item CONTEXT
Expand Down Expand Up @@ -624,7 +627,7 @@ differing elements by selectively escaping whitespace:
* 9|embedded ws |embedded\tws *
+--+--------------------------+--------------------------+
See L</Text::Diff::Table> for more details, including how the whitespace
See L<Text::Diff::Table> for more details, including how the whitespace
escaping works.
=head2 Text::Diff::Context
Expand Down Expand Up @@ -693,6 +696,28 @@ welcome.
Uses closures internally, this may lead to leaks on C<perl> versions 5.6.1 and
prior if used many times over a process' life time.
=head1 SEE ALSO
L<Algorithm::Diff> - the underlying implementation of the diff algorithm
used by C<Text::Diff>.
L<YAML::Diff> - find difference between two YAML documents.
L<HTML::Differences> - find difference between two HTML documents.
This uses a more sane approach than L<HTML::Diff>.
L<XML::Diff> - find difference between two XML documents.
L<Array::Diff> - find the differences between two Perl arrays.
L<Hash::Diff> - find the differences between two Perl hashes.
L<Data::Diff> - find difference between two arbitrary data structures.
=head1 REPOSITORY
L<https://github.com/neilbowers/Text-Diff>
=head1 AUTHOR
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
Expand Down
7 changes: 3 additions & 4 deletions PatchFoswikiContrib/lib/CPAN/lib/Text/Diff/Config.pm
@@ -1,12 +1,11 @@
package Text::Diff::Config;

use 5.006;
use strict;
use warnings;

use vars '$VERSION';
$VERSION = '1.41';

use vars qw($Output_Unicode);
our $VERSION = '1.43';
our $Output_Unicode;

BEGIN
{
Expand Down
29 changes: 19 additions & 10 deletions PatchFoswikiContrib/lib/CPAN/lib/Text/Diff/Table.pm
@@ -1,16 +1,14 @@
package Text::Diff::Table;

use 5.00503;
use 5.006;
use strict;
use warnings;
use Carp;
use vars qw{$VERSION @ISA @EXPORT_OK};
use Text::Diff::Config;

BEGIN {
$VERSION = '1.41';
@ISA = qw( Text::Diff::Base Exporter );
@EXPORT_OK = qw( expand_tabs );
}
our $VERSION = '1.43';
our @ISA = qw( Text::Diff::Base Exporter );
our @EXPORT_OK = qw( expand_tabs );

my %escapes = map {
my $c =
Expand Down Expand Up @@ -293,12 +291,23 @@ sub file_footer {
"*" => "* %$w[0]s|%-$w[1]s |%-$w[2]s *\n",
);

$fmts{bar} = sprintf $fmts{"="}, "", "", "", "";
my @args = ('', '', '');
push(@args, '') if $four_column_mode;
$fmts{bar} = sprintf $fmts{"="}, @args;
$fmts{bar} =~ s/\S/+/g;
$fmts{bar} =~ s/ /-/g;

# Sometimes the sprintf has too many arguments,
# which results in a warning on Perl 5.021+
# I really wanted to write:
# no warnings 'redundant';
# but that causes a compilation error on older versions of perl
# where the warnings pragma doesn't know about 'redundant'
no warnings;

return join( "",
map {
sprintf( $fmts{$_->[-1]}, @$_ )
sprintf( $fmts{$_->[-1]}, @$_ );
} (
["bar"],
@heading_lines,
Expand All @@ -324,7 +333,7 @@ __END__
use Text::Diff;
diff \@a, $b { STYLE => "Table" };
diff \@a, $b, { STYLE => "Table" };
=head1 DESCRIPTION
Expand Down
53 changes: 41 additions & 12 deletions PatchFoswikiContrib/lib/Foswiki/Configure/PatchFile.pm
Expand Up @@ -4,12 +4,11 @@ package Foswiki::Configure::PatchFile;

use strict;
use warnings;
use File::Copy ();
use File::Path ();
use File::Spec ();
use Foswiki::Time ();
use Text::Patch ();
use Foswiki::Configure::Util ();
use File::Copy ();
use File::Path ();
use File::Spec ();
use Foswiki::Time ();
use Text::Patch ();
use File::stat;

=begin TML
Expand Down Expand Up @@ -225,7 +224,7 @@ sub checkPatch {
next if ( $key eq 'identifier' );
foreach my $md5 ( keys %{ $patchRef->{$key} } ) {

my $file = Foswiki::Configure::Util::mapTarget( $root, $key );
my $file = mapTarget( $root, $key );
$msgs .= "| $key | | | Target Missing |\n" unless ( -f $file );

my $origMD5 = _getMD5($file);
Expand Down Expand Up @@ -283,7 +282,7 @@ sub applyPatch {
next if ( $key eq 'identifier' );
foreach my $md5 ( keys %{ $patchRef->{$key} } ) {

my $file = Foswiki::Configure::Util::mapTarget( $root, $key );
my $file = mapTarget( $root, $key );

my $fileMD5 = _getMD5($file);
my $wantMD5 = ($reverse) ? $patchRef->{$key}{$md5}{patched} : $md5;
Expand Down Expand Up @@ -381,7 +380,7 @@ sub backupTargets {
next if ( $key eq 'summary' );
next if ( $key eq 'identifier' );
next if ( $key eq 'error' );
my $file = Foswiki::Configure::Util::mapTarget( $root, $key );
my $file = mapTarget( $root, $key );
next unless ( -f $file );
foreach my $md5 ( keys %{ $patchRef->{$key} } ) {
$bkupFiles{$key} = $file
Expand Down Expand Up @@ -415,8 +414,7 @@ sub backupTargets {
$backup++;
}
my ( $rslt, $err );
( $rslt, $err ) =
Foswiki::Configure::Util::createArchive( $bkupDir, $bkupPath, '1' );
( $rslt, $err ) = createArchive( $bkupDir, $bkupPath, '1' );
$rslt = "FAILED \n" . $err unless ($rslt);
$msgs .= "Backup Archived as $rslt \n";
}
Expand All @@ -428,11 +426,42 @@ sub backupTargets {
return $msgs . "\n\n";

}

sub createArchive {

no warnings 'redefine';
eval { require Foswiki::Configure::Util };
unless ($@) {
*createArchive = \&Foswiki::Configure::Util::createArchive;
goto &Foswiki::Configure::Util::createArchive;
}
else {
*createArchive = \&Foswiki::Configure::FileUtil::createArchive;
goto &Foswiki::Configure::FileUtil::createArchive;
}
use warnings 'redefine';
}

sub mapTarget {

no warnings 'redefine';
eval { require Foswiki::Configure::Util };
unless ($@) {
*mapTarget = \&Foswiki::Configure::Util::mapTarget;
goto &Foswiki::Configure::Util::mapTarget;
}
else {
*mapTarget = \&Foswiki::Configure::Package::_mapTarget;
goto &Foswiki::Configure::Package::_mapTarget;
}
use warnings 'redefine';
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2015 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
Expand Up @@ -14,8 +14,9 @@ package Foswiki::Contrib::PatchFoswikiContrib;
use strict;
use warnings;

our $VERSION = '2.0';
our $RELEASE = '2.0';
# Keep in sync with lib/Foswiki/Plugins/PatchFoswikiContribPlugin.pm
our $VERSION = '2.1';
our $RELEASE = '02 Oct 2015';

our $SHORTDESCRIPTION = 'Apply critical patches to Foswiki.';

Expand Down

0 comments on commit 8093c4b

Please sign in to comment.