(isearch-yank-word-or-char): New function.
[bpt/emacs.git] / admin / revdiff
CommitLineData
30b50b5c
GM
1#! /usr/bin/perl
2
3# Copyright (C) 2001 Free Software Foundation, Inc.
4#
5# This file is part of GNU Emacs.
6#
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.
11#
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.
16#
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.
21
22use File::Basename;
23
24if (@ARGV < 3)
25{
26 print <<USAGE;
27revdiff FILE OLD NEW
28
29Get a diff of FILE between revisions OLD and NEW. Store the
13bc4e1a
GM
30diff in a file named FILE-OLD-NEW.diff.
31
32If OLD is `-' use FILE's current revision for OLD. If OLD is
33`-<number>', use the Nth revision before the current one for OLD.
34
35If NEW is +<number> or -<number>, build diffs between revisions OLD
36and OLD +/- <number>.
30b50b5c
GM
37
38Examples:
39
40revdiff FILE - -1 get the latest change of FILE
13bc4e1a 41revdiff FILE -1 +1 also gets the latest change of FILE
30b50b5c
GM
42revdiff FILE 1.500 +2 get diffs 1.500-1.501 and 1.501-1.502.
43
44USAGE
45 exit 1;
46}
47
48$file = shift @ARGV;
49$old = shift @ARGV;
50
51sub diffit
52{
53 my ($old, $new) = @_;
54 print "cvs diff -r$old -r$new $file >$file-$old-$new.diff\n";
55 system "cvs diff -r$old -r$new $file >$file-$old-$new.diff";
56}
57
58sub current_revision ($)
59{
60 my ($file) = @_;
61 my $dir = dirname ($file);
62 my $base = basename ($file);
63 my $entries = "$dir/CVS/Entries";
64 die "Can't find $entries" unless -f $entries;
65 open (IN, "<$entries") or die "Cannot open $entries";
66 my $rev;
67 while ($line = <IN>)
68 {
69 if ($line =~ m,/$base/([^/]+),)
70 {
71 $rev = $1;
72 break;
73 }
74 }
75 die "Cannot determine current revision of $file" unless $rev;
76 close (IN);
77 return $rev;
78}
79
80if ($old eq "-")
13bc4e1a
GM
81 {
82 $old = current_revision ($file);
83 }
84elsif ($old =~ /^-(\d+)$/)
85 {
86 my $offset = $1;
87 $old = current_revision ($file);
88 die "Internal error" unless $old =~ /(.*)\.(\d+)$/;
89 my $minor = $2 - $offset;
90 $old = sprintf ("%d.%d", $1, $minor);
91 }
30b50b5c
GM
92
93while (@ARGV)
94 {
95 my $new = shift @ARGV;
96 if ($new =~ /^[+]\d+$/)
97 {
98 my $n = $new;
99 for ($i = 0; $i < $n; ++$i)
100 {
101 unless ($old =~ /(.*)\.(\d+)$/)
102 {
103 die "Internal error";
104 }
105 my $j = $2 + 1;
106 $new = "$1.$j";
107 diffit ($old, $new);
108 $old = $new;
109 }
110 }
111 elsif ($new =~ /^[-]\d+$/)
112 {
113 my $n = - $new;
114 for ($i = 0; $i < $n; ++$i)
115 {
116 unless ($old =~ /(.*)\.(\d+)$/)
117 {
118 die "Internal error";
119 }
120 my $j = $2 - 1;
121 $new = "$1.$j";
122 diffit ($new, $old);
123 $old = $new;
124 }
125 }
126 else
127 {
128 diffit ($old, $new);
129 $old = $new;
130 }
131 }
132
133# Local Variables:
134# mode: cperl
135# End: