annotate kdiff3/admin/cvs-clean.pl @ 60:4732f709a8cb

*** empty log message ***
author joachim99
date Sun, 07 Mar 2004 10:08:07 +0000
parents 415083d043f3
children efe33e938730
rev   line source
joachim99@14 1 #! /usr/bin/perl
joachim99@14 2
joachim99@14 3 #
joachim99@14 4 # This script recursively (beginning with the current directory)
joachim99@14 5 # wipes out everything not registered in CVS.
joachim99@14 6 #
joachim99@14 7 # written by Oswald Buddenhagen <ossi@kde.org>
joachim99@14 8 # inspired by the "old" cvs-clean target from Makefile.common
joachim99@14 9 #
joachim99@14 10 # This file is free software in terms of the BSD licence. That means
joachim99@14 11 # that you can do anything with it except removing this license or
joachim99@14 12 # the above copyright notice. There is NO WARRANTY of any kind.
joachim99@14 13 #
joachim99@14 14
joachim99@14 15 sub rmrf()
joachim99@14 16 {
joachim99@14 17 my $fn = shift;
joachim99@14 18 lstat ($fn);
joachim99@14 19 if (-d _) {
joachim99@14 20 if (opendir (DIR, $fn)) {
joachim99@14 21 for my $efn (grep (!/^\.\.?$/, readdir (DIR))) {
joachim99@14 22 &rmrf ($fn."/".$efn);
joachim99@14 23 }
joachim99@14 24 closedir (DIR);
joachim99@14 25 rmdir ($fn);
joachim99@14 26 }
joachim99@14 27 } else {
joachim99@14 28 unlink ($fn);
joachim99@14 29 }
joachim99@14 30 }
joachim99@14 31
joachim99@14 32 sub newfiles()
joachim99@14 33 {
joachim99@14 34 my ($indir, $incvs) = @_;
joachim99@14 35 for my $n (keys (%$incvs)) { delete $$indir{$n} }
joachim99@14 36 return sort (keys (%$indir));
joachim99@14 37 }
joachim99@14 38
joachim99@14 39 sub cvsclean()
joachim99@14 40 {
joachim99@14 41 my $dir = shift;
joachim99@14 42 my (%dirsdir, %filesdir, %dirscvs, %filescvs);
joachim99@14 43 my $dnam = $dir ? $dir : ".";
joachim99@14 44 if (!opendir (DIR, $dnam)) {
joachim99@14 45 print STDERR "Cannot enter \"".$dnam."\".\n";
joachim99@14 46 return;
joachim99@14 47 }
joachim99@14 48 for my $fn (grep (!/^\.\.?$/, readdir (DIR))) {
joachim99@14 49 if (-d $dir.$fn) {
joachim99@14 50 $fn eq "CVS" or $dirsdir{$fn} = 1;
joachim99@14 51 } else {
joachim99@14 52 $filesdir{$fn} = 1;
joachim99@14 53 }
joachim99@14 54 }
joachim99@14 55 closedir (DIR);
joachim99@14 56 if (!open (FILE, "<".$dir."CVS/Entries")) {
joachim99@14 57 print STDERR "No CVS information in \"".$dnam."\".\n";
joachim99@14 58 return;
joachim99@14 59 }
joachim99@14 60 while (<FILE>) {
joachim99@14 61 m%^D/([^/]+)/.*$% and $dirscvs{$1} = 1;
joachim99@14 62 m%^/([^/]+)/.*$% and $filescvs{$1} = 1;
joachim99@14 63 }
joachim99@14 64 close (FILE);
joachim99@14 65 if (open (FILE, "<".$dir."CVS/Entries.Log")) {
joachim99@14 66 while (<FILE>) {
joachim99@14 67 m%^A D/([^/]+)/.*$% and $dirscvs{$1} = 1;
joachim99@14 68 m%^A /([^/]+)/.*$% and $filescvs{$1} = 1;
joachim99@14 69 m%^R D/([^/]+)/.*$% and delete $dirscvs{$1};
joachim99@14 70 m%^R /([^/]+)/.*$% and delete $filescvs{$1};
joachim99@14 71 }
joachim99@14 72 close (FILE);
joachim99@14 73 }
joachim99@14 74 for my $fn (&newfiles (\%filesdir, \%filescvs)) {
joachim99@14 75 print ("F ".$dir.$fn."\n");
joachim99@14 76 &rmrf ($dir.$fn);
joachim99@14 77 }
joachim99@14 78 for my $fn (&newfiles (\%dirsdir, \%dirscvs)) {
joachim99@14 79 print ("D ".$dir.$fn."\n");
joachim99@14 80 &rmrf ($dir.$fn);
joachim99@14 81 }
joachim99@14 82 for my $fn (sort (keys (%dirscvs))) {
joachim99@14 83 &cvsclean ($dir.$fn."/");
joachim99@14 84 }
joachim99@14 85 }
joachim99@14 86
joachim99@14 87 &cvsclean ("");