+cvs.isdn4linux.de
[nethome.git] / bin / cvsutil
index 27a4ab5..0ebe138 100755 (executable)
@@ -1,4 +1,14 @@
 #! /usr/bin/perl
+#
+#      $Id$
+#
+#      Recommended aliases:
+#              alias cvsfiles='cvsutil --files --print'
+#              alias cvsignores='cvsutil --ignores --print'
+#              alias cvsignoresall='cvsutil --ignores --workings --print'
+#              alias cvsignoresrm='cvsutil --ignores --rm'
+#              alias cvsignoresrmall='cvsutil --ignores --workings --rm'
+#              alias cvsignoresallrm='cvsutil --ignores --workings --rm'
 
 use strict;
 use warnings;
@@ -6,6 +16,7 @@ use warnings;
 use Getopt::Long;
 use Cwd qw(chdir fastgetcwd);
 use Errno qw(ENOENT);
+use File::Remove qw(remove);
 
 use constant ENTRIES  =>"CVS/Entries";
 use constant CVSIGNORE=>".cvsignore";
@@ -118,6 +129,17 @@ sub localdircore
        fordirs \&localdir,@dir_dirs;
 }
 
+sub filterout
+{
+my($from,@what)=@_;
+
+       my %hash=map { $_=>1; } @$from;
+       for (@what) {
+               delete $hash{$_};
+               }
+       return keys %hash;
+}
+
 sub localreaddir
 {
        local *E;
@@ -146,6 +168,7 @@ sub localreaddir
                                }
                        }
                close I;
+               @dir_ignores=filterout \@dir_ignores,@dir_dirs,@dir_files;
                }
        else {
                mayfatal "File \"".CVSIGNORE."\" cannot be opened" if !$!{ENOENT};
@@ -156,13 +179,8 @@ sub localreaddir
                mayfatal "Cannot read directory \".\"";
                return 0;
                }
-       @dir_workings=readdir D;
+       @dir_workings=filterout [readdir D],@dir_dirs,@dir_files,@dir_ignores,@all_ignore,".","..";
        closedir D;
-       my %delworkings=map { $_=>1; } @dir_workings;
-       for (@dir_dirs,@dir_files,@dir_ignores,@all_ignore,".","..") {
-               delete $delworkings{$_};
-               }
-       @dir_workings=keys %delworkings;
        return 1;
 }
 
@@ -186,7 +204,8 @@ sub localactionrm
 {
 my($filename)=@_;
 
-       if (!unlink $filename) {
+       # '\1' for '-r':
+       if (!remove \1,$filename) {
                mayfatal "File \"$_\" cannot be removed" if !$!{ENOENT};
                }
 }
@@ -194,11 +213,12 @@ my($filename)=@_;
 sub localactionrootset
 {
        local *R;
-       if (!open R,'>',ROOT) {
+       if (!open R,'+<',ROOT) {
                mayfatal "File \"".ROOT."\" cannot be written";
                return;
                }
        print R "$opt_root\n";
+       truncate R,tell R;
        close R;
 }