contrib/git-svn: add show-ignore command
[gitweb.git] / contrib / git-svn / git-svn.perl
index 3a5945490e4665133f1a4898608f20d3ce363f0c..3d855f123b3a7681cf388a2582fb8fb0e631ca47 100755 (executable)
@@ -1,4 +1,6 @@
 #!/usr/bin/env perl
+# Copyright (C) 2006, Eric Wong <normalperson@yhbt.net>
+# License: GPL v2 or later
 use warnings;
 use strict;
 use vars qw/   $AUTHOR $VERSION
@@ -6,7 +8,7 @@
                $GIT_SVN_INDEX $GIT_SVN
                $GIT_DIR $REV_DIR/;
 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
-$VERSION = '0.9.0';
+$VERSION = '0.9.1';
 $GIT_DIR = $ENV{GIT_DIR} || "$ENV{PWD}/.git";
 $GIT_SVN = $ENV{GIT_SVN_ID} || 'git-svn';
 $GIT_SVN_INDEX = "$GIT_DIR/$GIT_SVN/index";
@@ -31,7 +33,7 @@
 my $sha1 = qr/[a-f\d]{40}/;
 my $sha1_short = qr/[a-f\d]{6,40}/;
 my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
-       $_find_copies_harder, $_l);
+       $_find_copies_harder, $_l, $_version);
 
 GetOptions(    'revision|r=s' => \$_revision,
                'no-ignore-externals' => \$_no_ignore_ext,
                'help|H|h' => \$_help,
                'find-copies-harder' => \$_find_copies_harder,
                'l=i' => \$_l,
+               'version|V' => \$_version,
                'no-stop-on-copy' => \$_no_stop_copy );
 my %cmd = (
        fetch => [ \&fetch, "Download new revisions from SVN" ],
        init => [ \&init, "Initialize and fetch (import)"],
        commit => [ \&commit, "Commit git revisions to SVN" ],
+       'show-ignore' => [ \&show_ignore, "Show svn:ignore listings" ],
        rebuild => [ \&rebuild, "Rebuild git-svn metadata (after git clone)" ],
        help => [ \&usage, "Show help" ],
 );
@@ -66,6 +70,7 @@
        }
 }
 usage(0) if $_help;
+version() if $_version;
 usage(1) unless (defined $cmd);
 svn_check_ignore_externals();
 $cmd{$cmd}->[0]->(@ARGV);
@@ -91,6 +96,11 @@ sub usage {
        exit $exit;
 }
 
+sub version {
+       print "git-svn version $VERSION\n";
+       exit 0;
+}
+
 sub rebuild {
        $SVN_URL = shift or undef;
        my $repo_uuid;
@@ -249,6 +259,30 @@ sub commit {
 
 }
 
+sub show_ignore {
+       require File::Find or die $!;
+       my $exclude_file = "$GIT_DIR/info/exclude";
+       open my $fh, '<', $exclude_file or croak $!;
+       chomp(my @excludes = (<$fh>));
+       close $fh or croak $!;
+
+       $SVN_URL ||= file_to_s("$GIT_DIR/$GIT_SVN/info/url");
+       chdir $SVN_WC or croak $!;
+       my %ign;
+       File::Find::find({wanted=>sub{if(lstat $_ && -d _ && -d "$_/.svn"){
+               s#^\./##;
+               @{$ign{$_}} = safe_qx(qw(svn propget svn:ignore),$_);
+               }}, no_chdir=>1},'.');
+
+       print "\n# /\n";
+       foreach (@{$ign{'.'}}) { print '/',$_ if /\S/ }
+       delete $ign{'.'};
+       foreach my $i (sort keys %ign) {
+               print "\n# ",$i,"\n";
+               foreach (@{$ign{$i}}) { print '/',$i,'/',$_ if /\S/ }
+       }
+}
+
 ########################### utility functions #########################
 
 sub setup_git_svn {