Skip to content

Commit 2303de6

Browse files
authored
add git commit date and SHA-1 hash to volume metadata (#410)
1 parent 392ed86 commit 2303de6

File tree

10 files changed

+44
-15
lines changed

10 files changed

+44
-15
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/UnidocDB/Volumes/Unidoc.VolumeMetadata.NameFields.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension Unidoc.VolumeMetadata
1515
projection[.id] = true
1616
projection[.package] = true
1717
projection[.version] = true
18-
projection[.refname] = true
18+
projection[.commit_name] = true
1919
projection[.display] = true
2020
projection[.latest] = true
2121
projection[.realm] = true

Sources/UnidocDB/Volumes/Unidoc.VolumeMetadata.StoredFields.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ extension Unidoc.VolumeMetadata
1717
projection[.package] = true
1818
projection[.version] = true
1919
projection[.display] = true
20-
projection[.refname] = true
20+
projection[.commit_name] = true
21+
projection[.commit_sha1] = true
22+
projection[.commit_date] = true
2123
projection[.patch] = true
2224

2325
// TODO: we only need this for top-level queries and

Sources/UnidocLinker/Unidoc.LinkerContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ extension Unidoc.LinkerContext
111111
let metadata:Unidoc.VolumeMetadata = .init(id: self.current.id,
112112
dependencies: boundaries.map(\.target),
113113
display: self.current.metadata.display,
114-
refname: self.current.metadata.commit?.name,
114+
commit: self.current.metadata.commit,
115115
symbol: volume,
116116
latest: self.current.id == latestRelease,
117117
realm: realm,

Sources/UnidocQueryTests/VolumeQueries.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct VolumeQueries:Unidoc.TestBattery
8282

8383
#expect(output.canonicalVolume?.patch == .v(0, 2, 0))
8484
#expect(output.principalVolume.patch == nil)
85-
#expect(output.principalVolume.refname == "1.0.0-beta.1")
85+
#expect(output.principalVolume.commit?.name == "1.0.0-beta.1")
8686
#expect(output.principalVertex?.landing != nil)
8787
}
8888
}

Sources/UnidocRecords/Volumes/Metadata/Unidoc.VolumeMetadata.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension Unidoc
1818
public
1919
var display:String?
2020
public
21-
var refname:String?
21+
var commit:SymbolGraphMetadata.Commit?
2222

