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 082afee621aeb2d3746c8ae290af98823f981f34 ("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 <matthijs@stdin.nl> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 2, 2012 at 19:53 UTC
f760c903b8525878cd3b426fc61a7a2cf8742609
1 file changed
+25
-7
git-svn.perl
+25
-7
@@ -41,11 +41,28 @@ sub fatal (@) { print STDERR "@_\n"; exit 1 }
41
# repository decides to close the connection which we expect to be kept alive.
42
$SIG{PIPE} = 'IGNORE';
43
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
+
61
sub _req_svn {
62
require SVN::Core; # use()-ing this causes segfaults for me... *shrug*
63
require SVN::Ra;
64
require SVN::Delta;
48
- if ($SVN::Core::VERSION lt '1.1.0') {
65
+ if (::compare_svn_version('1.1.0') < 0) {
66
fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
67
}
68
}
@@ -1474,7 +1491,7 @@ sub cmd_info {
1491
}
1492
::_req_svn();
1493
$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");
1495
$result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
1496
1497
$result .= "Node Kind: " .
@@ -5464,7 +5481,7 @@ sub _auth_providers () {
5481
5482
# earlier 1.6.x versions would segfault, and <= 1.5.x didn't have
5483
# this function
5467
- if ($SVN::Core::VERSION gt '1.6.12') {
5484
+ if (::compare_svn_version('1.6.12') > 0) {
5485
my $config = SVN::Core::config_get_config($config_dir);
5486
my ($p, @a);
5487
# config_get_config returns all config files from
@@ -5623,7 +5640,7 @@ sub get_log {
5640
# drop it. Therefore, the receiver callback passed to it
5641
# is made aware of this limitation by being wrapped if
5642
# 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) {
5644
my $limit = splice(@args, 3, 1);
5645
if ($limit > 0) {
5646
my $receiver = pop @args;
@@ -5655,7 +5672,8 @@ sub trees_match {
5672
5673
sub get_commit_editor {
5674
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) : ();
5677
$self->SUPER::get_commit_editor($log, $cb, @lock, $pool);
5678
}
5679
@@ -5673,7 +5691,7 @@ sub gs_do_update {
5691
my (@pc) = split m#/#, $path;
5692
my $reporter = $self->do_update($rev_b, (@pc ? shift @pc : ''),
5693
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) : ();
5695
5696
# Since we can't rely on svn_ra_reparent being available, we'll
5697
# just have to do some magic with set_path to make it so
@@ -5723,7 +5741,7 @@ sub gs_do_switch {
5741
$ra ||= $self;
5742
$url_b = escape_url($url_b);
5743
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) : ();
5745
$reporter->set_path('', $rev_a, 0, @lock, $pool);
5746
$reporter->finish_report($pool);
5747