*** empty log message ***
[emacs.git] / admin / revdiff
blobbdd6a2210ce5deb1e7cde53c5a63215322be9fa7
1 #! /usr/bin/perl
3 # Copyright (C) 2001 Free Software Foundation, Inc.
5 # This file is part of GNU Emacs.
7 # GNU Emacs is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # GNU Emacs is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Emacs; see the file COPYING. If not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
22 use File::Basename;
24 if (@ARGV < 3)
26 print <<USAGE;
27 revdiff FILE OLD NEW
29 Get a diff of FILE between revisions OLD and NEW. Store the
30 diff in a file named FILE-OLD-NEW.diff. If NEW is +<number>
31 or -<number>, build diffs between revisions OLD and OLD +/- <number>.
32 OLD being `-' means use FILE's current revision.
34 Examples:
36 revdiff FILE - -1 get the latest change of FILE
37 revdiff FILE 1.500 +2 get diffs 1.500-1.501 and 1.501-1.502.
39 USAGE
40 exit 1;
43 $file = shift @ARGV;
44 $old = shift @ARGV;
46 sub diffit
48 my ($old, $new) = @_;
49 print "cvs diff -r$old -r$new $file >$file-$old-$new.diff\n";
50 system "cvs diff -r$old -r$new $file >$file-$old-$new.diff";
53 sub current_revision ($)
55 my ($file) = @_;
56 my $dir = dirname ($file);
57 my $base = basename ($file);
58 my $entries = "$dir/CVS/Entries";
59 die "Can't find $entries" unless -f $entries;
60 open (IN, "<$entries") or die "Cannot open $entries";
61 my $rev;
62 while ($line = <IN>)
64 if ($line =~ m,/$base/([^/]+),)
66 $rev = $1;
67 break;
70 die "Cannot determine current revision of $file" unless $rev;
71 close (IN);
72 return $rev;
75 if ($old eq "-")
77 $old = current_revision ($file);
80 while (@ARGV)
82 my $new = shift @ARGV;
83 if ($new =~ /^[+]\d+$/)
85 my $n = $new;
86 for ($i = 0; $i < $n; ++$i)
88 unless ($old =~ /(.*)\.(\d+)$/)
90 die "Internal error";
92 my $j = $2 + 1;
93 $new = "$1.$j";
94 diffit ($old, $new);
95 $old = $new;
98 elsif ($new =~ /^[-]\d+$/)
100 my $n = - $new;
101 for ($i = 0; $i < $n; ++$i)
103 unless ($old =~ /(.*)\.(\d+)$/)
105 die "Internal error";
107 my $j = $2 - 1;
108 $new = "$1.$j";
109 diffit ($new, $old);
110 $old = $new;
113 else
115 diffit ($old, $new);
116 $old = $new;
120 # Local Variables:
121 # mode: cperl
122 # End: