| 1 | package File::Find::Object::Rule::VCS; | ||||||||||
| 2 | |||||||||||
| 3 | =pod | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | File::Find::Object::Rule::VCS - Exclude files/directories for Version Control | ||||||||||
| 8 | Systems | ||||||||||
| 9 | |||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||
| 11 | |||||||||||
| 12 | use File::Find::Object::Rule (); | ||||||||||
| 13 | use File::Find::Object::Rule::VCS (); | ||||||||||
| 14 | |||||||||||
| 15 | # Find all files smaller than 10k, ignoring version control files | ||||||||||
| 16 | my @files = File::Find::Object::Rule->ignore_vcs | ||||||||||
| 17 | ->file | ||||||||||
| 18 | ->size('<10Ki') | ||||||||||
| 19 | ->in( $dir ); | ||||||||||
| 20 | |||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||
| 22 | |||||||||||
| 23 | Many tools need to be equally useful both on ordinary files, and on code | ||||||||||
| 24 | that has been checked out from revision control systems. | ||||||||||
| 25 | |||||||||||
| 26 | B<File::Find::Object::Rule::VCS> provides quick and convenient methods to | ||||||||||
| 27 | exclude the version control directories of several major Version | ||||||||||
| 28 | Control Systems (currently CVS, subversion, and Bazaar). | ||||||||||
| 29 | |||||||||||
| 30 | B<File::Find::Object::Rule::VCS> implements methods to ignore the following: | ||||||||||
| 31 | |||||||||||
| 32 | =over 4 | ||||||||||
| 33 | |||||||||||
| 34 | =item B<CVS> | ||||||||||
| 35 | |||||||||||
| 36 | =item B<Subversion> | ||||||||||
| 37 | |||||||||||
| 38 | =item B<Bazaar> | ||||||||||
| 39 | |||||||||||
| 40 | =back | ||||||||||
| 41 | |||||||||||
| 42 | In addition, the following version control systems do not create | ||||||||||
| 43 | directories in the checkout and do not require the use of any | ||||||||||
| 44 | ignore methods | ||||||||||
| 45 | |||||||||||
| 46 | =over 4 | ||||||||||
| 47 | |||||||||||
| 48 | =item B<SVK> | ||||||||||
| 49 | |||||||||||
| 50 | =item B<Git> | ||||||||||
| 51 | |||||||||||
| 52 | =back | ||||||||||
| 53 | |||||||||||
| 54 | =head1 METHODS | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 3 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 59 | |||||||||||
| 60 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 61 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | |||||||||||
| 63 | 3 | ▶ | use UNIVERSAL; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 3 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 65 | 3 | ▶ | use Text::Glob 0.08 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 3 | ▶ | use File::Find::Object::Rule (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 67 | |||||||||||
| 68 | 3 | ▶ | use vars qw{$VERSION @ISA @EXPORT}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 69 | |||||||||||
| 70 | 3 | $VERSION = '0.0.3'; | |||||||||
| 71 | |||||||||||
| 72 | 3 | ▶ | use base 'File::Find::Object::Rule'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 73 | |||||||||||
| 74 | 3 | my $FFOR = 'File::Find::Object::Rule'; | |||||||||
| 75 | |||||||||||
| 76 | # In some Windows SVN implementations, it uses _svn instead of | ||||||||||
| 77 | # .svn, so use both on Win32. | ||||||||||
| 78 | 3 | ▶ | my @svn = ($^O eq 'MSWin32') ? ('.svn', '_svn') : ('.svn'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | |||||||||||
| 80 | ##################################################################### | ||||||||||
| 81 | # File::Find::Object::Rule Method Addition | ||||||||||
| 82 | |||||||||||
| 83 | =pod | ||||||||||
| 84 | |||||||||||
| 85 | =head2 ignore_vcs | ||||||||||
| 86 | |||||||||||
| 87 | # Ignore all common version control systems | ||||||||||
| 88 | $find->ignore_vcs; | ||||||||||
| 89 | |||||||||||
| 90 | # Ignore a specific named version control systems | ||||||||||
| 91 | $find->ignore_vcs($name); | ||||||||||
| 92 | |||||||||||
| 93 | # Ignore nothing (silent pass-through) | ||||||||||
| 94 | $find->ignore_vcs(''); | ||||||||||
| 95 | |||||||||||
| 96 | The C<ignore_vcs> method excludes the files for a named Version Control | ||||||||||
| 97 | System from your L<File::Find::Object::Rule> search. | ||||||||||
| 98 | |||||||||||
| 99 | If passed, the name of the version control system is case in-sensitive. | ||||||||||
| 100 | Names currently supported are 'cvs', 'svn', 'subversion', 'bzr', and | ||||||||||
| 101 | 'bazaar'. | ||||||||||
| 102 | |||||||||||
| 103 | As a convenience for high-level APIs, if the VCS name is the defined | ||||||||||
| 104 | null string B<''> then the call will be treated as a nullop. | ||||||||||
| 105 | |||||||||||
| 106 | If no params at all are passed, this method will ignore all supported | ||||||||||
| 107 | version control systems. If ignoring every version control system, | ||||||||||
| 108 | please note that any legitimate directories called "CVS" or files | ||||||||||
| 109 | starting with .# will be ignored, which is not always desirable. | ||||||||||
| 110 | |||||||||||
| 111 | In widely-distributed code, you instead should try to detect the specific | ||||||||||
| 112 | version control system used and call ignore_vcs with the specific name. | ||||||||||
| 113 | |||||||||||
| 114 | Passing C<undef>, or an unsupported name, will throw an exception. | ||||||||||
| 115 | |||||||||||
| 116 | =cut | ||||||||||
| 117 | |||||||||||
| 118 | sub File::Find::Object::Rule::ignore_vcs { | ||||||||||
| 119 | 4 | ▶ | my $find = $_[0]->_force_object; | ||||||||
|
Subroutine
ignore_vcs: called CC=10 SCAR=28.2
Pod
undocumented
| |||||||||||
| 120 | |||||||||||
| 121 | # Handle special cases | ||||||||||
| 122 | 4 | ▶ | unless ( @_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | # Logically combine all the ignores. This will be much | ||||||||||
| 124 | # faster than just calling them all one after the other. | ||||||||||
| 125 | 0 | return $find->or( | |||||||||
| 126 | $FFOR->name(@svn, '.bzr', '.git', 'CVS')->directory->prune->discard, | ||||||||||
| 127 | $FFOR->name(qr/^\.\#/)->file->discard, | ||||||||||
| 128 | $FFOR->new, | ||||||||||
| 129 | ); | ||||||||||
| 130 | } | ||||||||||
| 131 | 4 | ▶ | unless ( defined $_[1] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | 0 | Carp::croak("->ignore_vcs: No version control system name provided"); | |||||||||
| 133 | } | ||||||||||
| 134 | |||||||||||
| 135 | # As a convenience for higher-level APIs | ||||||||||
| 136 | # we treat a defined null string as a nullop | ||||||||||
| 137 | 4 | my $vcs = lc $_[1]; | |||||||||
| 138 | 4 | ▶ | return $find if $vcs eq ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | |||||||||||
| 140 | # Hand off to the rules for each VCS | ||||||||||
| 141 | 3 | ▶ | return $find->ignore_cvs if $vcs eq 'cvs'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 2 | ▶ | return $find->ignore_svn if $vcs eq 'svn'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 1 | ▶ | return $find->ignore_svn if $vcs eq 'subversion'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | 1 | ▶ | return $find->ignore_bzr if $vcs eq 'bzr'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 0 | ▶ | return $find->ignore_bzr if $vcs eq 'bazaar'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 0 | ▶ | return $find->ignore_git if $vcs eq 'git'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 147 | 0 | Carp::croak("->ignore_vcs: '$vcs' is not supported"); | |||||||||
| 148 | } | ||||||||||
| 149 | |||||||||||
| 150 | =pod | ||||||||||
| 151 | |||||||||||
| 152 | =head2 ignore_cvs | ||||||||||
| 153 | |||||||||||
| 154 | The C<ignore_cvs> method excluding all CVS directories from your | ||||||||||
| 155 | L<File::Find::Object::Rule> search. | ||||||||||
| 156 | |||||||||||
| 157 | It will also exclude all the files left around by CVS after an | ||||||||||
| 158 | automated merge that start with C<'.#'> (dot-hash). | ||||||||||
| 159 | |||||||||||
| 160 | =cut | ||||||||||
| 161 | |||||||||||
| 162 | sub File::Find::Object::Rule::ignore_cvs { | ||||||||||
| 163 | 2 | ▶ | my $find = $_[0]->_force_object; | ||||||||
|
Subroutine
ignore_cvs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 164 | 2 | return $find->or( | |||||||||
| 165 | $FFOR->name('CVS')->directory->prune->discard, | ||||||||||
| 166 | $FFOR->name(qr/^\.\#/)->file->discard, | ||||||||||
| 167 | $FFOR->new, | ||||||||||
| 168 | ); | ||||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | =pod | ||||||||||
| 172 | |||||||||||
| 173 | =head2 ignore_svn | ||||||||||
| 174 | |||||||||||
| 175 | The C<ignore_svn> method excluding all Subversion (C<.svn>) directories | ||||||||||
| 176 | from your L<File::Find::Object::Rule> search. | ||||||||||
| 177 | |||||||||||
| 178 | =cut | ||||||||||
| 179 | |||||||||||
| 180 | sub File::Find::Object::Rule::ignore_svn { | ||||||||||
| 181 | 2 | ▶ | my $find = $_[0]->_force_object; | ||||||||
|
Subroutine
ignore_svn: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 182 | 2 | return $find->or( | |||||||||
| 183 | $FFOR->name(@svn)->directory->prune->discard, | ||||||||||
| 184 | $FFOR->new, | ||||||||||
| 185 | ); | ||||||||||
| 186 | } | ||||||||||
| 187 | |||||||||||
| 188 | =pod | ||||||||||
| 189 | |||||||||||
| 190 | =head2 ignore_bzr | ||||||||||
| 191 | |||||||||||
| 192 | The C<ignore_bzr> method excluding all Bazaar (C<.bzr>) directories | ||||||||||
| 193 | from your L<File::Find::Object::Rule> search. | ||||||||||
| 194 | |||||||||||
| 195 | =cut | ||||||||||
| 196 | |||||||||||
| 197 | sub File::Find::Object::Rule::ignore_bzr { | ||||||||||
| 198 | 2 | ▶ | my $find = $_[0]->_force_object; | ||||||||
|
Subroutine
ignore_bzr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 199 | 2 | return $find->or( | |||||||||
| 200 | $FFOR->name('.bzr')->directory->prune->discard, | ||||||||||
| 201 | $FFOR->new, | ||||||||||
| 202 | ); | ||||||||||
| 203 | } | ||||||||||
| 204 | |||||||||||
| 205 | =pod | ||||||||||
| 206 | |||||||||||
| 207 | =head2 ignore_git | ||||||||||
| 208 | |||||||||||
| 209 | The C<ignore_git> method excluding all Git (C<.git>) directories | ||||||||||
| 210 | from your L<File::Find::Object::Rule> search. | ||||||||||
| 211 | |||||||||||
| 212 | =cut | ||||||||||
| 213 | |||||||||||
| 214 | sub File::Find::Object::Rule::ignore_git { | ||||||||||
| 215 | 0 | ▶ | my $find = $_[0]->_force_object; | ||||||||
|
Subroutine
ignore_git: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 216 | 0 | return $find->or( | |||||||||
| 217 | $FFOR->name('.git')->directory->prune->discard, | ||||||||||
| 218 | $FFOR->new, | ||||||||||
| 219 | ); | ||||||||||
| 220 | } | ||||||||||
| 221 | |||||||||||
| 222 | 3 | 1; | |||||||||
| 223 | |||||||||||
| 224 | =pod | ||||||||||
| 225 | |||||||||||
| 226 | =head1 TO DO | ||||||||||
| 227 | |||||||||||
| 228 | - Add support for other version control systems. | ||||||||||
| 229 | |||||||||||
| 230 | - Add other useful VCS-related methods | ||||||||||
| 231 | |||||||||||
| 232 | =head1 SUPPORT | ||||||||||
| 233 | |||||||||||
| 234 | Bugs should always be submitted via the CPAN bug tracker | ||||||||||
| 235 | |||||||||||
| 236 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Find-Rule-VCS> | ||||||||||
| 237 | |||||||||||
| 238 | For other issues, contact the maintainer | ||||||||||
| 239 | |||||||||||
| 240 | =head1 AUTHOR | ||||||||||
| 241 | |||||||||||
| 242 | =head2 ORIGINAL AUTHOR | ||||||||||
| 243 | |||||||||||
| 244 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||
| 245 | |||||||||||
| 246 | =head2 MAINTAINER | ||||||||||
| 247 | |||||||||||
| 248 | Shlomi Fish, L<http://www.shlomifish.org/> | ||||||||||
| 249 | |||||||||||
| 250 | =head1 SEE ALSO | ||||||||||
| 251 | |||||||||||
| 252 | L<http://ali.as/>, L<File::Find::Object::Rule> | ||||||||||
| 253 | |||||||||||
| 254 | Note: this code originated from Adam Kennedy's L<File::Find::Rule::VCS> | ||||||||||
| 255 | and was span-off/forked with his permission. | ||||||||||
| 256 | |||||||||||
| 257 | =head1 COPYRIGHT | ||||||||||
| 258 | |||||||||||
| 259 | Copyright 2005 - 2009 Adam Kennedy. | ||||||||||
| 260 | |||||||||||
| 261 | This program is free software; you can redistribute | ||||||||||
| 262 | it and/or modify it under the same terms as Perl itself. | ||||||||||
| 263 | |||||||||||
| 264 | The full text of the license can be found in the | ||||||||||
| 265 | LICENSE file included with this module. | ||||||||||
| 266 | |||||||||||
| 267 | =head2 Modification Disclaimer | ||||||||||
| 268 | |||||||||||
| 269 | Modified by Shlomi Fish, 2009. All rights disclaimed. | ||||||||||
| 270 | |||||||||||
| 271 | =cut | ||||||||||