1998-06-17 01:43:24 +04:00
|
|
|
#!/usr/bonsaitools/bin/perl --
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# The contents of this file are subject to the Netscape Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/NPL/
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
|
|
|
# The Original Code is the Bonsai CVS tool.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 02:33:56 +03:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# cvsblame.pl - Shamelessly adapted from Scott Furman's cvsblame script
|
|
|
|
# by Steve Lamm (slamm@netscape.com)
|
|
|
|
# - Annotate each line of a CVS file with its author,
|
|
|
|
# revision #, date, etc.
|
|
|
|
#
|
|
|
|
# Report problems to Steve Lamm (slamm@netscape.com)
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
use diagnostics;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
# Shut up misguided -w warnings about "used only once". "use vars" just
|
|
|
|
# doesn't work for me.
|
|
|
|
|
|
|
|
sub cvsblame_pl_sillyness {
|
|
|
|
my $zz;
|
|
|
|
$zz = $::file_description;
|
|
|
|
$zz = $::opt_A;
|
|
|
|
$zz = $::opt_d;
|
|
|
|
$zz = $::principal_branch;
|
|
|
|
$zz = %::lines_added;
|
|
|
|
$zz = %::lines_removed;
|
|
|
|
};
|
|
|
|
|
1999-07-08 20:16:47 +04:00
|
|
|
use Time::Local qw(timegm); # timestamps
|
1999-10-19 02:55:01 +04:00
|
|
|
use Date::Format; # human-readable dates
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
my $debug = 0;
|
|
|
|
$::opt_m = 0 unless (defined($::opt_m));
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Extract base part of this script's name
|
1999-10-19 02:55:01 +04:00
|
|
|
($::progname = $0) =~ /([^\/]+)$/;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
&cvsblame_init;
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
my $SECS_PER_DAY;
|
|
|
|
my $time;
|
1998-06-22 20:36:43 +04:00
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
sub cvsblame_init {
|
|
|
|
# Use default formatting options if none supplied
|
1999-10-19 02:55:01 +04:00
|
|
|
if (!$::opt_A && !$::opt_a && !$::opt_d && !$::opt_v) {
|
|
|
|
$::opt_a = 1;
|
|
|
|
$::opt_v = 1;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$time = time;
|
|
|
|
$SECS_PER_DAY = 60 * 60 * 24;
|
|
|
|
|
|
|
|
# Timestamp threshold at which annotations begin to occur, if -m option present.
|
1999-10-19 02:55:01 +04:00
|
|
|
$::opt_m_timestamp = $time;
|
|
|
|
if (defined $::opt_m) {
|
|
|
|
$::opt_m_timestamp -= $::opt_m * $SECS_PER_DAY;
|
|
|
|
}
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generic traversal of a CVS tree. Invoke callback function for
|
|
|
|
# individual directories that contain CVS files.
|
|
|
|
sub traverse_cvs_tree {
|
1999-10-19 02:55:01 +04:00
|
|
|
my ($dir, $nlink);
|
1999-07-08 20:16:47 +04:00
|
|
|
local *callback;
|
|
|
|
($dir, *callback, $nlink) = @_;
|
|
|
|
my ($dev, $ino, $mode, $subcount);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Get $nlink for top-level directory
|
|
|
|
($dev, $ino, $mode, $nlink) = stat($dir) unless $nlink;
|
|
|
|
|
|
|
|
# Read directory
|
|
|
|
opendir(DIR, $dir) || die "Can't open $dir\n";
|
1999-07-08 20:16:47 +04:00
|
|
|
my (@filenames) = readdir(DIR);
|
1998-06-17 01:43:24 +04:00
|
|
|
closedir(DIR);
|
|
|
|
|
|
|
|
return if ! -d "$dir/CVS";
|
|
|
|
|
|
|
|
&callback($dir);
|
|
|
|
|
|
|
|
# This dir has subdirs
|
|
|
|
if ($nlink != 2) {
|
|
|
|
$subcount = $nlink - 2; # Number of subdirectories
|
|
|
|
for (@filenames) {
|
|
|
|
last if $subcount == 0;
|
|
|
|
next if $_ eq '.';
|
|
|
|
next if $_ eq '..';
|
|
|
|
next if $_ eq 'CVS';
|
1999-10-19 02:55:01 +04:00
|
|
|
my $name = "$dir/$_";
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
($dev, $ino, $mode, $nlink) = lstat($name);
|
|
|
|
next unless -d _;
|
|
|
|
if (-x _ && -r _) {
|
1999-10-19 02:55:01 +04:00
|
|
|
print STDERR "$::progname: Entering $name\n";
|
1998-06-17 01:43:24 +04:00
|
|
|
&traverse_cvs_tree($name, *callback, $nlink);
|
|
|
|
} else {
|
|
|
|
warn("Couldn't chdir to $name");
|
|
|
|
}
|
|
|
|
--$subcount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Consume one token from the already opened RCSFILE filehandle.
|
|
|
|
# Unescape string tokens, if necessary.
|
1999-10-19 02:55:01 +04:00
|
|
|
|
|
|
|
my $line_buffer;
|
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
sub get_token {
|
|
|
|
# Erase all-whitespace lines.
|
1999-07-23 22:39:31 +04:00
|
|
|
$line_buffer = '' unless (defined($line_buffer));
|
1998-06-17 01:43:24 +04:00
|
|
|
while ($line_buffer =~ /^$/) {
|
|
|
|
die ("Unexpected EOF") if eof(RCSFILE);
|
|
|
|
$line_buffer = <RCSFILE>;
|
|
|
|
$line_buffer =~ s/^\s+//; # Erase leading whitespace
|
|
|
|
}
|
|
|
|
|
|
|
|
# A string of non-whitespace characters is a token ...
|
|
|
|
return $1 if ($line_buffer =~ s/^([^;@][^;\s]*)\s*//o);
|
|
|
|
|
|
|
|
# ...and so is a single semicolon ...
|
|
|
|
return ';' if ($line_buffer =~ s/^;\s*//o);
|
|
|
|
|
|
|
|
# ...or an RCS-encoded string that starts with an @ character.
|
|
|
|
$line_buffer =~ s/^@([^@]*)//o;
|
1999-10-19 02:55:01 +04:00
|
|
|
my $token = $1;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Detect single @ character used to close RCS-encoded string.
|
|
|
|
while ($line_buffer !~ /@/o || # Short-circuit optimization
|
|
|
|
$line_buffer !~ /([^@]|^)@([^@]|$)/o) {
|
|
|
|
$token .= $line_buffer;
|
|
|
|
die ("Unexpected EOF") if eof(RCSFILE);
|
|
|
|
$line_buffer = <RCSFILE>;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Retain the remainder of the line after the terminating @ character.
|
1999-10-19 02:55:01 +04:00
|
|
|
my $i = rindex($line_buffer, '@');
|
1998-06-17 01:43:24 +04:00
|
|
|
$token .= substr($line_buffer, 0, $i);
|
|
|
|
$line_buffer = substr($line_buffer, $i + 1);
|
|
|
|
|
|
|
|
# Undo escape-coding of @ characters.
|
|
|
|
$token =~ s/@@/@/og;
|
|
|
|
|
1998-06-18 20:47:00 +04:00
|
|
|
# Digest any extra blank lines.
|
|
|
|
while (($line_buffer =~ /^$/) && !eof(RCSFILE)) {
|
|
|
|
$line_buffer = <RCSFILE>;
|
|
|
|
}
|
1998-06-17 01:43:24 +04:00
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
my $rcs_pathname;
|
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
# Consume a token from RCS filehandle and ensure that it matches
|
|
|
|
# the given string constant.
|
|
|
|
sub match_token {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($match) = @_;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($token) = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
die "Unexpected parsing error in RCS file $rcs_pathname.\n",
|
|
|
|
"Expected token: $match, but saw: $token\n"
|
|
|
|
if ($token ne $match);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Push RCS token back into the input buffer.
|
|
|
|
sub unget_token {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($token) = @_;
|
1998-06-17 01:43:24 +04:00
|
|
|
$line_buffer = $token . " " . $line_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parses "administrative" header of RCS files, setting these globals:
|
|
|
|
#
|
1999-10-19 02:55:01 +04:00
|
|
|
# $::head_revision -- Revision for which cleartext is stored
|
|
|
|
# $::principal_branch
|
|
|
|
# $::file_description
|
|
|
|
# %::revision_symbolic_name -- maps from numerical revision # to symbolic tag
|
|
|
|
# %::tag_revision -- maps from symbolic tag to numerical revision #
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
|
|
|
sub parse_rcs_admin {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($token, $tag, $tag_name, $tag_revision);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Undefine variables, because we may have already read another RCS file
|
1999-10-19 02:55:01 +04:00
|
|
|
undef %::tag_revision;
|
|
|
|
undef %::revision_symbolic_name;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
# Read initial token at beginning of line
|
1999-10-19 02:55:01 +04:00
|
|
|
$token = &get_token();
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# We're done once we reach the description of the RCS tree
|
|
|
|
if ($token =~ /^\d/o) {
|
|
|
|
&unget_token($token);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# print "token: $token\n";
|
|
|
|
|
|
|
|
if ($token eq "head") {
|
1999-10-19 02:55:01 +04:00
|
|
|
$::head_revision = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
&get_token; # Eat semicolon
|
|
|
|
} elsif ($token eq "branch") {
|
1999-10-19 02:55:01 +04:00
|
|
|
$::principal_branch = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
&get_token; # Eat semicolon
|
|
|
|
} elsif ($token eq "symbols") {
|
|
|
|
|
|
|
|
# Create an associate array that maps from tag name to
|
|
|
|
# revision number and vice-versa.
|
|
|
|
while (($tag = &get_token) ne ';') {
|
|
|
|
($tag_name, $tag_revision) = split(':', $tag);
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
$::tag_revision{$tag_name} = $tag_revision;
|
|
|
|
$::revision_symbolic_name{$tag_revision} = $tag_name;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
} elsif ($token eq "comment") {
|
1999-10-19 02:55:01 +04:00
|
|
|
$::file_description = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
&get_token; # Eat semicolon
|
|
|
|
|
|
|
|
# Ignore all these other fields - We don't care about them.
|
|
|
|
} elsif (($token eq "locks") ||
|
|
|
|
($token eq "strict") ||
|
|
|
|
($token eq "expand") ||
|
|
|
|
($token eq "access")) {
|
|
|
|
(1) while (&get_token ne ';');
|
|
|
|
} else {
|
|
|
|
warn ("Unexpected RCS token: $token\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
die "Unexpected EOF";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Construct associative arrays that represent the topology of the RCS tree
|
|
|
|
# and other arrays that contain info about individual revisions.
|
|
|
|
#
|
|
|
|
# The following associative arrays are created, keyed by revision number:
|
1999-10-19 02:55:01 +04:00
|
|
|
# %::revision_date -- e.g. "96.02.23.00.21.52"
|
|
|
|
# %::timestamp -- seconds since 12:00 AM, Jan 1, 1970 GMT
|
|
|
|
# %::revision_author -- e.g. "tom"
|
|
|
|
# %::revision_branches -- descendant branch revisions, separated by spaces,
|
1998-06-17 01:43:24 +04:00
|
|
|
# e.g. "1.21.4.1 1.21.2.6.1"
|
1999-10-19 02:55:01 +04:00
|
|
|
# %::prev_revision -- revision number of previous *ancestor* in RCS tree.
|
1998-06-17 01:43:24 +04:00
|
|
|
# Traversal of this array occurs in the direction
|
|
|
|
# of the primordial (1.1) revision.
|
1999-10-19 02:55:01 +04:00
|
|
|
# %::prev_delta -- revision number of previous revision which forms
|
|
|
|
# the basis for the edit commands in this revision.
|
1998-06-17 01:43:24 +04:00
|
|
|
# This causes the tree to be traversed towards the
|
|
|
|
# trunk when on a branch, and towards the latest trunk
|
|
|
|
# revision when on the trunk.
|
1999-10-19 02:55:01 +04:00
|
|
|
# %::next_delta -- revision number of next "delta". Inverts %::prev_delta.
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
1999-10-19 02:55:01 +04:00
|
|
|
# Also creates %::last_revision, keyed by a branch revision number, which
|
1998-06-17 01:43:24 +04:00
|
|
|
# indicates the latest revision on a given branch,
|
1999-10-19 02:55:01 +04:00
|
|
|
# e.g. $::last_revision{"1.2.8"} == 1.2.8.5
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
1999-10-19 02:55:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
my %revision_age;
|
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
sub parse_rcs_tree {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($revision, $date, $author, $branches, $next);
|
|
|
|
my ($branch, $is_trunk_revision);
|
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
# Undefine variables, because we may have already read another RCS file
|
1999-10-19 02:55:01 +04:00
|
|
|
undef %::timestamp;
|
1998-06-17 01:43:24 +04:00
|
|
|
undef %revision_age;
|
1999-10-19 02:55:01 +04:00
|
|
|
undef %::revision_author;
|
|
|
|
undef %::revision_branches;
|
|
|
|
undef %::revision_ctime;
|
|
|
|
undef %::revision_date;
|
|
|
|
undef %::prev_revision;
|
|
|
|
undef %::prev_delta;
|
|
|
|
undef %::next_delta;
|
|
|
|
undef %::last_revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
$revision = &get_token;
|
|
|
|
|
|
|
|
# End of RCS tree description ?
|
|
|
|
if ($revision eq 'desc') {
|
|
|
|
&unget_token($revision);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_trunk_revision = ($revision =~ /^[0-9]+\.[0-9]+$/);
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
$::tag_revision{$revision} = $revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
($branch) = $revision =~ /(.*)\.[0-9]+/o;
|
1999-10-19 02:55:01 +04:00
|
|
|
$::last_revision{$branch} = $revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Parse date
|
|
|
|
&match_token('date');
|
|
|
|
$date = &get_token;
|
1999-10-19 02:55:01 +04:00
|
|
|
$::revision_date{$revision} = $date;
|
1998-06-17 01:43:24 +04:00
|
|
|
&match_token(';');
|
|
|
|
|
|
|
|
# Convert date into timestamp
|
1999-10-19 02:55:01 +04:00
|
|
|
my @date_fields = reverse(split(/\./, $date));
|
1998-06-17 01:43:24 +04:00
|
|
|
$date_fields[4]--; # Month ranges from 0-11, not 1-12
|
1999-10-19 02:55:01 +04:00
|
|
|
$::timestamp{$revision} = timegm(@date_fields);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-07-08 20:16:47 +04:00
|
|
|
# Pretty print the date string
|
1999-10-19 02:55:01 +04:00
|
|
|
my @ltime = localtime($::timestamp{$revision});
|
|
|
|
my $formated_date = strftime("%d %b %Y %H:%M", @ltime);
|
|
|
|
$::revision_ctime{$revision} = $formated_date;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Save age
|
|
|
|
$revision_age{$revision} =
|
1999-10-19 02:55:01 +04:00
|
|
|
($time - $::timestamp{$revision}) / $SECS_PER_DAY;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Parse author
|
|
|
|
&match_token('author');
|
|
|
|
$author = &get_token;
|
1999-10-19 02:55:01 +04:00
|
|
|
$::revision_author{$revision} = $author;
|
1998-06-17 01:43:24 +04:00
|
|
|
&match_token(';');
|
|
|
|
|
|
|
|
# Parse state;
|
|
|
|
&match_token('state');
|
1999-10-19 02:55:01 +04:00
|
|
|
while (&get_token ne ';') { }
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Parse branches
|
|
|
|
&match_token('branches');
|
|
|
|
$branches = '';
|
1999-10-19 02:55:01 +04:00
|
|
|
my $token;
|
1998-06-17 01:43:24 +04:00
|
|
|
while (($token = &get_token) ne ';') {
|
1999-10-19 02:55:01 +04:00
|
|
|
$::prev_revision{$token} = $revision;
|
|
|
|
$::prev_delta{$token} = $revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
$branches .= "$token ";
|
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
$::revision_branches{$revision} = $branches;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Parse revision of next delta in chain
|
|
|
|
&match_token('next');
|
|
|
|
$next = '';
|
|
|
|
if (($token = &get_token) ne ';') {
|
|
|
|
$next = $token;
|
|
|
|
&get_token; # Eat semicolon
|
1999-10-19 02:55:01 +04:00
|
|
|
$::next_delta{$revision} = $next;
|
|
|
|
$::prev_delta{$next} = $revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
if ($is_trunk_revision) {
|
1999-10-19 02:55:01 +04:00
|
|
|
$::prev_revision{$revision} = $next;
|
1998-06-17 01:43:24 +04:00
|
|
|
} else {
|
1999-10-19 02:55:01 +04:00
|
|
|
$::prev_revision{$next} = $revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($debug >= 3) {
|
|
|
|
print "<pre>revision = $revision\n";
|
|
|
|
print "date = $date\n";
|
|
|
|
print "author = $author\n";
|
|
|
|
print "branches = $branches\n";
|
|
|
|
print "next = $next</pre>\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_rcs_description {
|
|
|
|
&match_token('desc');
|
1999-10-19 02:55:01 +04:00
|
|
|
my $rcs_file_description = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Construct associative arrays containing info about individual revisions.
|
|
|
|
#
|
|
|
|
# The following associative arrays are created, keyed by revision number:
|
1999-10-19 02:55:01 +04:00
|
|
|
# %::revision_log -- log message
|
|
|
|
# %::revision_deltatext -- Either the complete text of the revision,
|
1998-06-17 01:43:24 +04:00
|
|
|
# in the case of the head revision, or the
|
|
|
|
# encoded delta between this revision and another.
|
|
|
|
# The delta is either with respect to the successor
|
|
|
|
# revision if this revision is on the trunk or
|
|
|
|
# relative to its immediate predecessor if this
|
|
|
|
# revision is on a branch.
|
|
|
|
sub parse_rcs_deltatext {
|
1999-10-19 02:55:01 +04:00
|
|
|
undef %::revision_log;
|
|
|
|
undef %::revision_deltatext;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
while (!eof(RCSFILE)) {
|
1999-10-19 02:55:01 +04:00
|
|
|
my $revision = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
print "Reading delta for revision: $revision\n" if ($debug >= 3);
|
|
|
|
&match_token('log');
|
1999-10-19 02:55:01 +04:00
|
|
|
$::revision_log{$revision} = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
&match_token('text');
|
1999-10-19 02:55:01 +04:00
|
|
|
$::revision_deltatext{$revision} = &get_token;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
# Reads and parses complete RCS file from already-opened RCSFILE descriptor.
|
2003-05-19 16:58:45 +04:00
|
|
|
# Or if a parameter is given use the corresponding file
|
1998-06-17 01:43:24 +04:00
|
|
|
sub parse_rcs_file {
|
2003-05-19 16:58:45 +04:00
|
|
|
my $path = shift;
|
|
|
|
if (defined $path) {
|
|
|
|
open (RCSFILE, "< $path");
|
|
|
|
}
|
1998-06-17 01:43:24 +04:00
|
|
|
print "Reading RCS admin...\n" if ($debug >= 2);
|
|
|
|
&parse_rcs_admin();
|
|
|
|
print "Reading RCS revision tree topology...\n" if ($debug >= 2);
|
|
|
|
&parse_rcs_tree();
|
|
|
|
|
|
|
|
if( $debug >= 3 ){
|
|
|
|
print "<pre>Keys:\n\n";
|
1999-10-19 02:55:01 +04:00
|
|
|
for my $i (keys %::tag_revision ){
|
|
|
|
my $k = $::tag_revision{$i};
|
1998-06-17 01:43:24 +04:00
|
|
|
print "yoyuo $i: $k\n";
|
|
|
|
}
|
|
|
|
print "</pre>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
&parse_rcs_description();
|
|
|
|
print "Reading RCS revision deltas...\n" if ($debug >= 2);
|
|
|
|
&parse_rcs_deltatext();
|
|
|
|
print "Done reading RCS file...\n" if ($debug >= 2);
|
2003-05-19 16:58:45 +04:00
|
|
|
close RCSFILE if (defined $path);
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Map a tag to a numerical revision number. The tag can be a symbolic
|
|
|
|
# branch tag, a symbolic revision tag, or an ordinary numerical
|
|
|
|
# revision number.
|
|
|
|
sub map_tag_to_revision {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($tag_or_revision) = @_;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
my ($revision) = $::tag_revision{$tag_or_revision};
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Is this a branch tag, e.g. xxx.yyy.0.zzz
|
|
|
|
if ($revision =~ /(.*)\.0\.([0-9]+)/o) {
|
1999-10-19 02:55:01 +04:00
|
|
|
my $branch = $1 . '.' . $2;
|
1998-06-17 01:43:24 +04:00
|
|
|
# Return latest revision on the branch, if any.
|
1999-10-19 02:55:01 +04:00
|
|
|
return $::last_revision{$branch} if (defined($::last_revision{$branch}));
|
1998-06-17 01:43:24 +04:00
|
|
|
return $1; # No revisions on branch - return branch point
|
|
|
|
} else {
|
|
|
|
return $revision;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Construct an ordered list of ancestor revisions to the given
|
|
|
|
# revision, starting with the immediate ancestor and going back
|
|
|
|
# to the primordial revision (1.1).
|
|
|
|
#
|
|
|
|
# Note: The generated path does not traverse the tree the same way
|
|
|
|
# that the individual revision deltas do. In particular,
|
|
|
|
# the path traverses the tree "backwards" on branches.
|
|
|
|
|
|
|
|
sub ancestor_revisions {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($revision) = @_;
|
|
|
|
my (@ancestors);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
$revision = $::prev_revision{$revision};
|
1998-06-17 01:43:24 +04:00
|
|
|
while ($revision) {
|
|
|
|
push(@ancestors, $revision);
|
1999-10-19 02:55:01 +04:00
|
|
|
$revision = $::prev_revision{$revision};
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return @ancestors;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Extract the given revision from the digested RCS file.
|
|
|
|
# (Essentially the equivalent of cvs up -rXXX)
|
|
|
|
sub extract_revision {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($revision) = @_;
|
|
|
|
my (@path);
|
1999-10-19 02:55:01 +04:00
|
|
|
my $add_lines_remaining = 0;
|
|
|
|
my ($start_line, $count);
|
1998-06-17 01:43:24 +04:00
|
|
|
# Compute path through tree of revision deltas to most recent trunk revision
|
|
|
|
while ($revision) {
|
|
|
|
push(@path, $revision);
|
1999-10-19 02:55:01 +04:00
|
|
|
$revision = $::prev_delta{$revision};
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
@path = reverse(@path);
|
|
|
|
shift @path; # Get rid of head revision
|
|
|
|
|
|
|
|
# Get complete contents of head revision
|
1999-10-19 02:55:01 +04:00
|
|
|
my (@text) = split(/^/, $::revision_deltatext{$::head_revision});
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Iterate, applying deltas to previous revision
|
|
|
|
foreach $revision (@path) {
|
1999-10-19 02:55:01 +04:00
|
|
|
my $adjust = 0;
|
|
|
|
my @diffs = split(/^/, $::revision_deltatext{$revision});
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($lines_added) = 0;
|
|
|
|
my ($lines_removed) = 0;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
foreach my $command (@diffs) {
|
1998-06-17 01:43:24 +04:00
|
|
|
if ($add_lines_remaining > 0) {
|
|
|
|
# Insertion lines from a prior "a" command.
|
|
|
|
splice(@text, $start_line + $adjust,
|
|
|
|
0, $command);
|
|
|
|
$add_lines_remaining--;
|
|
|
|
$adjust++;
|
|
|
|
} elsif ($command =~ /^d(\d+)\s(\d+)/) {
|
|
|
|
# "d" - Delete command
|
|
|
|
($start_line, $count) = ($1, $2);
|
|
|
|
splice(@text, $start_line + $adjust - 1, $count);
|
|
|
|
$adjust -= $count;
|
|
|
|
$lines_removed += $count;
|
|
|
|
} elsif ($command =~ /^a(\d+)\s(\d+)/) {
|
|
|
|
# "a" - Add command
|
|
|
|
($start_line, $count) = ($1, $2);
|
|
|
|
$add_lines_remaining = $count;
|
|
|
|
$lines_added += $lines_added;
|
|
|
|
} else {
|
|
|
|
die "Error parsing diff commands";
|
|
|
|
}
|
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
$::lines_removed{$revision} += $lines_removed;
|
|
|
|
$::lines_added{$revision} += $lines_added;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return @text;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_cvs_file {
|
1999-10-19 02:55:01 +04:00
|
|
|
($rcs_pathname) = @_;
|
|
|
|
|
|
|
|
# Args in: $::opt_rev - requested revision
|
|
|
|
# $::opt_m - time since modified
|
|
|
|
# Args out: @::revision_map
|
|
|
|
# %::timestamp
|
|
|
|
# (%::revision_deltatext)
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
my @diffs;
|
|
|
|
my $revision;
|
|
|
|
my $skip;
|
|
|
|
my ($start_line, $count);
|
|
|
|
my @temp;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
@::revision_map = ();
|
1998-06-18 20:47:00 +04:00
|
|
|
CheckHidden($rcs_pathname);
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
die "$::progname: error: This file appeared to be under CVS control, " .
|
1998-06-17 01:43:24 +04:00
|
|
|
"but the RCS file is inaccessible.\n(Couldn't open '$rcs_pathname')\n"
|
|
|
|
if !open (RCSFILE, "< $rcs_pathname");
|
|
|
|
&parse_rcs_file();
|
|
|
|
close(RCSFILE);
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
if (!defined($::opt_rev) || $::opt_rev eq '' || $::opt_rev eq 'HEAD') {
|
1998-06-17 01:43:24 +04:00
|
|
|
# Explicitly specified topmost revision in tree
|
1999-10-19 02:55:01 +04:00
|
|
|
$revision = $::head_revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
} else {
|
|
|
|
# Symbolic tag or specific revision number specified.
|
1999-10-19 02:55:01 +04:00
|
|
|
$revision = &map_tag_to_revision($::opt_rev);
|
|
|
|
die "$::progname: error: -r: No such revision: $::opt_rev\n"
|
1998-06-17 01:43:24 +04:00
|
|
|
if ($revision eq '');
|
|
|
|
}
|
|
|
|
|
|
|
|
# The primordial revision is not always 1.1! Go find it.
|
|
|
|
my $primordial = $revision;
|
1999-10-19 02:55:01 +04:00
|
|
|
while (exists($::prev_revision{$primordial}) &&
|
|
|
|
$::prev_revision{$primordial} ne "") {
|
|
|
|
$primordial = $::prev_revision{$primordial};
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Don't display file at all, if -m option is specified and no
|
|
|
|
# changes have been made in the specified file.
|
1999-10-19 02:55:01 +04:00
|
|
|
if ($::opt_m && $::timestamp{$revision} < $::opt_m_timestamp) {
|
|
|
|
return '';
|
|
|
|
}
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Figure out how many lines were in the primordial, i.e. version 1.1,
|
|
|
|
# check-in by moving backward in time from the head revision to the
|
|
|
|
# first revision.
|
1999-10-19 02:55:01 +04:00
|
|
|
my $line_count = 0;
|
|
|
|
if (exists ($::revision_deltatext{$::head_revision}) &&
|
|
|
|
$::revision_deltatext{$::head_revision}) {
|
|
|
|
my @tmp_array = split(/^/, $::revision_deltatext{$::head_revision});
|
1999-07-23 22:39:31 +04:00
|
|
|
$line_count = @tmp_array;
|
|
|
|
}
|
|
|
|
$skip = 0 unless (defined($skip));
|
1999-10-19 02:55:01 +04:00
|
|
|
my $rev;
|
|
|
|
for ($rev = $::prev_revision{$::head_revision}; $rev;
|
|
|
|
$rev = $::prev_revision{$rev}) {
|
|
|
|
@diffs = split(/^/, $::revision_deltatext{$rev});
|
|
|
|
foreach my $command (@diffs) {
|
1998-06-17 01:43:24 +04:00
|
|
|
if ($skip > 0) {
|
|
|
|
# Skip insertion lines from a prior "a" command.
|
|
|
|
$skip--;
|
|
|
|
} elsif ($command =~ /^d(\d+)\s(\d+)/) {
|
|
|
|
# "d" - Delete command
|
|
|
|
($start_line, $count) = ($1, $2);
|
|
|
|
$line_count -= $count;
|
|
|
|
} elsif ($command =~ /^a(\d+)\s(\d+)/) {
|
|
|
|
# "a" - Add command
|
|
|
|
($start_line, $count) = ($1, $2);
|
|
|
|
$skip = $count;
|
|
|
|
$line_count += $count;
|
|
|
|
} else {
|
1999-10-19 02:55:01 +04:00
|
|
|
die "$::progname: error: illegal RCS file $rcs_pathname\n",
|
1998-06-17 01:43:24 +04:00
|
|
|
" error appears in revision $rev\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now, play the delta edit commands *backwards* from the primordial
|
|
|
|
# revision forward, but rather than applying the deltas to the text of
|
|
|
|
# each revision, apply the changes to an array of revision numbers.
|
|
|
|
# This creates a "revision map" -- an array where each element
|
|
|
|
# represents a line of text in the given revision but contains only
|
|
|
|
# the revision number in which the line was introduced rather than
|
|
|
|
# the line text itself.
|
|
|
|
#
|
|
|
|
# Note: These are backward deltas for revisions on the trunk and
|
|
|
|
# forward deltas for branch revisions.
|
|
|
|
|
|
|
|
# Create initial revision map for primordial version.
|
|
|
|
while ($line_count--) {
|
1999-10-19 02:55:01 +04:00
|
|
|
push(@::revision_map, $primordial);
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
my @ancestors = &ancestor_revisions($revision);
|
1998-06-17 01:43:24 +04:00
|
|
|
unshift (@ancestors, $revision); #
|
|
|
|
pop @ancestors; # Remove "1.1"
|
1999-10-19 02:55:01 +04:00
|
|
|
$::last_revision = $primordial;
|
1998-06-17 01:43:24 +04:00
|
|
|
foreach $revision (reverse @ancestors) {
|
1999-10-19 02:55:01 +04:00
|
|
|
my $is_trunk_revision = ($revision =~ /^[0-9]+\.[0-9]+$/);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
if ($is_trunk_revision) {
|
1999-10-19 02:55:01 +04:00
|
|
|
@diffs = split(/^/, $::revision_deltatext{$::last_revision});
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Revisions on the trunk specify deltas that transform a
|
|
|
|
# revision into an earlier revision, so invert the translation
|
|
|
|
# of the 'diff' commands.
|
1999-10-19 02:55:01 +04:00
|
|
|
foreach my $command (@diffs) {
|
1998-06-17 01:43:24 +04:00
|
|
|
if ($skip > 0) {
|
|
|
|
$skip--;
|
|
|
|
} else {
|
|
|
|
if ($command =~ /^d(\d+)\s(\d+)$/) { # Delete command
|
|
|
|
($start_line, $count) = ($1, $2);
|
|
|
|
|
|
|
|
$#temp = -1;
|
|
|
|
while ($count--) {
|
|
|
|
push(@temp, $revision);
|
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
splice(@::revision_map, $start_line - 1, 0, @temp);
|
1998-06-17 01:43:24 +04:00
|
|
|
} elsif ($command =~ /^a(\d+)\s(\d+)$/) { # Add command
|
|
|
|
($start_line, $count) = ($1, $2);
|
1999-10-19 02:55:01 +04:00
|
|
|
splice(@::revision_map, $start_line, $count);
|
1998-06-17 01:43:24 +04:00
|
|
|
$skip = $count;
|
|
|
|
} else {
|
|
|
|
die "Error parsing diff commands";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# Revisions on a branch are arranged backwards from those on
|
|
|
|
# the trunk. They specify deltas that transform a revision
|
|
|
|
# into a later revision.
|
1999-10-19 02:55:01 +04:00
|
|
|
my $adjust = 0;
|
|
|
|
@diffs = split(/^/, $::revision_deltatext{$revision});
|
|
|
|
foreach my $command (@diffs) {
|
1998-06-17 01:43:24 +04:00
|
|
|
if ($skip > 0) {
|
|
|
|
$skip--;
|
|
|
|
} else {
|
|
|
|
if ($command =~ /^d(\d+)\s(\d+)$/) { # Delete command
|
|
|
|
($start_line, $count) = ($1, $2);
|
1999-10-19 02:55:01 +04:00
|
|
|
splice(@::revision_map, $start_line + $adjust - 1, $count);
|
1998-06-17 01:43:24 +04:00
|
|
|
$adjust -= $count;
|
|
|
|
} elsif ($command =~ /^a(\d+)\s(\d+)$/) { # Add command
|
|
|
|
($start_line, $count) = ($1, $2);
|
|
|
|
|
|
|
|
$skip = $count;
|
|
|
|
$#temp = -1;
|
|
|
|
while ($count--) {
|
|
|
|
push(@temp, $revision);
|
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
splice(@::revision_map, $start_line + $adjust, 0, @temp);
|
1998-06-17 01:43:24 +04:00
|
|
|
$adjust += $skip;
|
|
|
|
} else {
|
|
|
|
die "Error parsing diff commands";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
$::last_revision = $revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
return $revision;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
1;
|
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
__END__
|
|
|
|
#
|
|
|
|
# The following are parts of the original cvsblame script that are not
|
|
|
|
# used for cvsblame.pl
|
|
|
|
#
|
|
|
|
|
|
|
|
# Read CVS/Entries and CVS/Repository files.
|
|
|
|
#
|
|
|
|
# Creates these associative arrays, keyed by the CVS file pathname
|
|
|
|
#
|
|
|
|
# %cvs_revision -- Revision # present in working directory
|
|
|
|
# %cvs_date
|
|
|
|
# %cvs_sticky_revision -- Sticky tag, if any
|
|
|
|
#
|
|
|
|
# Also, creates %cvs_files, keyed by the directory path, which contains
|
|
|
|
# a space-separated list of the files under CVS control in the directory
|
|
|
|
sub read_cvs_entries
|
|
|
|
{
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($directory) = @_;
|
|
|
|
my ($filename, $rev, $date, $idunno, $sticky, $pathname);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
$cvsdir = $directory . '/CVS';
|
|
|
|
|
1998-06-18 20:47:00 +04:00
|
|
|
CheckHidden($cvsdir);
|
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
return if (! -d $cvsdir);
|
|
|
|
|
|
|
|
return if !open(ENTRIES, "< $cvsdir/Entries");
|
|
|
|
|
|
|
|
while(<ENTRIES>) {
|
|
|
|
chop;
|
|
|
|
($filename, $rev, $date, $idunno, $sticky) = split("/", substr($_, 1));
|
|
|
|
($pathname) = $directory . "/" . $filename;
|
|
|
|
$cvs_revision{$pathname} = $rev;
|
|
|
|
$cvs_date{$pathname} = $date;
|
|
|
|
$cvs_sticky_revision{$pathname} = $sticky;
|
|
|
|
$cvs_files{$directory} .= "$filename\\";
|
|
|
|
}
|
|
|
|
close(ENTRIES);
|
|
|
|
|
|
|
|
return if !open(REPOSITORY, "< $cvsdir/Repository");
|
|
|
|
$repository = <REPOSITORY>;
|
|
|
|
chop($repository);
|
|
|
|
close(REPOSITORY);
|
|
|
|
$repository{$directory} = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Given path to file in CVS working directory, compute path to RCS
|
|
|
|
# repository file. Cache that info for future use.
|
1998-06-18 20:47:00 +04:00
|
|
|
|
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
sub rcs_pathname {
|
|
|
|
($pathname) = @_;
|
|
|
|
|
|
|
|
if ($pathname =~ m@/@) {
|
|
|
|
($directory,$filename) = $pathname =~ m@(.*)/([^/]+)$@;
|
|
|
|
} else {
|
|
|
|
($directory,$filename) = ('.',$pathname);
|
|
|
|
$pathname = "./" . $pathname;
|
|
|
|
}
|
|
|
|
if (!defined($repository{$directory})) {
|
|
|
|
&read_cvs_entries($directory);
|
|
|
|
}
|
1998-06-18 20:47:00 +04:00
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
if (!defined($cvs_revision{$pathname})) {
|
1999-10-19 02:55:01 +04:00
|
|
|
die "$::progname: error: File '$pathname' does not appear to be under" .
|
1998-06-17 01:43:24 +04:00
|
|
|
" CVS control.\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
print STDERR "file: $filename\n" if $debug;
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($rcs_path) = $repository{$directory} . '/' . $filename . ',v';
|
1998-06-17 01:43:24 +04:00
|
|
|
return $rcs_path if (-r $rcs_path);
|
|
|
|
|
|
|
|
# A file that exists only on the branch, not on the trunk, is found
|
|
|
|
# in the Attic subdir.
|
|
|
|
return $repository{$directory} . '/Attic/' . $filename . ',v';
|
|
|
|
}
|
|
|
|
|
|
|
|
sub show_annotated_cvs_file {
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($pathname) = @_;
|
|
|
|
my (@output) = ();
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
my $revision = &parse_cvs_file($pathname);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
@text = &extract_revision($revision);
|
1999-10-19 02:55:01 +04:00
|
|
|
die "$::progname: Internal consistency error" if ($#text != $#::revision_map);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Set total width of line annotation.
|
|
|
|
# Warning: field widths here must match format strings below.
|
|
|
|
$annotation_width = 0;
|
1999-10-19 02:55:01 +04:00
|
|
|
$annotation_width += 8 if $::opt_a; # author
|
|
|
|
$annotation_width += 7 if $::opt_v; # revision
|
|
|
|
$annotation_width += 6 if $::opt_A; # age
|
|
|
|
$annotation_width += 12 if $::opt_d; # date
|
1998-06-17 01:43:24 +04:00
|
|
|
$blank_annotation = ' ' x $annotation_width;
|
|
|
|
|
|
|
|
if ($multiple_files_on_command_line) {
|
|
|
|
print "\n", "=" x (83 + $annotation_width);
|
1999-10-19 02:55:01 +04:00
|
|
|
print "\n$::progname: Listing file: $pathname\n"
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Print each line of the revision, preceded by its annotation.
|
|
|
|
$line = 0;
|
1999-10-19 02:55:01 +04:00
|
|
|
foreach $revision (@::revision_map) {
|
1998-06-17 01:43:24 +04:00
|
|
|
$text = $text[$line++];
|
|
|
|
$annotation = '';
|
|
|
|
|
|
|
|
# Annotate with revision author
|
1999-10-19 02:55:01 +04:00
|
|
|
$annotation .= sprintf("%-8s", $::revision_author{$revision}) if $::opt_a;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Annotate with revision number
|
1999-10-19 02:55:01 +04:00
|
|
|
$annotation .= sprintf(" %-6s", $revision) if $::opt_v;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Date annotation
|
1999-10-19 02:55:01 +04:00
|
|
|
$annotation .= " $::revision_ctime{$revision}" if $::opt_d;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# Age annotation ?
|
|
|
|
$annotation .= sprintf(" (%3s)",
|
1999-10-19 02:55:01 +04:00
|
|
|
int($revision_age{$revision})) if $::opt_A;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
# -m (if-modified-since) annotion ?
|
1999-10-19 02:55:01 +04:00
|
|
|
if ($::opt_m && ($::timestamp{$revision} < $::opt_m_timestamp)) {
|
1998-06-17 01:43:24 +04:00
|
|
|
$annotation = $blank_annotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Suppress annotation of whitespace lines, if requested;
|
1999-10-19 02:55:01 +04:00
|
|
|
$annotation = $blank_annotation if $::opt_w && ($text =~ /^\s*$/);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
# printf "%4d ", $line if $::opt_l;
|
1998-06-17 01:43:24 +04:00
|
|
|
# print "$annotation - $text";
|
1999-10-19 02:55:01 +04:00
|
|
|
push(@output, sprintf("%4d ", $line)) if $::opt_l;
|
1998-06-17 01:43:24 +04:00
|
|
|
push(@output, "$annotation - $text");
|
|
|
|
}
|
|
|
|
@output;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
die
|
1999-10-19 02:55:01 +04:00
|
|
|
"$::progname: usage: [options] [file|dir]...\n",
|
1998-06-17 01:43:24 +04:00
|
|
|
" Options:\n",
|
|
|
|
" -r <revision> Specify CVS revision of file to display\n",
|
|
|
|
" <revision> can be any of:\n",
|
|
|
|
" + numeric tag, e.g. 1.23,\n",
|
|
|
|
" + symbolic branch or revision tag, e.g. CHEDDAR,\n",
|
|
|
|
" + HEAD keyword (most recent revision on trunk)\n",
|
|
|
|
" -a Annotate lines with author (username)\n",
|
|
|
|
" -A Annotate lines with age, in days\n",
|
|
|
|
" -v Annotate lines with revision number\n",
|
|
|
|
" -d Annotate lines with date, in local time zone\n",
|
|
|
|
" -l Annotate lines with line number\n",
|
|
|
|
" -w Don't annotate all-whitespace lines\n",
|
|
|
|
" -m <# days> Only annotate lines modified within last <# days>\n",
|
|
|
|
" -h Print help (this message)\n\n",
|
|
|
|
" (-a -v assumed, if none of -a, -v, -A, -d supplied)\n"
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
1999-10-19 02:55:01 +04:00
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
&usage if (!&Getopts('r:m:Aadhlvw'));
|
1999-10-19 02:55:01 +04:00
|
|
|
&usage if ($::opt_h); # help option
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
$multiple_files_on_command_line = 1 if ($#ARGV != 0);
|
|
|
|
|
|
|
|
&cvsblame_init;
|
|
|
|
|
|
|
|
sub annotate_cvs_directory
|
|
|
|
{
|
1999-07-08 20:16:47 +04:00
|
|
|
my ($dir) = @_;
|
1998-06-17 01:43:24 +04:00
|
|
|
&read_cvs_entries($dir);
|
|
|
|
foreach $file (split(/\\/, $cvs_files{$dir})) {
|
|
|
|
&show_annotated_cvs_file("$dir/$file");
|
|
|
|
}
|
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
|
1998-06-17 01:43:24 +04:00
|
|
|
# No files on command-line ? Use current directory.
|
|
|
|
push(@ARGV, '.') if ($#ARGV == -1);
|
|
|
|
|
|
|
|
# Iterate over files/directories on command-line
|
|
|
|
while ($#ARGV >= 0) {
|
|
|
|
$pathname = shift @ARGV;
|
|
|
|
# Is it a directory ?
|
|
|
|
if (-d $pathname) {
|
|
|
|
&traverse_cvs_tree($pathname, *annotate_cvs_directory);
|
|
|
|
|
|
|
|
# No, it must be a file.
|
|
|
|
} else {
|
|
|
|
&show_annotated_cvs_file($pathname);
|
|
|
|
}
|
|
|
|
}
|
1999-10-19 02:55:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
1;
|