From efc00108d1057ca715beea03271cfe9ebb55c22e Mon Sep 17 00:00:00 2001 From: Steve McIntyre Date: Thu, 31 May 2018 11:36:38 +0100 Subject: Add get_newest_revision() and test harness code for it --- Perl/Local/VCS_CVS.pm | 22 ++++++++++++++++++++++ Perl/Local/VCS_git.pm | 31 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'Perl') diff --git a/Perl/Local/VCS_CVS.pm b/Perl/Local/VCS_CVS.pm index 890f544c3a6..1f140742d47 100644 --- a/Perl/Local/VCS_CVS.pm +++ b/Perl/Local/VCS_CVS.pm @@ -545,6 +545,28 @@ sub get_oldest_revision return '1.1'; # earliest possible revision of any file, easy! } +=item get_newest_revision + +Return the version of the newest version of a file + +The first argument is a name of a file. + +This function finds the newest revision of a file that is known in the +repository and returns it. + +Example use: + + my $rev = get_newest_revision( 'foo.c'); + +=cut + +sub get_newest_revision +{ + # NOT SUPPORTED in the CVS code + + croak("NOT SUPPORTED IN THE CVS CODE"); +} + =item next_revision Given a file path and a current revision of that file, move backwards diff --git a/Perl/Local/VCS_git.pm b/Perl/Local/VCS_git.pm index 136d19f4153..d8ef385555f 100644 --- a/Perl/Local/VCS_git.pm +++ b/Perl/Local/VCS_git.pm @@ -756,6 +756,37 @@ sub get_oldest_revision croak(" Could not find any revisions for $file"); } +=item get_newest_revision + +Return the version of the newest version of a file + +The first argument is a name of a file. + +This function finds the newest revision of a file that is known in the +repository and returns it. + +Example use: + + my $rev = get_newest_revision( 'foo.c'); + +=cut + +sub get_newest_revision +{ + my $self = shift; + my $file = shift or croak("No file specified"); + + croak( "No such file: $file" ) unless -f $file; + + my @commits = $self->_grab_commits($file); + if (@commits) { + # Simply return the last revision in our list + return $commits[0]{'cmt_rev'}; + } + # Should hopefully never get here! + croak(" Could not find any revisions for $file"); +} + =item next_revision Given a file path and a current revision of that file, move backwards -- cgit v1.2.3