File: cvs-clean.pl

package info (click to toggle)
filelight 0.99beta6-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,604 kB
  • ctags: 662
  • sloc: sh: 8,992; cpp: 3,775; perl: 2,724; makefile: 104; ansic: 9
file content (87 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (249)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /usr/bin/perl

#
# This script recursively (beginning with the current directory)
# wipes out everything not registered in CVS.
#
# written by Oswald Buddenhagen <ossi@kde.org>
#  inspired by the "old" cvs-clean target from Makefile.common
#
# This file is free software in terms of the BSD license. That means
# that you can do anything with it except removing this license or
# the above copyright notice. There is NO WARRANTY of any kind.
#

sub rmrf()
{
  my $fn = shift;
  lstat ($fn);
  if (-d _) {
    if (opendir (DIR, $fn)) {
      for my $efn (grep (!/^\.\.?$/, readdir (DIR))) {
	&rmrf ($fn."/".$efn);
      }
      closedir (DIR);
      rmdir ($fn);
    }
  } else {
    unlink ($fn);
  }
}

sub newfiles()
{
  my ($indir, $incvs) = @_;
  for my $n (keys (%$incvs)) { delete $$indir{$n} }
  return sort (keys (%$indir));
}

sub cvsclean()
{
  my $dir = shift;
  my (%dirsdir, %filesdir, %dirscvs, %filescvs);
  my $dnam = $dir ? $dir : ".";
  if (!opendir (DIR, $dnam)) {
    print STDERR "Cannot enter \"".$dnam."\".\n";
    return;
  }
  for my $fn (grep (!/^\.\.?$/, readdir (DIR))) {
    if (-d $dir.$fn) {
      $fn eq "CVS" or $dirsdir{$fn} = 1;
    } else {
      $filesdir{$fn} = 1;
    }
  }
  closedir (DIR);
  if (!open (FILE, "<".$dir."CVS/Entries")) {
    print STDERR "No CVS information in \"".$dnam."\".\n";
    return;
  }
  while (<FILE>) {
    m%^D/([^/]+)/.*$% and $dirscvs{$1} = 1;
    m%^/([^/]+)/.*$% and $filescvs{$1} = 1;
  }
  close (FILE);
  if (open (FILE, "<".$dir."CVS/Entries.Log")) {
    while (<FILE>) {
      m%^A D/([^/]+)/.*$% and $dirscvs{$1} = 1;
      m%^A /([^/]+)/.*$% and $filescvs{$1} = 1;
      m%^R D/([^/]+)/.*$% and delete $dirscvs{$1};
      m%^R /([^/]+)/.*$% and delete $filescvs{$1};
    }
    close (FILE);
  }
  for my $fn (&newfiles (\%filesdir, \%filescvs)) {
    print ("F ".$dir.$fn."\n");
    &rmrf ($dir.$fn);
  }
  for my $fn (&newfiles (\%dirsdir, \%dirscvs)) {
    print ("D ".$dir.$fn."\n");
    &rmrf ($dir.$fn);
  }
  for my $fn (sort (keys (%dirscvs))) {
    &cvsclean ($dir.$fn."/");
  }
}

&cvsclean ("");