summaryrefslogtreecommitdiffstats
path: root/scripts/cvslastreferenced
blob: 666a5b6d7b4e75dd49636fc2456c8dc09bfccada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl -w
# Written by Zack Rusin <zack@kde.org>
#
# This file is free software, licensed under the BSD licence. 
# That means that you can do anything you want with it except 
# eating too much candy since that totally messes up your teeth
# and here in KDE land we care about your teeth. They're out 
# greatest priority right next to scoring chicks of course...
#

# This script goes through the whole history of a file to find 
# all modifications referencing specific string. It's useful if
# you want to know when a function has been removed/modified/added
# to a file if a recent cvs annotate doesn't anymore reference it.

our $file;
our $func;

sub check_file
{
  my $rev1 = shift;
  my $rev2 = shift;

  my $output = `cvs diff -r $rev1 -r $rev2 $file`;

  if ( $output =~ /(^[+-].+$func.+$)/m ) {
    print "FOUND IN: cvs diff -r $rev1 -r $rev2 $file\n";
    $_ = $1;
    s/^([-+])\s*(.+)/$1 $2/;
    return $_;
  }
  return 0;
}

sub get_revision
{
  my $output = `cvsversion $file`;
  chomp $output;
  return $output;
}

my $argc = scalar @ARGV;

die "$0 <function> <file>" if ( $argc != 2 );
$func = $ARGV[0];
$file = $ARGV[1];

my $current_revision = get_revision( $file );

$current_revision =~ /(\d+)\.(\d+)/;
$base = $1;
$working = $2;

while ( $working > 1 ) {
  my $older = $working - 1;
  my $res = check_file( "$base.$older", "$base.$working");
  
  if ( $res ) {
    print "\t($res)\n";
  }
  --$working;
}

print "Didn't find a reference to that $func in $file\n";