git-svn: allow 'init' to act as multi-init
multi-init is now just an alias that requires -T/-t/-b; all options that 'init' can now accept. This will hopefully simplify usage and reduce typing. Also, allow the --shared option in 'init' to take an optional argument now that 'git-init --shared' supports an optional argument. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Feb 14, 2007 at 12:27 UTC
dadc6d2a0904e55ac5a5a810dffac4d44fff0b66
3 files changed
+36
-24
git-svn.perl
+32
-20
@@ -71,10 +71,10 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
71
%remote_opts );
72
73
my ($_trunk, $_tags, $_branches);
74
-my %multi_opts = ( 'trunk|T=s' => \$_trunk,
75
- 'tags|t=s' => \$_tags,
76
- 'branches|b=s' => \$_branches );
77
-my %init_opts = ( 'template=s' => \$_template, 'shared' => \$_shared );
74
+my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared,
75
+ 'trunk|T=s' => \$_trunk, 'tags|t=s' => \$_tags,
76
+ 'branches|b=s' => \$_branches, 'prefix=s' => \$_prefix,
77
+ %remote_opts );
78
my %cmt_opts = ( 'edit|e' => \$_edit,
79
'rmdir' => \$SVN::Git::Editor::_rmdir,
80
'find-copies-harder' => \$SVN::Git::Editor::_find_copies_harder,
@@ -90,6 +90,10 @@ my %cmd = (
90
init => [ \&cmd_init, "Initialize a repo for tracking" .
91
" (requires URL argument)",
92
\%init_opts ],
93
+ 'multi-init' => [ \&cmd_multi_init,
94
+ "Deprecated alias for ".
95
+ "'$0 init -T<trunk> -b<branches> -t<tags>'",
96
+ \%init_opts ],
97
dcommit => [ \&cmd_dcommit,
98
'Commit several diffs to merge with upstream',
99
{ 'merge|m|M' => \$_merge,
@@ -101,12 +105,6 @@ my %cmd = (
105
{ 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
106
'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
107
{ 'revision|r=i' => \$_revision } ],
104
- 'multi-init' => [ \&cmd_multi_init,
105
- 'Initialize multiple trees (like git-svnimport)',
106
- { %multi_opts, %init_opts, %remote_opts,
107
- 'revision|r=i' => \$_revision,
108
- 'prefix=s' => \$_prefix,
109
- } ],
108
'multi-fetch' => [ \&cmd_multi_fetch,
109
"Deprecated alias for $0 fetch --all",
110
{ 'revision|r=s' => \$_revision, %fc_opts } ],
@@ -182,6 +180,7 @@ Usage: $0 <command> [options] [arguments]\n
180
next if $cmd && $cmd ne $_;
181
print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
182
foreach (keys %{$cmd{$_}->[2]}) {
183
+ next if /^multi-/; # don't show deprecated commands
184
# prints out arguments as they should be passed:
185
my $x = s#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
186
print $fd ' ' x 21, join(', ', map { length $_ > 1 ?
@@ -207,21 +206,31 @@ sub do_git_init_db {
206
unless (-d $ENV{GIT_DIR}) {
207
my @init_db = ('init');
208
push @init_db, "--template=$_template" if defined $_template;
210
- push @init_db, "--shared" if defined $_shared;
209
+ if (defined $_shared) {
210
+ if ($_shared =~ /[a-z]/) {
211
+ push @init_db, "--shared=$_shared";
212
+ } else {
213
+ push @init_db, "--shared";
214
+ }
215
+ }
216
command_noisy(@init_db);
217
}
218
}
219
220
+sub init_subdir {
221
+ my $repo_path = shift or return;
222
+ mkpath([$repo_path]) unless -d $repo_path;
223
+ chdir $repo_path or die "Couldn't chdir to $repo_path: $!\n";
224
+ $ENV{GIT_DIR} = $repo_path . "/.git";
225
+}
226
+
227
sub cmd_init {
216
- my $url = shift or die "SVN repository location required " .
217
- "as a command-line argument\n";
218
- if (my $repo_path = shift) {
219
- unless (-d $repo_path) {
220
- mkpath([$repo_path]);
221
- }
222
- chdir $repo_path or croak $!;
223
- $ENV{GIT_DIR} = $repo_path . "/.git";
228
+ if (defined $_trunk || defined $_branches || defined $_tags) {
229
+ return cmd_multi_init(@_);
230
}
231
+ my $url = shift or die "SVN repository location required ",
232
+ "as a command-line argument\n";
233
+ init_subdir(@_);
234
do_git_init_db();
235
236
Git::SVN->init($url);
@@ -367,7 +376,10 @@ sub cmd_multi_init {
376
}
377
do_git_init_db();
378
$_prefix = '' unless defined $_prefix;
370
- $url =~ s#/+$## if defined $url;
379
+ if (defined $url) {
380
+ $url =~ s#/+$##;
381
+ init_subdir(@_);
382
+ }
383
if (defined $_trunk) {
384
my $trunk_ref = $_prefix . 'trunk';
385
# try both old-style and new-style lookups:
t/t9107-git-svn-migrate.sh
+2
-2
@@ -40,7 +40,7 @@ test_expect_success 'initialize old-style (v0) git-svn layout' "
40
"
41
42
test_expect_success 'initialize a multi-repository repo' "
43
- git-svn multi-init $svnrepo -T trunk -t tags -b branches &&
43
+ git-svn init $svnrepo -T trunk -t tags -b branches &&
44
git-config --get-all svn-remote.svn.fetch > fetch.out &&
45
grep '^trunk:refs/remotes/trunk$' fetch.out &&
46
test -n \"\`git-config --get svn-remote.svn.branches \
@@ -72,7 +72,7 @@ test_expect_success 'multi-fetch works on partial urls + paths' "
72
refs/remotes/\$j\`\" ||exit 1; done; done
73
"
74
75
-test_expect_success 'migrate --minimize on old multi-inited layout' "
75
+test_expect_success 'migrate --minimize on old inited layout' "
76
git config --unset-all svn-remote.svn.fetch &&
77
git config --unset-all svn-remote.svn.url &&
78
rm -rf $GIT_DIR/svn &&
t/t9109-git-svn-svk-mirrorpaths.sh
+2
-2
@@ -73,8 +73,8 @@ test_expect_success 'initialize repo' "
73
cd ..
74
"
75
76
-test_expect_success 'multi-init an SVK mirror path' "
77
- git-svn multi-init -T trunk -t tags -b branches $svnrepo/mirror/foobar
76
+test_expect_success 'init an SVK mirror path' "
77
+ git-svn init -T trunk -t tags -b branches $svnrepo/mirror/foobar
78
"
79
80
test_expect_success 'multi-fetch an SVK mirror path' "git-svn multi-fetch"