2323
public
2424
var symbol:Symbol.Volume
@@ -42,7 +42,7 @@ extension Unidoc
4242
init(id:Unidoc.Edition,
4343
dependencies:[Dependency] = [],
4444
display:String? = nil,
45-
refname:String? = nil,
45+
commit:SymbolGraphMetadata.Commit? = nil,
4646
symbol:Symbol.Volume,
4747
latest:Bool,
4848
realm:Unidoc.Realm?,
@@ -55,7 +55,7 @@ extension Unidoc
5555
self.id = id
5656
self.dependencies = dependencies
5757
self.display = display
58-
self.refname = refname
58+
self.commit = commit
5959
self.symbol = symbol
6060
self.latest = latest
6161
self.realm = realm
@@ -91,7 +91,9 @@ extension Unidoc.VolumeMetadata
9191
/// This is currently copied verbatim from the symbol graph archive, but it is expected
9292
/// to match (and duplicate) the refname in the associated ``Unidoc.EditionMetadata``
9393
/// record.
94-
case refname = "G"
94+
case commit_name = "G"
95+
case commit_sha1 = "M"
96+
case commit_date = "N"
9597

9698
@available(*, unavailable)
9799
case commit = "H"
@@ -139,7 +141,9 @@ extension Unidoc.VolumeMetadata:BSONDocumentEncodable
139141
bson[.version] = self.symbol.version
140142

141143
bson[.display] = self.display
142-
bson[.refname] = self.refname
144+
bson[.commit_name] = self.commit?.name
145+
bson[.commit_sha1] = self.commit?.sha1
146+
bson[.commit_date] = self.commit?.date
143147

144148
bson[.latest] = self.latest ? true : nil
145149
bson[.realm] = self.realm
@@ -162,10 +166,22 @@ extension Unidoc.VolumeMetadata:BSONDocumentDecodable
162166
@inlinable public
163167
init(bson:BSON.DocumentDecoder<CodingKey>) throws
164168
{
169+
let commit:SymbolGraphMetadata.Commit?
170+
if let name:String = try bson[.commit_name]?.decode()
171+
{
172+
commit = .init(name: name,
173+
sha1: try bson[.commit_sha1]?.decode(),
174+
date: try bson[.commit_date]?.decode())
175+
}
176+
else
177+
{
178+
commit = nil
179+
}
180+
165181
self.init(id: try bson[.id].decode(),
166182
dependencies: try bson[.dependencies]?.decode() ?? [],
167183
display: try bson[.display]?.decode(),
168-
refname: try bson[.refname]?.decode(),
184+
commit: commit,
169185
symbol: .init(
170186
package: try bson[.package].decode(),
171187
version: try bson[.version].decode()),

Sources/UnidocRecords/Volumes/Vertices/Unidoc.SnapshotDetails.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ extension Unidoc
2121
/// `Package.swift` manifest.
2222
public
2323
var requirements:[SymbolGraphMetadata.PlatformRequirement]
24+
25+
/// TODO: we get this from the Volume Metadata instead.
2426
/// The git commit hash from the symbol graph metadata.
2527
public
2628
var commit:SHA1?

Sources/UnidocUI/Endpoints/Docs/Unidoc.DocsEndpoint.PackagePage.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Symbols
99
import Unidoc
1010
import UnidocDB
1111
import UnidocRecords
12+
import UnixCalendar
1213
import UnixTime
1314
import URI
1415

@@ -99,7 +100,7 @@ extension Unidoc.DocsEndpoint.PackagePage:Unidoc.ApicalPage
99100
$0[.div]
100101
{
101102
$0.class = "chyron"
102-
} = repo.chyron(now: format.time, ref: self.volume.refname)
103+
} = repo.chyron(now: format.time, ref: self.volume.commit?.name)
103104
}
104105

105106
main[.section] { $0.class = "notice canonical" } = self.context.canonical
@@ -231,7 +232,9 @@ extension Unidoc.DocsEndpoint.PackagePage:Unidoc.ApicalPage
231232
}
232233
}
233234

234-
if let commit:SHA1 = self.apex.snapshot.commit
235+
// TODO: we shouldn’t need the SnapshotDetails for this, after uplinking all
236+
// the volume metadata.
237+
if let commit:SHA1 = self.volume.commit?.sha1 ?? self.apex.snapshot.commit
235238
{
236239
$0[.dt] = "Git revision"
237240
$0[.dd]
@@ -249,6 +252,12 @@ extension Unidoc.DocsEndpoint.PackagePage:Unidoc.ApicalPage
249252
$0[link: url] { $0.external(safe: false) } = "\(commit)"
250253
}
251254
}
255+
if let date:UnixMillisecond = self.volume.commit?.date,
256+
let date:Timestamp = date.timestamp
257+
{
258+
$0[.dt] = "Git commit date"
259+
$0[.dd] = "\(date.http)"
260+
}
252261
}
253262

254263
main[.div] { $0.class = "more" } = Unidoc.StatsThumbnail.init(

Sources/UnidocUI/Page contexts/Unidoc.IdentifiablePageContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension Unidoc
4040
var media:PackageMedia = packages.principal?.media ?? .init()
4141
if let repo:PackageRepo = packages.principal?.repo
4242
{
43-
let ref:String = principal.refname ?? repo.master ?? "master"
43+
let ref:String = principal.commit?.name ?? repo.master ?? "master"
4444
let path:String
4545
switch repo.origin
4646
{

Sources/UnidocUI/Page contexts/Unidoc.VertexContext (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension Unidoc.VertexContext
6767
func link(source file:Unidoc.Scalar, line:Int? = nil) -> Unidoc.SourceLink?
6868
{
6969
guard
70-
let refname:String = self[file.edition]?.refname,
70+
let refname:String = self[file.edition]?.commit?.name,
7171
let vertex:Unidoc.FileVertex = self.vertices[file]?.vertex.file,
7272
let origin:Unidoc.PackageOrigin = self.repo?.origin
7373
else

0 commit comments

Comments
 (0)