git-svn: port the 'rebuild' command to use Git::SVN objects
Also correctly shared some variables needed for Git::SVN::Log Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 12, 2007 at 02:49 UTC
e7f023c81a03ccdd25ce4b4c7ed77f367c8f7edd
1 file changed
+28
-43
git-svn.perl
+28
-43
@@ -7,7 +7,8 @@ use vars qw/ $AUTHOR $VERSION
7
$SVN_URL
8
$GIT_SVN_INDEX $GIT_SVN
9
$GIT_DIR $GIT_SVN_DIR $REVDB
10
- $_follow_parent $sha1 $sha1_short/;
10
+ $_follow_parent $sha1 $sha1_short $_revision
11
+ $_cp_remote $_upgrade/;
12
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
13
$VERSION = '@@GIT_VERSION@@';
14
@@ -69,8 +70,8 @@ my ($SVN);
70
my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS};
71
$sha1 = qr/[a-f\d]{40}/;
72
$sha1_short = qr/[a-f\d]{4,40}/;
72
-my ($_revision,$_stdin,$_help,$_rmdir,$_edit,
73
- $_find_copies_harder, $_l, $_cp_similarity, $_cp_remote,
73
+my ($_stdin,$_help,$_rmdir,$_edit,
74
+ $_find_copies_harder, $_l, $_cp_similarity,
75
$_repack, $_repack_nr, $_repack_flags, $_q,
76
$_message, $_file, $_no_metadata,
77
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
@@ -119,7 +120,7 @@ my %cmd = (
120
{ 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
121
'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
122
{ 'revision|r=i' => \$_revision } ],
122
- rebuild => [ \&rebuild, "Rebuild git-svn metadata (after git clone)",
123
+ rebuild => [ \&cmd_rebuild, "Rebuild git-svn metadata (after git clone)",
124
{ 'copy-remote|remote=s' => \$_cp_remote,
125
'upgrade' => \$_upgrade } ],
126
'graft-branches' => [ \&graft_branches,
@@ -223,53 +224,48 @@ sub version {
224
exit 0;
225
}
226
226
-sub rebuild {
227
- if (!verify_ref("refs/remotes/$GIT_SVN^0")) {
228
- copy_remote_ref();
227
+sub cmd_rebuild {
228
+ my $url = shift;
229
+ my $gs = $url ? Git::SVN->init(undef, $url)
230
+ : eval { Git::SVN->new };
231
+ $gs ||= Git::SVN->_new;
232
+ if (!verify_ref($gs->refname.'^0')) {
233
+ $gs->copy_remote_ref;
234
}
230
- $SVN_URL = shift or undef;
231
- my $newest_rev = 0;
235
if ($_upgrade) {
233
- command_noisy('update-ref',"refs/remotes/$GIT_SVN","
234
- $GIT_SVN-HEAD");
236
+ command_noisy('update-ref',$gs->refname, $gs->{id}.'-HEAD');
237
} else {
236
- check_upgrade_needed();
238
+ $gs->check_upgrade_needed;
239
}
240
239
- my ($rev_list, $ctx) = command_output_pipe("rev-list",
240
- "refs/remotes/$GIT_SVN");
241
+ my ($rev_list, $ctx) = command_output_pipe("rev-list", $gs->refname);
242
my $latest;
243
my $svn_uuid;
244
while (<$rev_list>) {
245
chomp;
246
my $c = $_;
246
- croak "Non-SHA1: $c\n" unless $c =~ /^$sha1$/o;
247
- my @commit = grep(/^git-svn-id: /,
248
- command(qw/cat-file commit/, $c));
249
- next if (!@commit); # skip merges
250
- my ($url, $rev, $uuid) = extract_metadata($commit[$#commit]);
251
- if (!defined $rev || !$uuid) {
252
- croak "Unable to extract revision or UUID from ",
253
- "$c, $commit[$#commit]\n";
254
- }
247
+ fatal "Non-SHA1: $c\n" unless $c =~ /^$sha1$/o;
248
+ my ($url, $rev, $uuid) = cmt_metadata($c);
249
+
250
+ # ignore merges (from set-tree)
251
+ next if (!defined $rev || !$uuid);
252
253
# if we merged or otherwise started elsewhere, this is
254
# how we break out of it
258
- next if (defined $svn_uuid && ($uuid ne $svn_uuid));
259
- next if (defined $SVN_URL && defined $url && ($url ne $SVN_URL));
255
+ if ((defined $svn_uuid && ($uuid ne $svn_uuid)) ||
256
+ ($gs->{url} && $url && ($url ne $gs->{url}))) {
257
+ next;
258
+ }
259
260
unless (defined $latest) {
262
- if (!$SVN_URL && !$url) {
263
- croak "SVN repository location required: $url\n";
261
+ if (!$gs->{url} && !$url) {
262
+ fatal "SVN repository location required\n";
263
}
265
- $SVN_URL ||= $url;
266
- $svn_uuid ||= $uuid;
267
- setup_git_svn();
264
+ $gs = Git::SVN->init(undef, $url);
265
$latest = $rev;
266
}
270
- revdb_set($REVDB, $rev, $c);
267
+ $gs->rev_db_set($rev, $c);
268
print "r$rev = $c\n";
272
- $newest_rev = $rev if ($rev > $newest_rev);
269
}
270
command_close_pipe($rev_list, $ctx);
271
}
@@ -2617,17 +2613,6 @@ sub revdb_get {
2613
return $ret;
2614
}
2615
2620
-sub copy_remote_ref {
2621
- my $origin = $_cp_remote ? $_cp_remote : 'origin';
2622
- my $ref = "refs/remotes/$GIT_SVN";
2623
- if (command('ls-remote', $origin, $ref)) {
2624
- command_noisy('fetch', $origin, "$ref:$ref");
2625
- } elsif ($_cp_remote && !$_upgrade) {
2626
- die "Unable to find remote reference: ",
2627
- "refs/remotes/$GIT_SVN on $origin\n";
2628
- }
2629
-}
2630
-
2616
{
2617
my $kill_stupid_warnings = $SVN::Node::none.$SVN::Node::file.
2618
$SVN::Node::dir.$SVN::Node::unknown.