Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / debian / cvs-clean.pl
blob669dbdc65444a72f25f7bfd5cc1fd33235a84cd4
1 #! /usr/bin/perl
4 # This script recursively (beginning with the current directory)
5 # wipes out everything not registered in CVS.
7 # written by Oswald Buddenhagen <ossi@kde.org>
8 # inspired by the "old" cvs-clean target from Makefile.common
10 # This file is free software in terms of the BSD licence. That means
11 # that you can do anything with it except removing this license or
12 # the above copyright notice. There is NO WARRANTY of any kind.
15 sub rmrf()
17 my $fn = shift;
18 lstat ($fn);
19 if (-d _) {
20 if (opendir (DIR, $fn)) {
21 for my $efn (grep (!/^\.\.?$/, readdir (DIR))) {
22 &rmrf ($fn."/".$efn);
24 closedir (DIR);
25 rmdir ($fn);
27 } else {
28 unlink ($fn);
32 sub newfiles()
34 my ($indir, $incvs) = @_;
35 for my $n (keys (%$incvs)) { delete $$indir{$n} }
36 return sort (keys (%$indir));
39 sub cvsclean()
41 my $dir = shift;
42 my (%dirsdir, %filesdir, %dirscvs, %filescvs);
43 my $dnam = $dir ? $dir : ".";
44 if (!opendir (DIR, $dnam)) {
45 print STDERR "Cannot enter \"".$dnam."\".\n";
46 return;
48 for my $fn (grep (!/^\.\.?$/, readdir (DIR))) {
49 if (-d $dir.$fn) {
50 $fn eq "CVS" or $dirsdir{$fn} = 1;
51 } else {
52 $filesdir{$fn} = 1;
55 closedir (DIR);
56 if (!open (FILE, "<".$dir."CVS/Entries")) {
57 print STDERR "No CVS information in \"".$dnam."\".\n";
58 return;
60 while (<FILE>) {
61 m%^D/([^/]+)/.*$% and $dirscvs{$1} = 1;
62 m%^/([^/]+)/.*$% and $filescvs{$1} = 1;
64 close (FILE);
65 if (open (FILE, "<".$dir."CVS/Entries.Log")) {
66 while (<FILE>) {
67 m%^A D/([^/]+)/.*$% and $dirscvs{$1} = 1;
68 m%^A /([^/]+)/.*$% and $filescvs{$1} = 1;
69 m%^R D/([^/]+)/.*$% and delete $dirscvs{$1};
70 m%^R /([^/]+)/.*$% and delete $filescvs{$1};
72 close (FILE);
74 for my $fn (&newfiles (\%filesdir, \%filescvs)) {
75 print ("F ".$dir.$fn."\n");
76 &rmrf ($dir.$fn);
78 for my $fn (&newfiles (\%dirsdir, \%dirscvs)) {
79 print ("D ".$dir.$fn."\n");
80 &rmrf ($dir.$fn);
82 for my $fn (sort (keys (%dirscvs))) {
83 &cvsclean ($dir.$fn."/");
87 &cvsclean ("");