Skip to content

Commit f760c90

Browse files
gitsterEric Wong
authored andcommitted
git-svn: introduce SVN version comparison function
With double-digit version components in SVN::Core::VERSION, a naive string comparison is no longer sufficient and a numeric comparison is required for correct results. This fixes a regression introduced in commit 082afee ("git-svn: use platform specific auth providers") where SVN version "1.6.6" was incorrectly assumed to be newer than the required "1.6.12" version. [mk: fix namespace references] [ew: commit message] Tested-by: Matthijs Kooijman <[email protected]> Acked-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 242cab3 commit f760c90

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

git-svn.perl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,28 @@
4141
# repository decides to close the connection which we expect to be kept alive.
4242
$SIG{PIPE} = 'IGNORE';
4343

44+
# Given a dot separated version number, "subtract" it from
45+
# the SVN::Core::VERSION; non-negaitive return means the SVN::Core
46+
# is at least at the version the caller asked for.
47+
sub compare_svn_version {
48+
my (@ours) = split(/\./, $SVN::Core::VERSION);
49+
my (@theirs) = split(/\./, $_[0]);
50+
my ($i, $diff);
51+
52+
for ($i = 0; $i < @ours && $i < @theirs; $i++) {
53+
$diff = $ours[$i] - $theirs[$i];
54+
return $diff if ($diff);
55+
}
56+
return 1 if ($i < @ours);
57+
return -1 if ($i < @theirs);
58+
return 0;
59+
}
60+
4461
sub _req_svn {
4562
require SVN::Core; # use()-ing this causes segfaults for me... *shrug*
4663
require SVN::Ra;
4764
require SVN::Delta;
48-
if ($SVN::Core::VERSION lt '1.1.0') {
65+
if (::compare_svn_version('1.1.0') < 0) {
4966
fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
5067
}
5168
}
@@ -1474,7 +1491,7 @@ sub cmd_info {
14741491
}
14751492
::_req_svn();
14761493
$result .= "Repository UUID: $uuid\n" unless $diff_status eq "A" &&
1477-
($SVN::Core::VERSION le '1.5.4' || $file_type ne "dir");
1494+
(::compare_svn_version('1.5.4') <= 0 || $file_type ne "dir");
14781495
$result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
14791496

14801497
$result .= "Node Kind: " .
@@ -5464,7 +5481,7 @@ ()
54645481

54655482
# earlier 1.6.x versions would segfault, and <= 1.5.x didn't have
54665483
# this function
5467-
if ($SVN::Core::VERSION gt '1.6.12') {
5484+
if (::compare_svn_version('1.6.12') > 0) {
54685485
my $config = SVN::Core::config_get_config($config_dir);
54695486
my ($p, @a);
54705487
# config_get_config returns all config files from
@@ -5623,7 +5640,7 @@ sub get_log {
56235640
# drop it. Therefore, the receiver callback passed to it
56245641
# is made aware of this limitation by being wrapped if
56255642
# the limit passed to is being wrapped.
5626-
if ($SVN::Core::VERSION le '1.2.0') {
5643+
if (::compare_svn_version('1.2.0') <= 0) {
56275644
my $limit = splice(@args, 3, 1);
56285645
if ($limit > 0) {
56295646
my $receiver = pop @args;
@@ -5655,7 +5672,8 @@ sub trees_match {
56555672

56565673
sub get_commit_editor {
56575674
my ($self, $log, $cb, $pool) = @_;
5658-
my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : ();
5675+
5676+
my @lock = (::compare_svn_version('1.2.0') >= 0) ? (undef, 0) : ();
56595677
$self->SUPER::get_commit_editor($log, $cb, @lock, $pool);
56605678
}
56615679

@@ -5673,7 +5691,7 @@ sub gs_do_update {
56735691
my (@pc) = split m#/#, $path;
56745692
my $reporter = $self->do_update($rev_b, (@pc ? shift @pc : ''),
56755693
1, $editor, $pool);
5676-
my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
5694+
my @lock = (::compare_svn_version('1.2.0') >= 0) ? (undef) : ();
56775695

56785696
# Since we can't rely on svn_ra_reparent being available, we'll
56795697
# just have to do some magic with set_path to make it so
@@ -5723,7 +5741,7 @@ sub gs_do_switch {
57235741
$ra ||= $self;
57245742
$url_b = escape_url($url_b);
57255743
my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
5726-
my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
5744+
my @lock = (::compare_svn_version('1.2.0') >= 0) ? (undef) : ();
57275745
$reporter->set_path('', $rev_a, 0, @lock, $pool);
57285746
$reporter->finish_report($pool);
57295747

0 commit comments

Comments
 (0)