#!/usr/bin/perl -w # # Show the last n CVS commits for a file # # 2006-10-04: Written by Steven J. DeRose, sderose@acm.org. # 2007-12-17 sjd: strict, version. use strict; use Getopt::Long; my $version = "2010-09-12"; my $n = 5; my $quiet = 0; my $verbose = 0; # Process options Getopt::Long::Configure ("ignore_case"); my $result = GetOptions( "h|help|?" => sub { system "perldoc cvslast"; exit; }, "n=n" => \$n, "q|quiet!" => \$quiet, "v|verbose+" => \$verbose, "version" => sub { die "Version of $version, by Steven J. DeRose.\n"; } ); ($result) || die "Bad options.\n"; # Validate and default options # ($n >= 0) || die "Invalid -n (number of revisions) option '$ARGV[0]'\n"; my $file = $ARGV[0]; (-e $ARGV[0]) || die "Couldn't find file '$ARGV[0]'.\n"; ############################################################################### # Get the latest revision number # my $latest = `cvs log -h $file | grep '^head:'`; chomp($latest); $latest =~ s/head: //; ($verbose) && warn "Latest revision: $latest\n"; # Assemble the lowest revision number we want my ($major, $minor) = split(/\./,$latest); my $earliest; if ($minor > $n) { $earliest = $major . "." . ($minor - $n + 1); } else { $earliest = $major . 1; } # Issue the command my $cmd = "cvs log -r$earliest:$latest $file | more"; print "\n$cmd\n"; system "$cmd"; exit; ############################################################################### # sub showUsage() { warn " =head1 Usage cvslast [options] [file] Shows the CVS log for the last several revisions of the file (default 5). =head1 Options =over =item * B<-n> Set how many revisions to show (default 5). =item * B<-q> Suppresses most messages. =item * B<-version> Show version info and exit. =back =head1 Ownership This work by Steven J. DeRose is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. For further information on this license, see http://creativecommons.org/licenses/by-sa/3.0/. The author's present email is sderose at acm.org. For the most recent version, see http://www.derose.net/steve/utilities/. =cut "; }