| 1 |
#! /usr/bin/perl |
|---|
| 2 |
|
|---|
| 3 |
# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
|---|
| 4 |
# Free Software Foundation, Inc. |
|---|
| 5 |
# |
|---|
| 6 |
# This file is part of GNU Emacs. |
|---|
| 7 |
# |
|---|
| 8 |
# GNU Emacs is free software; you can redistribute it and/or modify |
|---|
| 9 |
# it under the terms of the GNU General Public License as published by |
|---|
| 10 |
# the Free Software Foundation; either version 3, or (at your option) |
|---|
| 11 |
# any later version. |
|---|
| 12 |
# |
|---|
| 13 |
# GNU Emacs is distributed in the hope that it will be useful, |
|---|
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 |
# GNU General Public License for more details. |
|---|
| 17 |
# |
|---|
| 18 |
# You should have received a copy of the GNU General Public License |
|---|
| 19 |
# along with GNU Emacs; see the file COPYING. If not, write to the |
|---|
| 20 |
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|---|
| 21 |
# Boston, MA 02110-1301, USA. |
|---|
| 22 |
|
|---|
| 23 |
use File::Basename; |
|---|
| 24 |
|
|---|
| 25 |
if (@ARGV < 3) |
|---|
| 26 |
{ |
|---|
| 27 |
print <<USAGE; |
|---|
| 28 |
revdiff FILE OLD NEW |
|---|
| 29 |
|
|---|
| 30 |
Get a diff of FILE between revisions OLD and NEW. Store the |
|---|
| 31 |
diff in a file named FILE-OLD-NEW.diff. |
|---|
| 32 |
|
|---|
| 33 |
If OLD is `-' use FILE's current revision for OLD. If OLD is |
|---|
| 34 |
`-<number>', use the Nth revision before the current one for OLD. |
|---|
| 35 |
|
|---|
| 36 |
If NEW is +<number> or -<number>, build diffs between revisions OLD |
|---|
| 37 |
and OLD +/- <number>. |
|---|
| 38 |
|
|---|
| 39 |
Examples: |
|---|
| 40 |
|
|---|
| 41 |
revdiff FILE - -1 get the latest change of FILE |
|---|
| 42 |
revdiff FILE -1 +1 also gets the latest change of FILE |
|---|
| 43 |
revdiff FILE 1.500 +2 get diffs 1.500-1.501 and 1.501-1.502. |
|---|
| 44 |
|
|---|
| 45 |
USAGE |
|---|
| 46 |
exit 1; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
$file = shift @ARGV; |
|---|
| 50 |
$old = shift @ARGV; |
|---|
| 51 |
|
|---|
| 52 |
sub diffit |
|---|
| 53 |
{ |
|---|
| 54 |
my ($old, $new) = @_; |
|---|
| 55 |
print "cvs diff -r$old -r$new $file >$file-$old-$new.diff\n"; |
|---|
| 56 |
system "cvs diff -r$old -r$new $file >$file-$old-$new.diff"; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
sub current_revision ($) |
|---|
| 60 |
{ |
|---|
| 61 |
my ($file) = @_; |
|---|
| 62 |
my $dir = dirname ($file); |
|---|
| 63 |
my $base = basename ($file); |
|---|
| 64 |
my $entries = "$dir/CVS/Entries"; |
|---|
| 65 |
die "Can't find $entries" unless -f $entries; |
|---|
| 66 |
open (IN, "<$entries") or die "Cannot open $entries"; |
|---|
| 67 |
my $rev; |
|---|
| 68 |
while ($line = <IN>) |
|---|
| 69 |
{ |
|---|
| 70 |
if ($line =~ m,/$base/([^/]+),) |
|---|
| 71 |
{ |
|---|
| 72 |
$rev = $1; |
|---|
| 73 |
break; |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
die "Cannot determine current revision of $file" unless $rev; |
|---|
| 77 |
close (IN); |
|---|
| 78 |
return $rev; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
if ($old eq "-") |
|---|
| 82 |
{ |
|---|
| 83 |
$old = current_revision ($file); |
|---|
| 84 |
} |
|---|
| 85 |
elsif ($old =~ /^-(\d+)$/) |
|---|
| 86 |
{ |
|---|
| 87 |
my $offset = $1; |
|---|
| 88 |
$old = current_revision ($file); |
|---|
| 89 |
die "Internal error" unless $old =~ /(.*)\.(\d+)$/; |
|---|
| 90 |
my $minor = $2 - $offset; |
|---|
| 91 |
$old = sprintf ("%d.%d", $1, $minor); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
while (@ARGV) |
|---|
| 95 |
{ |
|---|
| 96 |
my $new = shift @ARGV; |
|---|
| 97 |
if ($new =~ /^[+]\d+$/) |
|---|
| 98 |
{ |
|---|
| 99 |
my $n = $new; |
|---|
| 100 |
for ($i = 0; $i < $n; ++$i) |
|---|
| 101 |
{ |
|---|
| 102 |
unless ($old =~ /(.*)\.(\d+)$/) |
|---|
| 103 |
{ |
|---|
| 104 |
die "Internal error"; |
|---|
| 105 |
} |
|---|
| 106 |
my $j = $2 + 1; |
|---|
| 107 |
$new = "$1.$j"; |
|---|
| 108 |
diffit ($old, $new); |
|---|
| 109 |
$old = $new; |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
elsif ($new =~ /^[-]\d+$/) |
|---|
| 113 |
{ |
|---|
| 114 |
my $n = - $new; |
|---|
| 115 |
for ($i = 0; $i < $n; ++$i) |
|---|
| 116 |
{ |
|---|
| 117 |
unless ($old =~ /(.*)\.(\d+)$/) |
|---|
| 118 |
{ |
|---|
| 119 |
die "Internal error"; |
|---|
| 120 |
} |
|---|
| 121 |
my $j = $2 - 1; |
|---|
| 122 |
$new = "$1.$j"; |
|---|
| 123 |
diffit ($new, $old); |
|---|
| 124 |
$old = $new; |
|---|
| 125 |
} |
|---|
| 126 |
} |
|---|
| 127 |
else |
|---|
| 128 |
{ |
|---|
| 129 |
diffit ($old, $new); |
|---|
| 130 |
$old = $new; |
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
# Local Variables: |
|---|
| 135 |
# mode: cperl |
|---|
| 136 |
# End: |
|---|
| 137 |
|
|---|
| 138 |
# arch-tag: 2798b20d-c7f2-4c78-8378-7bb529c36a09 |
|---|