Warning, /sdk/kde-dev-scripts/svn-clean is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env perl
0002
0003 #
0004 # This script recursively (beginning with the current directory)
0005 # wipes out everything not registered in SVN.
0006 #
0007 # rewritten in perl by Oswald Buddenhagen <ossi@kde.org>
0008 # based on bash version by Thiago Macieira <thiago@kde.org>
0009 # inspired by cvs-clean, written by Oswald Buddenhagen <ossi@kde.org>
0010 # inspired by the "old" cvs-clean target from Makefile.common
0011 #
0012 # This file is free software in terms of the BSD licence. That means
0013 # that you can do anything with it except removing this license or
0014 # the above copyright notice. There is NO WARRANTY of any kind.
0015 #
0016
0017 # Warning:
0018 # This script processes the output from the SVN executable
0019 # Do not run it along with colorsvn
0020
0021 use File::Path;
0022
0023 my $version = "svn-clean v1.0";
0024 my $heading = $version.": cleans up the Subversion working directory\n";
0025 my $usage = $heading.
0026 "svn-clean [-h] [-n] [-q] [-i|-f] [dirname]\n\n".
0027 "Where:\n".
0028 " -h shows this help screen\n".
0029 " -n dry-run: doesn't actually erase the files, just show their names\n".
0030 " -i interactive: ask for confirmation before erasing the files\n".
0031 " -f force: doesn't ask for confirmation before erasing\n".
0032 " -q quiet: doesn't show output\n";
0033
0034
0035 my $dry_run = 0;
0036 my $force = 0;
0037 my $quiet = 0;
0038
0039 sub check_confirm()
0040 {
0041 return if ($force);
0042
0043 open(TTY, "+< /dev/tty") or die "cannot open /dev/tty";
0044
0045 print TTY "This will erase files and directories that aren't in Subversion\n".
0046 "Are you sure you want to continue? (y/N) ";
0047
0048 if (<TTY> =~ /^[Yy]/) {
0049 $force = 1;
0050 close TTY;
0051 return;
0052 }
0053
0054 # user cancelled
0055 exit 0;
0056 }
0057
0058 # Parse arguments
0059 my $rest = 0;
0060 my @files = ();
0061 foreach my $arg (@ARGV) {
0062 if ($rest) {
0063 push @files, $arg;
0064 } else {
0065 if ($arg eq '-h' || $arg eq '--help') {
0066 print $usage;
0067 exit (0);
0068 } elsif ($arg eq '-n' || $arg eq '--dry-run') {
0069 $dry_run = 1;
0070 $force = 1;
0071 } elsif ($arg eq '-f' || $arg eq '--force') {
0072 $force = 1;
0073 } elsif ($arg eq '-i' || $arg eq '--interactive') {
0074 $force = 0;
0075 } elsif ($arg eq '-q' || $arg eq '--quiet') {
0076 $quiet = 1;
0077 } elsif ($arg eq '--') {
0078 $rest = 1;
0079 } elsif ($arg =~ /^-/) {
0080 print STDERR "svn-clean: unknown argument '".$arg."'\n\n".$usage;
0081 exit (1);
0082 } else {
0083 push @files, $arg;
0084 }
0085 }
0086 }
0087 if (!@files) {
0088 push @files, '.';
0089 }
0090
0091 # Unset TERM just so that no colours are output
0092 # in case $SVN points to colorsvn
0093 delete $ENV{'TERM'};
0094
0095 #print($heading."\n") unless $quiet;
0096
0097 foreach my $dir (@files) {
0098 open SVN, "-|", qw(svn status --no-ignore), $dir;
0099 while (<SVN>) {
0100 /^[I?] +(.*)$/ or next;
0101 my $file = $1;
0102 check_confirm();
0103 lstat $file;
0104 if (-d _) {
0105 print("D ".$file."\n") unless $quiet;
0106 rmtree($file, 0, 0) unless $dry_run;
0107 } else {
0108 print("F ".$file."\n") unless $quiet;
0109 unlink($file) unless $dry_run;
0110 }
0111 }
0112 close SVN;
0113 }