git-svn: dcommit/rebase confused by patches with git-svn-id: lines
When patches are merged from another git-svn managed branch, they will have the git-svn-id: metadata line in them (generated by git-format-patch). When doing rebase or dcommit via git-svn, this would cause git-svn to find the wrong upstream branch. We now verify that the commit is consistent with the value in the .rev_db file. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric Wong committed
Apr 8, 2007 at 00:59 UTC
13c823fb520eaf1cded520213cf0ae4c3268208d
1 file changed
+21
-20
git-svn.perl
+21
-20
@@ -363,13 +363,12 @@ sub cmd_dcommit {
363
my $head = shift;
364
$head ||= 'HEAD';
365
my @refs;
366
- my ($url, $rev, $uuid) = working_head_info($head, \@refs);
367
- my $c = $refs[-1];
368
- unless (defined $url && defined $rev && defined $uuid) {
366
+ my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs);
367
+ unless ($gs) {
368
die "Unable to determine upstream SVN information from ",
369
"$head history\n";
370
}
372
- my $gs = Git::SVN->find_by_url($url);
371
+ my $c = $refs[-1];
372
my $last_rev;
373
foreach my $d (@refs) {
374
if (!verify_ref("$d~1")) {
@@ -431,16 +430,11 @@ sub cmd_dcommit {
430
431
sub cmd_rebase {
432
command_noisy(qw/update-index --refresh/);
434
- my $url = (working_head_info('HEAD'))[0];
435
- if (!defined $url) {
433
+ my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
434
+ unless ($gs) {
435
die "Unable to determine upstream SVN information from ",
436
"working tree history\n";
437
}
439
-
440
- my $gs = Git::SVN->find_by_url($url);
441
- unless ($gs) {
442
- die "Unable to determine remote information from URL: $url\n";
443
- }
438
if (command(qw/diff-index HEAD --/)) {
439
print STDERR "Cannot rebase with uncommited changes:\n";
440
command_noisy('status');
@@ -453,8 +447,8 @@ sub cmd_rebase {
447
}
448
449
sub cmd_show_ignore {
456
- my $url = (::working_head_info('HEAD'))[0];
457
- my $gs = Git::SVN->find_by_url($url) || Git::SVN->new;
450
+ my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
451
+ $gs ||= Git::SVN->new;
452
my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
453
$gs->traverse_ignore(\*STDOUT, $gs->{path}, $r);
454
}
@@ -776,16 +770,23 @@ sub cmt_metadata {
770
771
sub working_head_info {
772
my ($head, $refs) = @_;
779
- my ($url, $rev, $uuid);
773
my ($fh, $ctx) = command_output_pipe('rev-list', $head);
774
while (<$fh>) {
775
chomp;
783
- ($url, $rev, $uuid) = cmt_metadata($_);
784
- last if (defined $url && defined $rev && defined $uuid);
776
+ my ($url, $rev, $uuid) = cmt_metadata($_);
777
+ if (defined $url && defined $rev) {
778
+ if (my $gs = Git::SVN->find_by_url($url)) {
779
+ my $c = $gs->rev_db_get($rev);
780
+ if ($c && $c eq $_) {
781
+ close $fh; # break the pipe
782
+ return ($url, $rev, $uuid, $gs);
783
+ }
784
+ }
785
+ }
786
unshift @$refs, $_ if $refs;
787
}
787
- close $fh; # break the pipe
788
- ($url, $rev, $uuid);
788
+ command_close_pipe($fh, $ctx);
789
+ (undef, undef, undef, undef);
790
}
791
792
package Git::SVN;
@@ -3321,8 +3322,8 @@ sub git_svn_log_cmd {
3322
last;
3323
}
3324
3324
- my $url = (::working_head_info($head))[0];
3325
- my $gs = Git::SVN->find_by_url($url) || Git::SVN->_new;
3325
+ my ($url, $rev, $uuid, $gs) = ::working_head_info($head);
3326
+ $gs ||= Git::SVN->_new;
3327
my @cmd = (qw/log --abbrev-commit --pretty=raw --default/,
3328
$gs->refname);
3329
push @cmd, '-r' unless $non_recursive;