git-svn: rebuild convenience and bugfixes
We will now automatically fetch the refs/remotes/git-svn ref from origin and store a Pull: line for it. --remote=<origin> may be passed if your remote is named something other than 'origin' Also, remember to make GIT_SVN_DIR whenever we need to create .rev_db Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jun 16, 2006 at 02:55 UTC
1a82e79315ed633f6b0b1fc4076054950c5380d3
1 file changed
+19
-2
contrib/git-svn/git-svn.perl
+19
-2
@@ -42,7 +42,7 @@ my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS};
42
my $sha1 = qr/[a-f\d]{40}/;
43
my $sha1_short = qr/[a-f\d]{4,40}/;
44
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
45
- $_find_copies_harder, $_l, $_cp_similarity,
45
+ $_find_copies_harder, $_l, $_cp_similarity, $_cp_remote,
46
$_repack, $_repack_nr, $_repack_flags,
47
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
48
$_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
@@ -86,6 +86,7 @@ my %cmd = (
86
{ 'revision|r=i' => \$_revision } ],
87
rebuild => [ \&rebuild, "Rebuild git-svn metadata (after git clone)",
88
{ 'no-ignore-externals' => \$_no_ignore_ext,
89
+ 'copy-remote|remote=s' => \$_cp_remote,
90
'upgrade' => \$_upgrade } ],
91
'graft-branches' => [ \&graft_branches,
92
'Detect merges/branches from already imported history',
@@ -134,7 +135,7 @@ init_vars();
135
load_authors() if $_authors;
136
load_all_refs() if $_branch_all_refs;
137
svn_compat_check();
137
-migration_check() unless $cmd =~ /^(?:init|multi-init)$/;
138
+migration_check() unless $cmd =~ /^(?:init|rebuild|multi-init)$/;
139
$cmd{$cmd}->[0]->(@ARGV);
140
exit 0;
141
@@ -174,6 +175,9 @@ sub version {
175
}
176
177
sub rebuild {
178
+ if (quiet_run(qw/git-rev-parse --verify/,"refs/remotes/$GIT_SVN^0")) {
179
+ copy_remote_ref();
180
+ }
181
$SVN_URL = shift or undef;
182
my $newest_rev = 0;
183
if ($_upgrade) {
@@ -1940,6 +1944,7 @@ sub svn_cmd_checkout {
1944
1945
sub check_upgrade_needed {
1946
if (!-r $REVDB) {
1947
+ -d $GIT_SVN_DIR or mkpath([$GIT_SVN_DIR]);
1948
open my $fh, '>>',$REVDB or croak $!;
1949
close $fh;
1950
}
@@ -2052,6 +2057,7 @@ sub migrate_revdb {
2057
init_vars();
2058
exit 0 if -r $REVDB;
2059
print "Upgrading svn => git mapping...\n";
2060
+ -d $GIT_SVN_DIR or mkpath([$GIT_SVN_DIR]);
2061
open my $fh, '>>',$REVDB or croak $!;
2062
close $fh;
2063
rebuild();
@@ -2763,6 +2769,17 @@ sub revdb_get {
2769
return $ret;
2770
}
2771
2772
+sub copy_remote_ref {
2773
+ my $origin = $_cp_remote ? $_cp_remote : 'origin';
2774
+ my $ref = "refs/remotes/$GIT_SVN";
2775
+ if (safe_qx('git-ls-remote', $origin, $ref)) {
2776
+ sys(qw/git fetch/, $origin, "$ref:$ref");
2777
+ } else {
2778
+ die "Unable to find remote reference: ",
2779
+ "refs/remotes/$GIT_SVN on $origin\n";
2780
+ }
2781
+}
2782
+
2783
package SVN::Git::Editor;
2784
use vars qw/@ISA/;
2785
use strict;