6 # alias cvsfiles='cvsutil --files --print'
7 # alias cvsignores='cvsutil --ignores --print'
8 # alias cvsignoresall='cvsutil --ignores --workings --print'
9 # alias cvsignoresrm='cvsutil --ignores --rm'
10 # alias cvsignoresrmall='cvsutil --ignores --workings --rm'
11 # alias cvsignoresallrm='cvsutil --ignores --workings --rm'
17 use Cwd qw(chdir fastgetcwd);
19 use File::Remove qw(remove);
21 use constant ENTRIES =>"CVS/Entries";
22 use constant CVSIGNORE=>".cvsignore";
23 use constant ROOT =>"CVS/Root";
25 my($opt_files,$opt_ignores,$opt_workings,$opt_dirs);
26 my($opt_rm,$opt_print);
27 our($opt_root); # undefined=>no rooting, ""=>print roots or first phase for root checking, ne ""=>set roots
28 my($opt_verbose,$opt_fatal);
29 my($opt_force); # set roots without their checking
32 $Getopt::Long::ignorecase=0;
33 $Getopt::Long::bundling=1;
34 die if !GetOptions_shortfilter(
35 "f|files!" ,\$opt_files,
36 "i|ignores!" ,\$opt_ignores,
37 "w|workings!",\$opt_workings,
38 "d|dirs!" ,\$opt_dirs,
40 "p|print!" ,\$opt_print,
42 "v|verbose!" ,\$opt_verbose,
43 "fatal!" ,\$opt_fatal,
44 "force!" ,\$opt_force,
45 "I|ignore=s" ,\@opt_ignore,
48 die "--root possible only with (optional and ignored) -d|--dirs"
49 if defined $opt_root && ($opt_files || $opt_ignores || $opt_workings || $opt_dirs || $opt_rm || $opt_print);
50 die "-d|--dirs forbidden with -r|--rm"
51 if $opt_dirs && $opt_rm;
52 die "Nothing to do (no -r|--rm, no -p|--print)"
53 if !$opt_rm && !$opt_print && !defined $opt_root;
54 die "Nothing to process (no -f|--files, no -i|--ignores, no -w|--workings, no -d|--dirs)"
55 if !defined $opt_root && (!$opt_files && !$opt_ignores && !$opt_workings && !$opt_dirs);
57 my @all_ignore=("CVS");
60 @all_ignore=() if $_ eq "!";
63 my($root_contents,@root_dirs);
65 @ARGV=(".") if !@ARGV;
67 our(@dir_files,@dir_ignores,@dir_workings,@dir_victims);
69 unless ((defined $opt_root && $opt_root ne "") && $opt_force) {
70 local($opt_root)=$opt_root;
71 $opt_root="" if defined $opt_root && $opt_root ne "";
75 actionrootfinal() if defined $opt_root && $opt_root eq "";
76 if (defined $opt_root && $opt_root ne "") {
77 die "Non-matching \"".ROOT."\" contents, use --force for override" if !@root_dirs && !$opt_force;
88 $msg.=" in \"".fastgetcwd."\" (CVS \"$dir_dirname\")".($opts{"noerrno"} ? "" : ": $errstr");
89 die $msg if $opt_fatal;
97 my $origdir=fastgetcwd;
100 mayfatal "Unable to process directory \"$_\"";
110 my($localdirname)=@_;
112 verbose("localdir(\"$localdirname\") entry");
114 local(@dir_dirs,@dir_files,@dir_ignores,@dir_workings,@dir_victims);
115 local($dir_dirname)=$dir_dirname.$localdirname."/";
117 localreaddir() or return;
121 verbose("localdir(\"$localdirname\") exit");
126 localvictims() if !defined $opt_root;
129 fordirs \&localdir,@dir_dirs;
136 my %hash=map { $_=>1; } @$from;
146 if (!open E,ENTRIES) {
147 mayfatal "File \"".ENTRIES."\" cannot be opened";
152 do { push @dir_dirs ,$1; next; } if m#^D/([^/]*)/#;
153 do { push @dir_files,$1; next; } if m#^/([^/]*)/# ;
155 mayfatal "File ".ENTRIES." contains invalid line \"$_\"",("noerrno"=>1);
159 return 1 if defined $opt_root;
162 if (open I,CVSIGNORE) {
166 push @dir_ignores,$_ if -e $_;
171 @dir_ignores=filterout \@dir_ignores,@dir_dirs,@dir_files;
174 mayfatal "File \"".CVSIGNORE."\" cannot be opened" if !$!{ENOENT};
178 if (!opendir D,".") {
179 mayfatal "Cannot read directory \".\"";
182 @dir_workings=filterout [readdir D],@dir_dirs,@dir_files,@dir_ignores,@all_ignore,".","..";
189 push @dir_victims,@dir_files if $opt_files;
190 push @dir_victims,@dir_ignores if $opt_ignores;
191 push @dir_victims,@dir_workings if $opt_workings;
192 push @dir_victims,@dir_dirs if $opt_dirs;
199 mayfatal "File \"$filename\" does not exist",("noerrno"=>1) if !-e $filename;
200 print "${dir_dirname}$filename\n";
208 if (!remove \1,$filename) {
209 mayfatal "File \"$_\" cannot be removed" if !$!{ENOENT};
213 sub localactionrootset
216 if (!open R,'+<',ROOT) {
217 mayfatal "File \"".ROOT."\" cannot be written";
220 print R "$opt_root\n";
225 sub localactionrootprint
229 mayfatal "File \"".ROOT."\" cannot be opened";
233 localactionrootprintcheck(<R>);
237 sub localactionrootprintcheck
241 if (!defined $root_contents) {
242 push @root_dirs,$dir_dirname;
243 $root_contents=$contents;
246 if (@root_dirs && $root_contents eq $contents) {
247 push @root_dirs,$dir_dirname;
251 print map "$_: $root_contents",@root_dirs;
254 print "$dir_dirname: $contents";
259 return if !@root_dirs;
260 print $root_contents;
265 if ("" ne $dir_dirname && defined $opt_root) {
266 localactionrootset() if defined $opt_root && "" ne $opt_root;
267 localactionrootprint() if defined $opt_root && "" eq $opt_root;
271 localactionprint $_ if $opt_print;
272 localactionrm $_ if $opt_rm;
280 return if !$opt_verbose;
281 print fastgetcwd.": $msg\n";
284 sub GetOptions_shortfilter
290 push @r,$1,$ref,$',$ref;
295 return GetOptions @r;