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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
package File::Find::Rule::VCS; # git description: b034768
=pod
=head1 NAME
File::Find::Rule::VCS - Exclude files/directories for Version Control Systems
=head1 SYNOPSIS
use File::Find::Rule ();
use File::Find::Rule::VCS ();
# Find all files smaller than 10k, ignoring version control files
my @files = File::Find::Rule->ignore_vcs
->file
->size('<10Ki')
->in( $dir );
=head1 DESCRIPTION
Many tools need to be equally useful both on ordinary files, and on code
that has been checked out from revision control systems.
B<File::Find::Rule::VCS> provides quick and convenient methods to
exclude the version control directories of several major Version
Control Systems (currently CVS, subversion, and Bazaar).
B<File::Find::Rule::VCS> implements methods to ignore the following:
=over 4
=item B<CVS>
=item B<Subversion>
=item B<Bazaar>
=back
In addition, the following version control systems do not create
directories in the checkout and do not require the use of any
ignore methods
=over 4
=item B<SVK>
=item B<Git>
=back
=head1 METHODS
=cut
use 5.00503;
use strict;
use Carp ();
use Text::Glob 0.08 ();
use File::Find::Rule 0.20 ();
our $VERSION = '1.09';
our @ISA = 'File::Find::Rule';
our @EXPORT = @File::Find::Rule::EXPORT;
use constant FFR => 'File::Find::Rule';
# In some Windows SVN implementations, it uses _svn instead of
# .svn, so use both on Win32.
my @svn = ($^O eq 'MSWin32') ? ('.svn', '_svn') : ('.svn');
#####################################################################
# File::Find::Rule Method Addition
=pod
=head2 ignore_vcs
# Ignore all common version control systems
$find->ignore_vcs;
# Ignore a specific named version control systems
$find->ignore_vcs($name);
# Ignore nothing (silent pass-through)
$find->ignore_vcs('');
The C<ignore_vcs> method excludes the files for a named Version Control
System from your L<File::Find::Rule> search.
If passed, the name of the version control system is case in-sensitive.
Names currently supported are 'cvs', 'svn', 'subversion', 'bzr', and
'bazaar'.
As a convenience for high-level APIs, if the VCS name is the defined
null string B<''> then the call will be treated as a nullop.
If no params at all are passed, this method will ignore all supported
version control systems. If ignoring every version control system,
please note that any legitimate directories called "CVS" or files
starting with .# will be ignored, which is not always desirable.
In widely-distributed code, you instead should try to detect the specific
version control system used and call ignore_vcs with the specific name.
Passing C<undef>, or an unsupported name, will throw an exception.
=cut
sub File::Find::Rule::ignore_vcs {
my $find = $_[0]->_force_object;
# Handle special cases
if( 1 == scalar( @_ ) ) {
# Logically combine all the ignores. This will be much
# faster than just calling them all one after the other.
return $find->or(
FFR->name(@svn, '.bzr', '.git', '.hg', 'CVS', 'RCS')
->directory->prune->discard,
FFR->name(qr/^\.\#/, qr/,v$/)->file->discard,
FFR->new,
);
}
unless ( defined $_[1] ) {
Carp::croak("->ignore_vcs: No version control system name provided");
}
# As a convenience for higher-level APIs
# we treat a defined null string as a nullop
my $vcs = lc $_[1];
return $find if $vcs eq '';
# Hand off to the rules for each VCS
return $find->ignore_cvs if $vcs eq 'cvs';
return $find->ignore_rcs if $vcs eq 'rcs';
return $find->ignore_svn if $vcs eq 'svn';
return $find->ignore_svn if $vcs eq 'subversion';
return $find->ignore_bzr if $vcs eq 'bzr';
return $find->ignore_bzr if $vcs eq 'bazaar';
return $find->ignore_git if $vcs eq 'git';
return $find->ignore_hg if $vcs eq 'hg';
return $find->ignore_hg if $vcs eq 'mercurial';
Carp::croak("->ignore_vcs: '$vcs' is not supported");
}
=pod
=head2 ignore_cvs
The C<ignore_cvs> method excluding all CVS directories from your
L<File::Find::Rule> search.
It will also exclude all the files left around by CVS after an
automated merge that start with C<'.#'> (dot-hash).
=cut
sub File::Find::Rule::ignore_cvs {
my $find = $_[0]->_force_object;
return $find->or(
FFR->name('CVS')->directory->prune->discard,
FFR->name(qr/^\.\#/)->file->discard,
FFR->new,
);
}
=pod
=head2 ignore_rcs
The C<ignore_rcs> method excluding all RCS directories from your
L<File::Find::Rule> search.
It will also exclude all the files used by RCS to store the revisions
(end with C<',v'>).
=cut
sub File::Find::Rule::ignore_rcs {
my $find = $_[0]->_force_object;
return $find->or(
FFR->name('RCS')->directory->prune->discard,
FFR->name(qr/,v$/)->file->discard,
FFR->new,
);
}
=pod
=head2 ignore_svn
The C<ignore_svn> method excluding all Subversion (C<.svn>) directories
from your L<File::Find::Rule> search.
=cut
sub File::Find::Rule::ignore_svn {
my $find = $_[0]->_force_object;
return $find->or(
FFR->name(@svn)->directory->prune->discard,
FFR->new,
);
}
=pod
=head2 ignore_bzr
The C<ignore_bzr> method excluding all Bazaar (C<.bzr>) directories
from your L<File::Find::Rule> search.
=cut
sub File::Find::Rule::ignore_bzr {
my $find = $_[0]->_force_object;
return $find->or(
FFR->name('.bzr')->directory->prune->discard,
FFR->new,
);
}
=pod
=head2 ignore_git
The C<ignore_git> method excluding all Git (C<.git>) directories
from your L<File::Find::Rule> search.
=cut
sub File::Find::Rule::ignore_git {
my $find = $_[0]->_force_object;
return $find->or(
FFR->name('.git')->directory->prune->discard,
FFR->new,
);
}
=pod
=head2 ignore_hg
The C<ignore_hg> method excluding all Mercurial/Hg (C<.hg>) directories
from your L<File::Find::Rule> search.
=cut
sub File::Find::Rule::ignore_hg {
my $find = $_[0]->_force_object;
return $find->or(
FFR->name('.hg')->directory->prune->discard,
FFR->new,
);
}
1;
=pod
=head1 TO DO
- Add support for other version control systems.
- Add other useful VCS-related methods
=head1 SUPPORT
Bugs should always be submitted via the CPAN bug tracker
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Find-Rule-VCS>
For other issues, contact the maintainer
=head1 AUTHOR
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
=head1 SEE ALSO
L<http://ali.as/>, L<File::Find::Rule>
=head1 COPYRIGHT
Copyright 2005 - 2010 Adam Kennedy.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=cut
|