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);
20 use constant ENTRIES =>"CVS/Entries";
21 use constant CVSIGNORE=>".cvsignore";
22 use constant ROOT =>"CVS/Root";
24 my($opt_files,$opt_ignores,$opt_workings,$opt_dirs);
25 my($opt_rm,$opt_print);
26 our($opt_root); # undefined=>no rooting, ""=>print roots or first phase for root checking, ne ""=>set roots
27 my($opt_verbose,$opt_fatal);
28 my($opt_force); # set roots without their checking
31 $Getopt::Long::ignorecase=0;
32 $Getopt::Long::bundling=1;
33 die if !GetOptions_shortfilter(
34 "f|files!" ,\$opt_files,
35 "i|ignores!" ,\$opt_ignores,
36 "w|workings!",\$opt_workings,
37 "d|dirs!" ,\$opt_dirs,
39 "p|print!" ,\$opt_print,
41 "v|verbose!" ,\$opt_verbose,
42 "fatal!" ,\$opt_fatal,
43 "force!" ,\$opt_force,
44 "I|ignore=s" ,\@opt_ignore,
47 die "--root possible only with (optional and ignored) -d|--dirs"
48 if defined $opt_root && ($opt_files || $opt_ignores || $opt_workings || $opt_dirs || $opt_rm || $opt_print);
49 die "-d|--dirs forbidden with -r|--rm"
50 if $opt_dirs && $opt_rm;
51 die "Nothing to do (no -r|--rm, no -p|--print)"
52 if !$opt_rm && !$opt_print && !defined $opt_root;
53 die "Nothing to process (no -f|--files, no -i|--ignores, no -w|--workings, no -d|--dirs)"
54 if !defined $opt_root && (!$opt_files && !$opt_ignores && !$opt_workings && !$opt_dirs);
56 my @all_ignore=("CVS");
59 @all_ignore=() if $_ eq "!";
62 my($root_contents,@root_dirs);
64 @ARGV=(".") if !@ARGV;
66 our(@dir_files,@dir_ignores,@dir_workings,@dir_victims);
68 unless ((defined $opt_root && $opt_root ne "") && $opt_force) {
69 local($opt_root)=$opt_root;
70 $opt_root="" if defined $opt_root && $opt_root ne "";
74 actionrootfinal() if defined $opt_root && $opt_root eq "";
75 if (defined $opt_root && $opt_root ne "") {
76 die "Non-matching \"".ROOT."\" contents, use --force for override" if !@root_dirs && !$opt_force;
87 $msg.=" in \"".fastgetcwd."\" (CVS \"$dir_dirname\")".($opts{"noerrno"} ? "" : ": $errstr");
88 die $msg if $opt_fatal;
96 my $origdir=fastgetcwd;
99 mayfatal "Unable to process directory \"$_\"";
109 my($localdirname)=@_;
111 verbose("localdir(\"$localdirname\") entry");
113 local(@dir_dirs,@dir_files,@dir_ignores,@dir_workings,@dir_victims);
114 local($dir_dirname)=$dir_dirname.$localdirname."/";
116 localreaddir() or return;
120 verbose("localdir(\"$localdirname\") exit");
125 localvictims() if !defined $opt_root;
128 fordirs \&localdir,@dir_dirs;
135 my %hash=map { $_=>1; } @$from;
145 if (!open E,ENTRIES) {
146 mayfatal "File \"".ENTRIES."\" cannot be opened";
151 do { push @dir_dirs ,$1; next; } if m#^D/([^/]*)/#;
152 do { push @dir_files,$1; next; } if m#^/([^/]*)/# ;
154 mayfatal "File ".ENTRIES." contains invalid line \"$_\"",("noerrno"=>1);
158 return 1 if defined $opt_root;
161 if (open I,CVSIGNORE) {
165 push @dir_ignores,$_ if -e $_;
170 @dir_ignores=filterout \@dir_ignores,@dir_dirs,@dir_files;
173 mayfatal "File \"".CVSIGNORE."\" cannot be opened" if !$!{ENOENT};
177 if (!opendir D,".") {
178 mayfatal "Cannot read directory \".\"";
181 @dir_workings=filterout [readdir D],@dir_dirs,@dir_files,@dir_ignores,@all_ignore,".","..";
188 push @dir_victims,@dir_files if $opt_files;
189 push @dir_victims,@dir_ignores if $opt_ignores;
190 push @dir_victims,@dir_workings if $opt_workings;
191 push @dir_victims,@dir_dirs if $opt_dirs;
198 mayfatal "File \"$filename\" does not exist",("noerrno"=>1) if !-e $filename;
199 print "${dir_dirname}$filename\n";
206 if (!unlink $filename) {
207 mayfatal "File \"$_\" cannot be removed" if !$!{ENOENT};
211 sub localactionrootset
214 if (!open R,'+<',ROOT) {
215 mayfatal "File \"".ROOT."\" cannot be written";
218 print R "$opt_root\n";
223 sub localactionrootprint
227 mayfatal "File \"".ROOT."\" cannot be opened";
231 localactionrootprintcheck(<R>);
235 sub localactionrootprintcheck
239 if (!defined $root_contents) {
240 push @root_dirs,$dir_dirname;
241 $root_contents=$contents;
244 if (@root_dirs && $root_contents eq $contents) {
245 push @root_dirs,$dir_dirname;
249 print map "$_: $root_contents",@root_dirs;
252 print "$dir_dirname: $contents";
257 return if !@root_dirs;
258 print $root_contents;
263 if ("" ne $dir_dirname && defined $opt_root) {
264 localactionrootset() if defined $opt_root && "" ne $opt_root;
265 localactionrootprint() if defined $opt_root && "" eq $opt_root;
269 localactionprint $_ if $opt_print;
270 localactionrm $_ if $opt_rm;
278 return if !$opt_verbose;
279 print fastgetcwd.": $msg\n";
282 sub GetOptions_shortfilter
288 push @r,$1,$ref,$',$ref;
293 return GetOptions @r;