@@ -11,21 +11,67 @@ struct PackageEdition:Identifiable, Equatable, Sendable
11
11
public
12
12
let id : Unidoc . Zone
13
13
14
+ /// Whether or not this edition is a release.
15
+ public
16
+ var release : Bool
17
+ /// The patch version associated with this edition. This might not be trivially-computable
18
+ /// from the ``name`` property, for example, `5.9.0` from `swift-5.9-RELEASE`.
19
+ public
20
+ var patch : PatchVersion
21
+
14
22
/// The exact ref name associated with this edition.
15
23
public
16
- let name : String
24
+ var name : String
17
25
/// The SHA-1 hash of the git commit associated with this edition.
18
26
public
19
- let sha1 : SHA1 ?
27
+ var sha1 : SHA1 ?
20
28
/// Indicates if the repository host has published a tag of the same name with a different
21
29
/// ``sha1`` hash.
22
30
public
23
- let lost : Bool
31
+ var lost : Bool
24
32
25
33
@inlinable public
26
- init ( id: Unidoc . Zone , name: String , sha1: SHA1 ? , lost: Bool = false )
34
+ init ( id: Unidoc . Zone ,
35
+ release: Bool ? ,
36
+ patch: PatchVersion ? ,
37
+ name: String ,
38
+ sha1: SHA1 ? ,
39
+ lost: Bool = false )
27
40
{
28
41
self . id = id
42
+
43
+ // Temporary HACK until we can migrate all the database records.
44
+ self . release = release ?? true
45
+ if let patch: PatchVersion
46
+ {
47
+ self . patch = patch
48
+ }
49
+ else if name == " swift-5.8.1-RELEASE "
50
+ {
51
+ self . patch = . v( 5 , 8 , 1 )
52
+ }
53
+ else if name == " swift-5.9-RELEASE "
54
+ {
55
+ self . patch = . v( 5 , 9 , 0 )
56
+ }
57
+ else
58
+ {
59
+ switch SemanticVersion . init ( refname: name)
60
+ {
61
+ case . release( let version, build: _) ? :
62
+ self . release = true
63
+ self . patch = version
64
+
65
+ case . prerelease( let version, _, build: _) ? :
66
+ self . release = false
67
+ self . patch = version
68
+
69
+ case nil :
70
+ fatalError ( " can’t infer patch version from refname: \( name) " )
71
+ }
72
+ }
73
+ // End temporary HACK.
74
+
29
75
self . name = name
30
76
self . sha1 = sha1
31
77
self . lost = lost
@@ -66,22 +112,8 @@ extension PackageEdition:BSONDocumentEncodable
66
112
bson [ . package ] = self . id. package
67
113
bson [ . version] = self . id. version
68
114
69
- /// Parses and returns this edition's refname as a semantic version. If the refname
70
- /// looks like a semantic version, this will strip leading `v`’s, and zero-extend the
71
- /// patch number.
72
- switch SemanticVersion . init ( refname: self . name)
73
- {
74
- case . release( let version, build: _) ? :
75
- bson [ . release] = true
76
- bson [ . patch] = version
77
-
78
- case . prerelease( let version, _, build: _) ? :
79
- bson [ . release] = false
80
- bson [ . patch] = version
81
-
82
- case nil :
83
- break
84
- }
115
+ bson [ . release] = self . release
116
+ bson [ . patch] = self . patch
85
117
86
118
bson [ . name] = self . name
87
119
bson [ . sha1] = self . sha1
@@ -94,6 +126,8 @@ extension PackageEdition:BSONDocumentDecodable
94
126
init ( bson: BSON . DocumentDecoder < CodingKey , some RandomAccessCollection < UInt8 > > ) throws
95
127
{
96
128
self . init ( id: try bson [ . id] . decode ( ) ,
129
+ release: try bson [ . release] ? . decode ( ) ,
130
+ patch: try bson [ . patch] ? . decode ( ) ,
97
131
name: try bson [ . name] . decode ( ) ,
98
132
sha1: try bson [ . sha1] ? . decode ( ) ,
99
133
lost: try bson [ . lost] ? . decode ( ) ?? false )
0 commit comments