Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa27120

Browse files
committed
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
1 parent 9b5558e commit aa27120

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/test/perl/PostgresVersion.pm

+18-18
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,24 @@ sub new
7979
# postgres command line tool
8080
my $devel;
8181
($arg,$devel) = ($1, $2)
82-
if ($arg =~ m/^(?:\(?PostgreSQL\)? )?(\d+(?:\.\d+)*)(devel)?/);
82+
if ($arg =~
83+
m!^ # beginning of line
84+
(?:\(?PostgreSQL\)?\s)? # ignore PostgreSQL marker
85+
(\d+(?:\.\d+)*) # version number, dotted notation
86+
(devel|(?:alpha|beta|rc)\d+)? # dev marker - see version_stamp.pl
87+
!x);
8388

8489
# Split into an array
85-
my @result = split(/\./, $arg);
90+
my @numbers = split(/\./, $arg);
8691

8792
# Treat development versions as having a minor/micro version one less than
8893
# the first released version of that branch.
89-
push @result, -1 if ($devel);
94+
push @numbers, -1 if ($devel);
9095

91-
return bless \@result, $class;
92-
}
96+
$devel ||= "";
9397

98+
return bless { str => "$arg$devel", num => \@numbers }, $class;
99+
}
94100

95101
# Routine which compares the _pg_version_array obtained for the two
96102
# arguments and returns -1, 0, or 1, allowing comparison between two
@@ -108,27 +114,21 @@ sub _version_cmp
108114

109115
$b = __PACKAGE__->new($b) unless blessed($b);
110116

117+
my ($an, $bn) = ($a->{num}, $b->{num});
118+
111119
for (my $idx = 0;; $idx++)
112120
{
113-
return 0 unless (defined $a->[$idx] && defined $b->[$idx]);
114-
return $a->[$idx] <=> $b->[$idx]
115-
if ($a->[$idx] <=> $b->[$idx]);
121+
return 0 unless (defined $an->[$idx] && defined $bn->[$idx]);
122+
return $an->[$idx] <=> $bn->[$idx]
123+
if ($an->[$idx] <=> $bn->[$idx]);
116124
}
117125
}
118126

119-
# Render the version number in the standard "joined by dots" notation if
120-
# interpolated into a string. Put back 'devel' if we previously turned it
121-
# into a -1.
127+
# Render the version number using the saved string.
122128
sub _stringify
123129
{
124130
my $self = shift;
125-
my @sections = @$self;
126-
if ($sections[-1] == -1)
127-
{
128-
pop @sections;
129-
$sections[-1] = "$sections[-1]devel";
130-
}
131-
return join('.', @sections);
131+
return $self->{str};
132132
}
133133

134134
1;

0 commit comments

Comments
 (0)