@@ -11,14 +11,16 @@ package Version;
11
11
# ************************************************************
12
12
13
13
use strict;
14
+ use File::Spec;
14
15
15
16
# ************************************************************
16
17
# Data Section
17
18
# ************************************************************
18
19
19
20
# # This is the starting major and minor version
20
- my $version = ' 4.1 ' ;
21
+ my $version = ' 5.0 ' ;
21
22
my $once = 1;
23
+ my $cache = ' modules/.version' ;
22
24
23
25
# ************************************************************
24
26
# Subroutine Section
@@ -29,30 +31,63 @@ sub get {
29
31
# # We only need to do this once
30
32
$once = 0;
31
33
32
- # # Here we determine the beta version. The base variable
33
- # # is the negated number of existing ChangeLog entries at the
34
- # # time of the release of the major and minor version. We then
35
- # # add the total number of ChangeLog entries to the base to
36
- # # get the beta version.
37
- my $base = -1;
38
- if (open (CLH, ::getBasePath() . ' /ChangeLog' )) {
39
- while (<CLH>) {
40
- if (/ ^\w\w\w\s\w\w\w\s / ) {
41
- ++$base ;
34
+ # # Attempt to dynamically determine the revision part of the version
35
+ # # string every time the version number is requested. This only happens
36
+ # # if the --version option is used, an invalid option is used, and when
37
+ # # the process starts up and the version hasn't been cached yet.
38
+ my $rev = ' ?' ;
39
+ my $cwd = Cwd::getcwd();
40
+ if (chdir (::getBasePath())) {
41
+ # # Get the git revision for the final part of the version string.
42
+ my $nul = File::Spec-> devnull();
43
+ my $r = _readVersion(" git rev-parse --short HEAD 2> $nul |" );
44
+ if (defined $r ) {
45
+ # # Store the version for later use, in the event that the git
46
+ # # revision isn't available in the future.
47
+ if (open (CLH, " >$cache " )) {
48
+ print CLH " $r \n " ;
49
+ close (CLH);
42
50
}
43
51
}
44
- close (CLH);
52
+ else {
53
+ # # See if we can load in the previously stored version string.
54
+ $r = _readVersion($cache );
55
+ }
45
56
46
- # # We then append the beta version number to the version string
47
- $version .= " .$base " ;
48
- }
49
- else {
50
- $version .= ' .??' ;
57
+ # # Set the revision string if we were able to read one.
58
+ $rev = $r if (defined $r );
59
+
60
+ chdir ($cwd );
51
61
}
62
+
63
+ # # We then append the revision to the version string.
64
+ $version .= " .$rev " ;
52
65
}
53
66
54
67
return $version ;
55
68
}
56
69
70
+ sub cache {
71
+ # # Attempt to cache the revision if the cache file does not exist.
72
+ # # This will allow the revision to be obtained in the event that git
73
+ # # cannot return the revision information at a later time.
74
+ get() if (!-e ::getBasePath() . ' /' . $cache );
75
+ }
57
76
58
77
1;
78
+
79
+ sub _readVersion {
80
+ my $file = shift ;
81
+ my $rev ;
82
+ if (open (CLH, $file )) {
83
+ while (<CLH>) {
84
+ if (/ ^(\w +)$ / ) {
85
+ $rev = $1 ;
86
+ last ;
87
+ }
88
+ }
89
+ close (CLH);
90
+ }
91
+ return $rev ;
92
+ }
93
+
0 commit comments