git-svn: hopefully make 'fetch' more user-friendly
multi-fetch is deprecated, "fetch -a" is easier to type By default, fetch will fetch everything from its default [svn-remote]; if fetch [--all|-a] is specified, then it will fetch from all svn remotes. Refspecs on the command-line (like git-fetch) are not supported. Also, enable -r/--revision arguments for fetch so users can shoot themselves in the foot^W^W^W^W^W skip some history and do the equivalent of a shallow clone/fetch they're not interested in. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Feb 14, 2007 at 02:21 UTC
e98671e5c2067a39759c8f08b79c260a9f0b2771
1 file changed
+33
-25
git-svn.perl
+33
-25
@@ -53,7 +53,7 @@ $sha1_short = qr/[a-f\d]{4,40}/;
53
my ($_stdin, $_help, $_edit,
54
$_message, $_file,
55
$_template, $_shared,
56
- $_version,
56
+ $_version, $_fetch_all,
57
$_merge, $_strategy, $_dry_run,
58
$_prefix);
59
$Git::SVN::_follow_parent = 1;
@@ -84,7 +84,9 @@ my %cmt_opts = ( 'edit|e' => \$_edit,
84
85
my %cmd = (
86
fetch => [ \&cmd_fetch, "Download new revisions from SVN",
87
- { 'revision|r=s' => \$_revision, %fc_opts } ],
87
+ { 'revision|r=s' => \$_revision,
88
+ 'all|a' => \$_fetch_all,
89
+ %fc_opts } ],
90
init => [ \&cmd_init, "Initialize a repo for tracking" .
91
" (requires URL argument)",
92
\%init_opts ],
@@ -106,8 +108,8 @@ my %cmd = (
108
'prefix=s' => \$_prefix,
109
} ],
110
'multi-fetch' => [ \&cmd_multi_fetch,
109
- 'Fetch multiple trees (like git-svnimport)',
110
- \%fc_opts ],
111
+ "Deprecated alias for $0 fetch --all",
112
+ { 'revision|r=s' => \$_revision, %fc_opts } ],
113
'migrate' => [ sub { },
114
# no-op, we automatically run this anyways,
115
'Migrate configuration/metadata/layout from
@@ -226,16 +228,19 @@ sub cmd_init {
228
}
229
230
sub cmd_fetch {
229
- if (@_) {
230
- die "Additional fetch arguments are no longer supported.\n",
231
- "Use --follow-parent if you have moved/copied directories
232
- instead.\n";
231
+ if (grep /^\d+=./, @_) {
232
+ die "'<rev>=<commit>' fetch arguments are ",
233
+ "no longer supported.\n";
234
}
234
- my $gs = Git::SVN->new;
235
- $gs->fetch(parse_revision_argument());
236
- if ($gs->{last_commit} && !verify_ref('refs/heads/master^0')) {
237
- command_noisy(qw(update-ref refs/heads/master),
238
- $gs->{last_commit});
235
+ my ($remote) = @_;
236
+ if (@_ > 1) {
237
+ die "Usage: $0 fetch [--all|-a] [svn-remote]\n";
238
+ }
239
+ $remote ||= $Git::SVN::default_repo_id;
240
+ if ($_fetch_all) {
241
+ cmd_multi_fetch();
242
+ } else {
243
+ Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes());
244
}
245
}
246
@@ -440,18 +445,6 @@ sub cmd_commit_diff {
445
446
########################### utility functions #########################
447
443
-sub parse_revision_argument {
444
- if (!defined $_revision || $_revision eq 'BASE:HEAD') {
445
- return (undef, undef);
446
- }
447
- return ($1, $2) if ($_revision =~ /^(\d+):(\d+)$/);
448
- return ($_revision, $_revision) if ($_revision =~ /^\d+$/);
449
- return (undef, $1) if ($_revision =~ /^BASE:(\d+)$/);
450
- return ($1, undef) if ($_revision =~ /^(\d+):HEAD$/);
451
- die "revision argument: $_revision not understood by git-svn\n",
452
- "Try using the command-line svn client instead\n";
453
-}
454
-
448
sub complete_svn_url {
449
my ($url, $path) = @_;
450
$path =~ s#/+$##;
@@ -755,6 +748,19 @@ sub resolve_local_globs {
748
}
749
}
750
751
+sub parse_revision_argument {
752
+ my ($base, $head) = @_;
753
+ if (!defined $::_revision || $::_revision eq 'BASE:HEAD') {
754
+ return ($base, $head);
755
+ }
756
+ return ($1, $2) if ($::_revision =~ /^(\d+):(\d+)$/);
757
+ return ($::_revision, $::_revision) if ($::_revision =~ /^\d+$/);
758
+ return ($head, $head) if ($::_revision eq 'HEAD');
759
+ return ($base, $1) if ($::_revision =~ /^BASE:(\d+)$/);
760
+ return ($1, $head) if ($::_revision =~ /^(\d+):HEAD$/);
761
+ die "revision argument: $::_revision not understood by git-svn\n";
762
+}
763
+
764
sub fetch_all {
765
my ($repo_id, $remotes) = @_;
766
my $remote = $remotes->{$repo_id};
@@ -787,6 +793,8 @@ sub fetch_all {
793
push @gs, $gs;
794
}
795
}
796
+
797
+ ($base, $head) = parse_revision_argument($base, $head);
798
$ra->gs_fetch_loop_common($base, $head, \@gs, \@globs);
799
}
800