aboutsummaryrefslogtreecommitdiffstats
path: root/Perl/Local
diff options
context:
space:
mode:
authorBas Zoetekouw <bas>2008-09-22 22:11:31 +0000
committerBas Zoetekouw <bas>2008-09-22 22:11:31 +0000
commit3e32593003f7fec727cafc29d4d6a931cadfd880 (patch)
tree9a9c1b9f9dffb5c211d8262052ec0a7bc14fab5d /Perl/Local
parentba205fa03b4bb362805a70ce35744aff711c6c23 (diff)
Add a vcs_get_diff() funtion to VCS_CVS.pm
CVS version numbers Perl/Local/VCS_CVS.pm: 1.5 -> 1.6
Diffstat (limited to 'Perl/Local')
-rw-r--r--Perl/Local/VCS_CVS.pm72
1 files changed, 70 insertions, 2 deletions
diff --git a/Perl/Local/VCS_CVS.pm b/Perl/Local/VCS_CVS.pm
index 14f6b7ec016..cdd27cddc54 100644
--- a/Perl/Local/VCS_CVS.pm
+++ b/Perl/Local/VCS_CVS.pm
@@ -56,7 +56,7 @@ BEGIN {
&vcs_cmp_rev &vcs_count_changes
&vcs_get_topdir
&vcs_path_info &vcs_file_info
- &vcs_get_log
+ &vcs_get_log &vcs_get_diff
);
our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
}
@@ -280,7 +280,7 @@ sub vcs_file_info
Return the log info about a specified file
The first argument is a name of a checked-out file.
-The (optional) seconds and third argument specify the starting and end revision
+The (optional) second and third argument specify the starting and end revision
of the log entries
Example use:
@@ -343,6 +343,74 @@ sub vcs_get_log
return reverse @logdata;
}
+=item vcs_get_diff
+
+Returns a hash of (filename,diff) pairs info about a specified file or
+directory.
+
+The first argument is a name of a checked-out file. The second and third
+argument specify the starting and end revision of the log entries. If the
+third argument is not specified, the current (possibly modified) version is
+used. If the second argument is also not specified, the current (possibly
+modified) version is diffed against the latest checked in version.
+
+Example use:
+
+ my %diffs = vcs_get_diff( 'foo.wml', '1.4', '1.17' );
+ my %diffs = vcs_get_diff( 'bla.wml', '1.8' );
+ my %diffs = vcs_get_diff( 'bas.wml' );
+
+=cut
+
+sub vcs_get_diff
+{
+ my $file = shift or return;
+ my $rev1 = shift;
+ my $rev2 = shift;
+
+ # hash to store the output
+ my %data;
+
+ my $command = sprintf( 'cvs -q diff %s %s -u %s 2> /dev/null',
+ defined $rev1 ? "-r$rev1" : '',
+ defined $rev2 ? "-r$rev2" : '',
+ $file );
+
+ # set the record separator for cvs diff output
+ local $/ = "\n" . ('=' x 67) . "\n";
+
+ open( my $cvs, '-|', $command )
+ or croak("Couldn't run `$command': $!");
+
+ # the first "record" is bogusl
+ <$cvs>;
+
+ # read the consequetive records
+ while ( my $record = <$cvs> )
+ {
+ # remove the record separator from the end of the record
+ $record =~ s{ $/ \n? \Z }{}msx;
+
+ # remove the "Index:" line from the end of the record
+ $record =~ s{ ^Index: [^\n]+ \n+ \Z }{}msx;
+
+ # remove the first four lines
+ $record =~ s{ \A (?: .*? \n ){4} }{}msx;
+
+ # get the file name
+ if ( not $record =~ m{ \A --- \s+ ([^\t]+) \t }msx )
+ {
+ croak("Parse error in output of `$command'");
+ }
+ my $file = $1;
+
+ $data{$file} = $record;
+ }
+ close( $cvs );
+
+ return %data;
+}
+
=item vcs_get_topdir
Return the top dir of the webwml repository

© 2014-2024 Faster IT GmbH | imprint | privacy policy