sync 3.0 into HEAD for the last time
[kai/samba.git] / source3 / script / cvslog.pl
1 #!/usr/bin/perl -w
2
3 my ( $tag, $filename, $date );
4 my ( $tmp, $change_flag );
5
6 if ( $#ARGV != 2 ) {
7
8         print "Usage: ", $0, " cvstag date file\n";
9         exit 1;
10 }
11
12 $tag      = $ARGV[0];
13 $date     = $ARGV[1];
14 $filename = $ARGV[2];
15
16 print STDERR "$filename\n";
17
18 open ( CVSLOG, "cvs log -d\"$date\" $filename |" ) || die $!;
19
20 ##
21 ## First get the branch revision number
22 ##
23 undef $revision;
24 while ( !defined($revision) ) {
25         if ( eof( \*CVSLOG ) ) {
26                 print STDERR "Premature end of cvs log output!\n";
27                 exit (1);
28         }
29
30         $string = <CVSLOG>;
31         chomp( $string );
32
33         if ( $string =~ /$tag:/ ) {
34                 ( $tmp, $revision ) = split( /:/, $string );
35                 $revision =~ s/\s+//g;
36                 $revision =~ s/\.0\./\./g;
37         }
38 }
39
40 ##
41 ## Setup the beginning of the first record
42 ##
43 $string = "";
44 while ( $string !~ /^-+/ ) {
45         $string = <CVSLOG>;
46         exit(0) if ( eof(\*CVSLOG) );
47 }
48
49 ##
50 ## Loop starting at the revision number for the entry
51 ##
52
53 while ( $string = <CVSLOG> ) {
54
55         ($tmp, $entry_rev) = split( /\s+/, $string );
56         if ( equal_revision( $revision, $entry_rev ) ) {
57                 if ( ! defined($change_flag) ) {
58                         print "++++++++++++++++++++++++++++++++++++++++++++++++++\n";
59                         print "## $filename\n";
60                         print "++\n";
61                         $change_flag = 1;
62                 }
63
64                 while ( $string !~ /^-+/ && !eof(CVSLOG) ) {
65                         print "$string";
66                         $string = <CVSLOG>;
67                 }
68         }
69         else {
70                 while ( ($string !~ /^-+/) && !eof(CVSLOG) ) {
71                         $string = <CVSLOG>; 
72                 }
73         }
74 }
75
76 close( CVSLOG );
77 exit 0;
78
79 ##############################################################
80 ##
81 sub equal_revision {
82         my ( $branch, $newfile ) = @_;
83         my ( $indx );
84         my ( @branch_rev, @file_rev );
85
86         @branch_rev = split( /\./, $branch );
87         @file_rev = split( /\./, $newfile );
88
89         return 0 if ( $#branch_rev != ($#file_rev - 1) );
90
91         $indx = 0;
92         while( $indx <= $#branch_rev ) {
93                 if ( $branch_rev[$indx] != $file_rev[$indx] ) {
94                         return 0;
95                 }
96                 $indx++;
97         }
98
99         return 1;
100 }
101
102