mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Teach PostgresVersion all the ways to mark non-release code
As well as 'devel' version_stamp.pl provides for 'alphaN' 'betaN' and 'rcN', so teach PostgresVersion about those. Also stash the version string instead of trying to reconstruct it during stringification. Discussion: https://postgr.es/m/YIHlw5nSgAHs4dK1@paquier.xyz
This commit is contained in:
@ -79,19 +79,25 @@ sub new
|
|||||||
# postgres command line tool
|
# postgres command line tool
|
||||||
my $devel;
|
my $devel;
|
||||||
($arg,$devel) = ($1, $2)
|
($arg,$devel) = ($1, $2)
|
||||||
if ($arg =~ m/^(?:\(?PostgreSQL\)? )?(\d+(?:\.\d+)*)(devel)?/);
|
if ($arg =~
|
||||||
|
m!^ # beginning of line
|
||||||
|
(?:\(?PostgreSQL\)?\s)? # ignore PostgreSQL marker
|
||||||
|
(\d+(?:\.\d+)*) # version number, dotted notation
|
||||||
|
(devel|(?:alpha|beta|rc)\d+)? # dev marker - see version_stamp.pl
|
||||||
|
!x);
|
||||||
|
|
||||||
# Split into an array
|
# Split into an array
|
||||||
my @result = split(/\./, $arg);
|
my @numbers = split(/\./, $arg);
|
||||||
|
|
||||||
# Treat development versions as having a minor/micro version one less than
|
# Treat development versions as having a minor/micro version one less than
|
||||||
# the first released version of that branch.
|
# the first released version of that branch.
|
||||||
push @result, -1 if ($devel);
|
push @numbers, -1 if ($devel);
|
||||||
|
|
||||||
return bless \@result, $class;
|
$devel ||= "";
|
||||||
|
|
||||||
|
return bless { str => "$arg$devel", num => \@numbers }, $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Routine which compares the _pg_version_array obtained for the two
|
# Routine which compares the _pg_version_array obtained for the two
|
||||||
# arguments and returns -1, 0, or 1, allowing comparison between two
|
# arguments and returns -1, 0, or 1, allowing comparison between two
|
||||||
# PostgresVersion objects or a PostgresVersion and a version string or number.
|
# PostgresVersion objects or a PostgresVersion and a version string or number.
|
||||||
@ -108,27 +114,21 @@ sub _version_cmp
|
|||||||
|
|
||||||
$b = __PACKAGE__->new($b) unless blessed($b);
|
$b = __PACKAGE__->new($b) unless blessed($b);
|
||||||
|
|
||||||
|
my ($an, $bn) = ($a->{num}, $b->{num});
|
||||||
|
|
||||||
for (my $idx = 0;; $idx++)
|
for (my $idx = 0;; $idx++)
|
||||||
{
|
{
|
||||||
return 0 unless (defined $a->[$idx] && defined $b->[$idx]);
|
return 0 unless (defined $an->[$idx] && defined $bn->[$idx]);
|
||||||
return $a->[$idx] <=> $b->[$idx]
|
return $an->[$idx] <=> $bn->[$idx]
|
||||||
if ($a->[$idx] <=> $b->[$idx]);
|
if ($an->[$idx] <=> $bn->[$idx]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Render the version number in the standard "joined by dots" notation if
|
# Render the version number using the saved string.
|
||||||
# interpolated into a string. Put back 'devel' if we previously turned it
|
|
||||||
# into a -1.
|
|
||||||
sub _stringify
|
sub _stringify
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my @sections = @$self;
|
return $self->{str};
|
||||||
if ($sections[-1] == -1)
|
|
||||||
{
|
|
||||||
pop @sections;
|
|
||||||
$sections[-1] = "$sections[-1]devel";
|
|
||||||
}
|
|
||||||
return join('.', @sections);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Reference in New Issue
Block a user