| 1 |
tdb |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
# script to change an author in all files |
| 4 |
|
|
# in a cvs repository. Handy if a users |
| 5 |
|
|
# login changes. |
| 6 |
|
|
|
| 7 |
|
|
# tdb, 09/12/2001. |
| 8 |
|
|
|
| 9 |
|
|
# sample line to fix: |
| 10 |
|
|
#date 2000.10.08.21.13.25; author tdb1; state Exp; |
| 11 |
|
|
|
| 12 |
|
|
# cvsroot |
| 13 |
|
|
$cvsroot = "/usr/home/tdb/cvsup/i-scream"; |
| 14 |
|
|
|
| 15 |
|
|
# kick the recursion off |
| 16 |
|
|
&checkdir($cvsroot); |
| 17 |
|
|
|
| 18 |
|
|
# subroutine to check a directory, and recusively |
| 19 |
|
|
# call itself on all subdirectories. Also makes |
| 20 |
|
|
# appropriate changes to files as it finds them. |
| 21 |
|
|
sub checkdir() { |
| 22 |
|
|
my($dir) = @_; |
| 23 |
|
|
print "* checking $dir...\n"; |
| 24 |
|
|
# read current dir |
| 25 |
|
|
opendir(DIR, $dir); |
| 26 |
|
|
my(@contents) = readdir(DIR); |
| 27 |
|
|
closedir DIR; |
| 28 |
|
|
# look at each item |
| 29 |
|
|
foreach my $item (@contents) { |
| 30 |
|
|
# lets ignore . and .. :) |
| 31 |
tdb |
1.2 |
if($item =~ /^\.$/ || $item =~ /^\.\.$/) { |
| 32 |
tdb |
1.1 |
next; |
| 33 |
|
|
} |
| 34 |
|
|
# if it ends in ,v it's an RCS file! |
| 35 |
|
|
# ... and if it's a file, of course :) |
| 36 |
|
|
elsif($item =~ /,v$/ && -f "$dir/$item") { |
| 37 |
|
|
print "rcsfile: $item\n"; |
| 38 |
|
|
# keep a copy to read from |
| 39 |
|
|
print `cp $dir/$item $dir/$item.b4`; |
| 40 |
|
|
# cvs doesn't give us write access |
| 41 |
|
|
print `chmod u+w $dir/$item`; |
| 42 |
|
|
# open the original for reading |
| 43 |
|
|
open(OFILE, "$dir/$item.b4"); |
| 44 |
|
|
# and the new file (overwriting!) |
| 45 |
|
|
open(NFILE, ">$dir/$item") or die("can't write!"); |
| 46 |
|
|
while(<OFILE>) { |
| 47 |
|
|
# see if it's an author line.. |
| 48 |
|
|
if($_ =~ /^(date\s+\S+;\s+author\s+)(\S+)(;\s+state\s+\S+;)$/) { |
| 49 |
|
|
print " old author: $2\n"; |
| 50 |
|
|
# some hardcoded checking to see if we |
| 51 |
|
|
# should change the author |
| 52 |
|
|
if($2 eq "tdb1") { |
| 53 |
|
|
print " new author: tdb\n"; |
| 54 |
|
|
print NFILE $1 . "tdb" . $3; |
| 55 |
|
|
} |
| 56 |
|
|
elsif($2 eq "ajm4") { |
| 57 |
|
|
print " new author: ajm\n"; |
| 58 |
|
|
print NFILE $1 . "ajm" . $3; |
| 59 |
|
|
} |
| 60 |
|
|
# or just leave it alone |
| 61 |
|
|
else { |
| 62 |
|
|
print " unchanged\n"; |
| 63 |
|
|
print NFILE $_; |
| 64 |
|
|
} |
| 65 |
|
|
} |
| 66 |
|
|
# not an author line, just add to new file |
| 67 |
|
|
else { |
| 68 |
|
|
print NFILE $_; |
| 69 |
|
|
} |
| 70 |
|
|
} |
| 71 |
|
|
# close the files |
| 72 |
|
|
close OFILE; |
| 73 |
|
|
close NFILE; |
| 74 |
|
|
# get rid of that write we added :) |
| 75 |
|
|
print `chmod u-w $dir/$item`; |
| 76 |
|
|
# and get rid of our temporary file |
| 77 |
|
|
print `rm -f $dir/$item.b4`; |
| 78 |
|
|
} |
| 79 |
|
|
# recurse down the subdirectories |
| 80 |
|
|
elsif(-d "$dir/$item") { |
| 81 |
|
|
&checkdir("$dir/$item"); |
| 82 |
|
|
} |
| 83 |
|
|
} |
| 84 |
|
|
print "* finished $dir.\n"; |
| 85 |
|
|
} |