Skip to content

Commit 13c823f

Browse files
Eric WongJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 512b620 commit 13c823f

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

git-svn.perl

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,12 @@ sub cmd_dcommit {
363363
my $head = shift;
364364
$head ||= 'HEAD';
365365
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) {
369368
die "Unable to determine upstream SVN information from ",
370369
"$head history\n";
371370
}
372-
my $gs = Git::SVN->find_by_url($url);
371+
my $c = $refs[-1];
373372
my $last_rev;
374373
foreach my $d (@refs) {
375374
if (!verify_ref("$d~1")) {
@@ -431,16 +430,11 @@ sub cmd_dcommit {
431430

432431
sub cmd_rebase {
433432
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) {
436435
die "Unable to determine upstream SVN information from ",
437436
"working tree history\n";
438437
}
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-
}
444438
if (command(qw/diff-index HEAD --/)) {
445439
print STDERR "Cannot rebase with uncommited changes:\n";
446440
command_noisy('status');
@@ -453,8 +447,8 @@ sub cmd_rebase {
453447
}
454448

455449
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;
458452
my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
459453
$gs->traverse_ignore(\*STDOUT, $gs->{path}, $r);
460454
}
@@ -776,16 +770,23 @@ sub cmt_metadata {
776770

777771
sub working_head_info {
778772
my ($head, $refs) = @_;
779-
my ($url, $rev, $uuid);
780773
my ($fh, $ctx) = command_output_pipe('rev-list', $head);
781774
while (<$fh>) {
782775
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+
}
785786
unshift @$refs, $_ if $refs;
786787
}
787-
close $fh; # break the pipe
788-
($url, $rev, $uuid);
788+
command_close_pipe($fh, $ctx);
789+
(undef, undef, undef, undef);
789790
}
790791

791792
package Git::SVN;
@@ -3321,8 +3322,8 @@ sub git_svn_log_cmd {
33213322
last;
33223323
}
33233324

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;
33263327
my @cmd = (qw/log --abbrev-commit --pretty=raw --default/,
33273328
$gs->refname);
33283329
push @cmd, '-r' unless $non_recursive;

0 commit comments

Comments
 (0)