@matheusbsbs / matheus-bagliano / commits / eeb0abe047
Fork 0

contrib/git-svn: cleanup option parsing

Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Mar 3, 2006 at 01:20 UTC eeb0abe0477dd638f52ef82795338edcb49efa2f
1 file changed +35 -30
contrib/git-svn/git-svn.perl
+35 -30
@@ -24,6 +24,7 @@ $ENV{LC_ALL} = 'C';
24 # If SVN:: library support is added, please make the dependencies
25 # optional and preserve the capability to use the command-line client.
26 # use eval { require SVN::... } to make it lazy load
27 +# We don't use any modules not in the standard Perl distribution:
28 use Carp qw/croak/;
29 use IO::File qw//;
30 use File::Basename qw/dirname basename/;
@@ -37,26 +38,25 @@ my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
38 $_find_copies_harder, $_l, $_version, $_upgrade, $_authors);
39 my (@_branch_from, %tree_map, %users);
40
40 -GetOptions( 'revision|r=s' => \$_revision,
41 - 'no-ignore-externals' => \$_no_ignore_ext,
42 - 'stdin|' => \$_stdin,
43 - 'edit|e' => \$_edit,
44 - 'rmdir' => \$_rmdir,
45 - 'upgrade' => \$_upgrade,
46 - 'help|H|h' => \$_help,
41 +my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
42 'branch|b=s' => \@_branch_from,
48 - 'find-copies-harder' => \$_find_copies_harder,
49 - 'authors-file|authors|A=s' => \$_authors,
50 - 'l=i' => \$_l,
51 - 'version|V' => \$_version,
52 - 'no-stop-on-copy' => \$_no_stop_copy );
43 + 'authors-file|A=s' => \$_authors );
44 my %cmd = (
54 - fetch => [ \&fetch, "Download new revisions from SVN" ],
55 - init => [ \&init, "Initialize and fetch (import)"],
56 - commit => [ \&commit, "Commit git revisions to SVN" ],
57 - 'show-ignore' => [ \&show_ignore, "Show svn:ignore listings" ],
58 - rebuild => [ \&rebuild, "Rebuild git-svn metadata (after git clone)" ],
59 - help => [ \&usage, "Show help" ],
45 + fetch => [ \&fetch, "Download new revisions from SVN",
46 + { 'revision|r=s' => \$_revision, %fc_opts } ],
47 + init => [ \&init, "Initialize and fetch (import)", { } ],
48 + commit => [ \&commit, "Commit git revisions to SVN",
49 + { 'stdin|' => \$_stdin,
50 + 'edit|e' => \$_edit,
51 + 'rmdir' => \$_rmdir,
52 + 'find-copies-harder' => \$_find_copies_harder,
53 + 'l=i' => \$_l,
54 + %fc_opts,
55 + } ],
56 + 'show-ignore' => [ \&show_ignore, "Show svn:ignore listings", { } ],
57 + rebuild => [ \&rebuild, "Rebuild git-svn metadata (after git clone)",
58 + { 'no-ignore-externals' => \$_no_ignore_ext,
59 + 'upgrade' => \$_upgrade } ],
60 );
61 my $cmd;
62 for (my $i = 0; $i < @ARGV; $i++) {
@@ -75,21 +75,14 @@ foreach (keys %cmd) {
75 }
76 }
77
78 -# '<svn username> = real-name <email address>' mapping based on git-svnimport:
79 -if ($_authors) {
80 - open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
81 - while (<$authors>) {
82 - chomp;
83 - next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
84 - my ($user, $name, $email) = ($1, $2, $3);
85 - $users{$user} = [$name, $email];
86 - }
87 - close $authors or croak $!;
88 -}
78 +my %opts;
79 +%opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
80
81 +GetOptions(%opts, 'help|H|h' => \$_help, 'version|V' => \$_version ) or exit 1;
82 usage(0) if $_help;
83 version() if $_version;
92 -usage(1) unless (defined $cmd);
84 +usage(1) unless defined $cmd;
85 +load_authors() if $_authors;
86 svn_check_ignore_externals();
87 $cmd{$cmd}->[0]->(@ARGV);
88 exit 0;
@@ -1047,6 +1040,18 @@ sub map_tree_joins {
1040 }
1041 }
1042
1043 +# '<svn username> = real-name <email address>' mapping based on git-svnimport:
1044 +sub load_authors {
1045 + open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1046 + while (<$authors>) {
1047 + chomp;
1048 + next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
1049 + my ($user, $name, $email) = ($1, $2, $3);
1050 + $users{$user} = [$name, $email];
1051 + }
1052 + close $authors or croak $!;
1053 +}
1054 +
1055 __END__
1056
1057 Data structures: