ignore anything in .cvsignore

This commit is contained in:
adam 2005-12-15 11:37:31 +00:00 committed by Adam Spiers
parent 859401f1cd
commit 4ea5f396f9

42
stow.in
View file

@ -23,10 +23,18 @@
# $Date$ # $Date$
# $Author$ # $Author$
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Wed Nov 23 2005 Adam Spiers # Wed Nov 23 2005 Adam Spiers
# This version is hacked to ignore CVS/ directories. # This version is hacked to ignore anything listed in ~/.cvsignore
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! use File::Spec;
use FindBin qw($RealBin);
use Getopt::Long;
use lib "$RealBin/../lib/perl5";
use Sh 'glob_to_re';
my $ignore_file = File::Spec->join($ENV{HOME}, ".cvsignore");
my $ignore_re = get_ignore_re_from_file($ignore_file);
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
require 5.005; require 5.005;
use POSIX; use POSIX;
@ -333,14 +341,20 @@ sub StowContents {
local($content); local($content);
warn "Stowing contents of $dir\n" if ($Verbose > 1); warn "Stowing contents of $dir\n" if ($Verbose > 1);
opendir(DIR, &JoinPaths($Stow, $dir)) my $joined = &JoinPaths($Stow, $dir);
opendir(DIR, $joined)
|| die "$ProgramName: Cannot read directory \"$dir\" ($!)\n"; || die "$ProgramName: Cannot read directory \"$dir\" ($!)\n";
@contents = readdir(DIR); @contents = readdir(DIR);
closedir(DIR); closedir(DIR);
foreach $content (@contents) { foreach $content (@contents) {
# Wed Nov 23 2005 Adam Spiers # Wed Nov 23 2005 Adam Spiers
# hack to # hack to ignore stuff in ~/.cvsignore
next if $content eq '.' or $content eq '..' or $content eq 'CVS'; next if $content eq '.' or $content eq '..';
if ($content =~ $ignore_re) {
warn "Ignoring $joined/$content via $ignore_file\n"
if $Verbose > 2;
next;
}
if (-d &JoinPaths($Stow, $dir, $content)) { if (-d &JoinPaths($Stow, $dir, $content)) {
&StowDir(&JoinPaths($dir, $content), $stow); &StowDir(&JoinPaths($dir, $content), $stow);
} else { } else {
@ -547,6 +561,22 @@ sub version {
exit(0); exit(0);
} }
sub get_ignore_re_from_file {
my ($file) = @_;
my @regexps;
# Bootstrap issue - first time we stow, we will be stowing
# .cvsignore so it won't exist in ~ yet. At that time, use
# a sensible default instead.
open(REGEXPS, $file) or return qr!^(CVS)$!;
while (<REGEXPS>) {
chomp;
push @regexps, glob_to_re($_);
}
close(REGEXPS);
my $re = join '|', @regexps;
return qr/$re/;
}
# Local variables: # Local variables:
# mode: perl # mode: perl
# End: # End: