From 5876381bd2f5f8a62d415163e170393647c239a9 Mon Sep 17 00:00:00 2001 From: Laura Arjona Reina Date: Tue, 7 Nov 2017 10:50:03 +0000 Subject: initial conversion of function vcs_count_changes into git: use git rev-list --count to get number of changes between 2 revisions CVS version numbers Perl/Local/VCS_git.pm: 1.5 -> 1.6 --- Perl/Local/VCS_git.pm | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'Perl') diff --git a/Perl/Local/VCS_git.pm b/Perl/Local/VCS_git.pm index 3b35bded30f..46b075a7043 100644 --- a/Perl/Local/VCS_git.pm +++ b/Perl/Local/VCS_git.pm @@ -135,37 +135,35 @@ FIXME: this needs to be "translated" into git and hashes sub vcs_count_changes { + # FIXME: not sure if we need to handle the issue of wrong $rev1/$rev2 here + # or the caller function will care. + # Not sure if this function makes sense in a git context, either, + # but just in case + my $file = shift or return undef; - my $rev1 = shift || '1.1'; + my $rev1 = shift || ''; my $rev2 = shift || 'HEAD'; - $rev1 = '1.1' if $rev1 eq 'n/a'; + $rev1 = '' if $rev1 eq 'n/a'; - # find the version number of HEAD, if it was specified - if ( $rev2 eq 'HEAD' ) - { - my %info = vcs_file_info( $file ); - return -1 if not %info; - $rev2 = $info{'cmt_rev'}; - } - - # for CVS, this is pretty easy: we simply compare the two version numbers + # for git, this is pretty easy: we simply compare the two version numbers # note: we don't support branches (aren't used in the webwml repo anyway) - my @rev1 = split( /\./, $rev1 ); - my @rev2 = split( /\./, $rev2 ); - - croak "non-similar revision numbers `$rev1' and `$rev2' (different branches?)" - if ( scalar @rev1 != scalar @rev2 ); - # check that all but the last components of the version numbers match - # i.e., we can compare 2.0.1 and 2.0.17, but not 1.0.2 and 2.0.17 - while ( @rev1 > 1 ) + my $command = sprintf( 'git rev-list --count %s..%s %s', $rev1, $rev2, $file ); + + open ( my $git, '-|', $command ) + or croak("Error while executing `$command': $!"); + my $text; + while ( my $line = <$git> ) { - croak "non-similar revision numbers (different branches?)" - unless shift @rev1 == shift @rev2; + $text .= $line; } + close( $git ); + croak("Error while executing `$command': $!") unless WIFEXITED($?); + + # return the number of changes (or error text) - return $rev2[0] - $rev1[0]; + return $text; } -- cgit v1.2.3