MAJOR=7
MINOR=1
DEVNAME=vcs1
  6   …ˆl–Ü4ý(”Ê:”Ú€Æ_¸ÛJbÑ¿�þBür,à‡#®½#£+Àþñƒq·ŸðÀî ½    …#!/usr/bin/perl

# svn-clean - Wipes out unversioned files from SVN working copy.
# Copyright (C) 2004, 2005, 2006 Simon Perreault
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

use strict;
use Cwd;
use File::Path;
use Getopt::Long;
use Pod::Usage;

# Try to use SVN module if available.
my $use_svn_module = eval { require SVN::Client };

my $CWD = getcwd;

my @exclude      = ();
my $force        = 0;
my $quiet        = 0;
my $print        = 0;
my $help         = 0;
my $man          = 0;
my $nonrecursive = 0;
my @paths        = ($CWD);
GetOptions(
    "exclude=s"       => \@exclude,
    "force"           => \$force,
    "non-recursive|N" => \$nonrecursive,
    "quiet"           => \$quiet,
    "print"           => \$print,
    "help|?"          => \$help,
    "man"             => \$man
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
@paths = map { Cwd::abs_path($_) } @ARGV if @ARGV;

# Precompile regexes.
$_ = qr/$_/ foreach @exclude;

if ($use_svn_module) {

    # Create SVN client object. No need for connection to remote server.
    my $ctx = new SVN::Client;

    # Call handler function with status info for each file.
    $ctx->status( $_, undef, \&clean, !$nonrecursive, 1, 0, 1 )
      for @paths;
}
else {
    warn "Warning: Not using SVN Perl modules, this might be slow.\n"
      unless $quiet;

    # Build svn client command
    my @command = qw(svn status --no-ignore -v);
    if ($nonrecursive) {
        push @command, '-N';
    }

    # Main file-wiping loop.
    if ( $^O eq 'MSWin32' ) {

        # Perl on Windows currently doesn't have list pipe opens.
        open SVN, join( ' ', @command, @paths ) . '|'
          or die "Can't call program \"svn\": $!\n";
    }
    else {
        open SVN, "-|", @command, @paths
          or die "Can't call program \"svn\": $!\n";
    }
  LINE: while (<SVN>) {
        if (/^([\?ID])/) {
            my $file = (split)[-1];
            foreach my $ex (@exclude) {
                if ( $file =~ $ex ) {
                    print "excluded $file\n" unless $quiet or $print;
                    next LINE;
                }
            }
            if ( $1 eq 'D' ) {
                next unless -f $file;
            }
            else {
                next unless -e $file;
            }
            if ($print) {
                print "$file\n";
            }
            else {
                rmtree( $file, !$quiet, !$force );
            }
        }
    }
}

# Main file-wiping function.
sub clean {
    my ( $path, $status ) = @_;

    # Use relative path for pretty-printing.
    if ( $path =~ s/^\Q$CWD\E\/?//o ) {

        # If the substitution succeeded, we should have a relative path. Make
        # sure we don't delete critical stuff.
        return if $path =~ /^\//;
    }

    # Find files needing to be removed.
    if (   $status->text_status == $SVN::Wc::Status::unversioned
        or $status->text_status == $SVN::Wc::Status::ignored
        or $status->text_status == $SVN::Wc::Status::deleted )
    {
        foreach my $ex (@exclude) {
            if ( $path =~ $ex ) {
                print "excluded $path\n" unless $quiet or $print;
                return;
            }
        }

        # Make sure the file exists before removing it. Do not remove deleted
        # directories as 