git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Eric Wong <normalperson@yhbt.net>
Cc: git@vger.kernel.org, Gustav Munkby <grddev@gmail.com>,
	Edward Rudd <urkle@outoforder.cc>, Carsten Bormann <cabo@tzi.org>
Subject: Re: [PATCH 1/2] git-svn: use platform specific auth providers
Date: Mon, 30 Apr 2012 18:08:29 -0700	[thread overview]
Message-ID: <7vy5pcd7xu.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20120430192016.GQ4023@login.drsnuggles.stderr.nl> (Matthijs Kooijman's message of "Mon, 30 Apr 2012 21:20:16 +0200")

Matthijs Kooijman <matthijs@stdin.nl> writes:

> Hi Eric,
>
>> > This does textual comparison, so 1.6.6 > 1.6.12. To do proper version
>> > comparison, I think the version numbers should be split into
>> > major/minor/revision and each be compared numerically.
>> 
>> Ah, thanks for the analysis, we were lucky in the past that all version
>> components only had a single character.
> Indeed. Note that this includes the released subversion versions. For
> example, the code contains this check:
>
>     $SVN::Core::VERSION le '1.5.4'
>
> and 1.5.10 < 1.5.4. Fortunately, 1.5.9 was the last release in the 1.5
> series, and no other checks compare against 1.6.x.
>
> If subversion would ever reach the 1.10.x version number, things would
> also start breaking.
>
>> I think the former is preferable for git.  Sort::Versions isn't used
>> anywhere else in git and I don't think it's widely installed.

Ok, something along the lines of this.  Perhaps instead of "compare_",
we may want to call it "require_", so that negative return maps naturally
to a failure.

diff --git a/git-svn.perl b/git-svn.perl
index 427da9e..4a2ec43 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -41,11 +41,28 @@ sub fatal (@) { print STDERR "@_\n"; exit 1 }
 # repository decides to close the connection which we expect to be kept alive.
 $SIG{PIPE} = 'IGNORE';
 
+# Given a dot separated version number, "subtract" it from
+# the SVN::Core::VERSION; non-negaitive return means the SVN::Core
+# is at least at the version the caller asked for.
+sub compare_svn_version {
+	my (@ours) = split(/\./, $SVN::Core::VERSION);
+	my (@theirs) = split(/\./, $_[0]);
+	my ($i, $diff);
+
+	for ($i = 0; $i < @ours && $i < @theirs; $i++) {
+		$diff = $ours[$i] - $theirs[$i];
+		return $diff if ($diff);
+	}
+	return 1 if ($i < @ours);
+	return -1 if ($i < @theirs);
+	return 0;
+}
+
 sub _req_svn {
 	require SVN::Core; # use()-ing this causes segfaults for me... *shrug*
 	require SVN::Ra;
 	require SVN::Delta;
-	if ($SVN::Core::VERSION lt '1.1.0') {
+	if (compare_svn_version('1.1.0') < 0) {
 		fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
 	}
 }
@@ -1474,7 +1491,7 @@ sub cmd_info {
 	}
 	::_req_svn();
 	$result .= "Repository UUID: $uuid\n" unless $diff_status eq "A" &&
-		($SVN::Core::VERSION le '1.5.4' || $file_type ne "dir");
+		(compare_svn_version('1.5.4') <= 0 || $file_type ne "dir");
 	$result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
 
 	$result .= "Node Kind: " .
@@ -5464,7 +5481,7 @@ sub _auth_providers () {
 
 	# earlier 1.6.x versions would segfault, and <= 1.5.x didn't have
 	# this function
-	if ($SVN::Core::VERSION gt '1.6.12') {
+	if (compare_svn_version('1.6.12') > 0) {
 		my $config = SVN::Core::config_get_config($config_dir);
 		my ($p, @a);
 		# config_get_config returns all config files from
@@ -5623,7 +5640,7 @@ sub get_log {
 	# drop it.  Therefore, the receiver callback passed to it
 	# is made aware of this limitation by being wrapped if
 	# the limit passed to is being wrapped.
-	if ($SVN::Core::VERSION le '1.2.0') {
+	if (compare_svn_version('1.2.0') <= 0) {
 		my $limit = splice(@args, 3, 1);
 		if ($limit > 0) {
 			my $receiver = pop @args;
@@ -5655,7 +5672,8 @@ sub trees_match {
 
 sub get_commit_editor {
 	my ($self, $log, $cb, $pool) = @_;
-	my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : ();
+	
+	my @lock = (compare_svn_version('1.2.0') >= 0) ? (undef, 0) : ();
 	$self->SUPER::get_commit_editor($log, $cb, @lock, $pool);
 }
 
@@ -5673,7 +5691,7 @@ sub gs_do_update {
 	my (@pc) = split m#/#, $path;
 	my $reporter = $self->do_update($rev_b, (@pc ? shift @pc : ''),
 	                                1, $editor, $pool);
-	my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
+	my @lock = (compare_svn_version('1.2.0') >= 0) ? (undef) : ();
 
 	# Since we can't rely on svn_ra_reparent being available, we'll
 	# just have to do some magic with set_path to make it so
@@ -5723,7 +5741,7 @@ sub gs_do_switch {
 	$ra ||= $self;
 	$url_b = escape_url($url_b);
 	my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
-	my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
+	my @lock = (compare_svn_version('1.2.0') >= 0) ? (undef) : ();
 	$reporter->set_path('', $rev_a, 0, @lock, $pool);
 	$reporter->finish_report($pool);
 

  reply	other threads:[~2012-05-01  1:08 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-18  0:36 git-svn won't remember pem password Igor
2012-02-18 11:30 ` Jakub Narebski
2012-02-19  4:03   ` Nikolaus Demmel
2012-02-20  0:57   ` Jeff King
2012-02-20  3:08     ` Nikolaus Demmel
2012-02-19  1:30 ` Eric Wong
2012-04-26 18:00   ` Matthijs Kooijman
     [not found]     ` <41A093CB-CA4A-4FEF-9F5C-A9B626D10AFB@gmail.com>
     [not found]       ` <20120426181327.GZ4023@login.drsnuggles.stderr.nl>
2012-04-26 18:31         ` Igor
2012-04-26 18:36           ` Matthijs Kooijman
2012-04-26 19:34             ` [PATCH 1/2] git-svn: use platform specific auth providers Matthijs Kooijman
2012-04-26 19:34               ` [PATCH 2/2] git-svn: Configure a prompt callback for gnome_keyring Matthijs Kooijman
2012-04-27  8:28                 ` Eric Wong
2012-04-27  9:36                   ` Matthijs Kooijman
2013-06-18 16:36                   ` Matthijs Kooijman
2013-06-18 16:38                     ` [PATCH] " Matthijs Kooijman
2013-08-29  9:42                       ` Matthijs Kooijman
2013-08-29 17:38                         ` Eric Wong
     [not found]                           ` <35AE7D09-F859-4277-AC74-729BA1188D10@outoforder.cc>
2013-08-29 17:56                             ` Eric Wong
2012-04-27  8:29                 ` [PATCH 2/2] " Matthijs Kooijman
2012-04-27  8:21               ` [PATCH 1/2] git-svn: use platform specific auth providers Eric Wong
2012-04-27  8:25                 ` Matthijs Kooijman
2012-04-29  8:23                   ` Eric Wong
2012-04-30  0:03                     ` Junio C Hamano
2012-04-30  1:21                       ` Junio C Hamano
2012-04-30  8:19                         ` Eric Wong
2012-04-30 16:04                           ` Junio C Hamano
2012-04-30 16:53                             ` Matthijs Kooijman
2012-04-30 19:02                               ` Eric Wong
2012-04-30 19:20                                 ` Matthijs Kooijman
2012-05-01  1:08                                   ` Junio C Hamano [this message]
2012-06-03 10:49                                     ` Charles Bailey
2012-06-03 21:44                                       ` Junio C Hamano
2012-06-04  9:00                                         ` Matthijs Kooijman
2012-06-04 19:26                                           ` Junio C Hamano
2012-06-04 19:36                                             ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vy5pcd7xu.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=cabo@tzi.org \
    --cc=git@vger.kernel.org \
    --cc=grddev@gmail.com \
    --cc=normalperson@yhbt.net \
    --cc=urkle@outoforder.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).