summaryrefslogtreecommitdiff
path: root/Hutch/Models
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-03-18 19:28:42 -0500
committerChristian Cleberg <[email protected]>2026-03-18 19:28:42 -0500
commitbb8fae4d1145266de4f5117a3b8c48f2ccacb0be (patch)
tree2b4ce5b2a114c5df60aa20db07ad1d38f426e59d /Hutch/Models
parente07b4a28d6ac6086e5b652f72b9089e4d06f7e80 (diff)
downloadhutch-bb8fae4d1145266de4f5117a3b8c48f2ccacb0be.tar.gz
hutch-bb8fae4d1145266de4f5117a3b8c48f2ccacb0be.tar.bz2
hutch-bb8fae4d1145266de4f5117a3b8c48f2ccacb0be.zip
lazily load file blobs from repository tree views
Diffstat (limited to 'Hutch/Models')
-rw-r--r--Hutch/Models/Git.swift19
1 files changed, 11 insertions, 8 deletions
diff --git a/Hutch/Models/Git.swift b/Hutch/Models/Git.swift
index 19ec31b..905822e 100644
--- a/Hutch/Models/Git.swift
+++ b/Hutch/Models/Git.swift
@@ -113,7 +113,7 @@ struct GitTree: Codable, Sendable {
struct GitTextBlob: Codable, Sendable {
let id: String?
let shortId: String?
- let text: String
+ let text: String?
let size: Int?
}
@@ -134,14 +134,16 @@ struct GitTreeEntryPage: Codable, Sendable {
extension GitObject: Codable {
private enum CodingKeys: String, CodingKey {
case type, id, shortId, entries, text, size, content
+ case typename = "__typename"
}
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decodeIfPresent(String.self, forKey: .type)
+ let typename = try container.decodeIfPresent(String.self, forKey: .typename)
- switch type {
- case "TREE":
+ switch type ?? typename {
+ case "TREE", "Tree":
let tree = GitTree(
id: try container.decodeIfPresent(String.self, forKey: .id),
shortId: try container.decodeIfPresent(String.self, forKey: .shortId),
@@ -149,13 +151,12 @@ extension GitObject: Codable {
)
self = .tree(tree)
- case "BLOB":
- // TextBlob has a "text" key; BinaryBlob does not
- if container.contains(.text) {
+ case "BLOB", "TextBlob", "BinaryBlob":
+ if typename == "TextBlob" || container.contains(.text) {
let blob = GitTextBlob(
id: try container.decodeIfPresent(String.self, forKey: .id),
shortId: try container.decodeIfPresent(String.self, forKey: .shortId),
- text: try container.decode(String.self, forKey: .text),
+ text: try container.decodeIfPresent(String.self, forKey: .text),
size: try container.decodeIfPresent(Int.self, forKey: .size)
)
self = .textBlob(blob)
@@ -184,12 +185,14 @@ extension GitObject: Codable {
try container.encodeIfPresent(tree.entries, forKey: .entries)
case .textBlob(let blob):
try container.encode("BLOB", forKey: .type)
+ try container.encode("TextBlob", forKey: .typename)
try container.encodeIfPresent(blob.id, forKey: .id)
try container.encodeIfPresent(blob.shortId, forKey: .shortId)
- try container.encode(blob.text, forKey: .text)
+ try container.encodeIfPresent(blob.text, forKey: .text)
try container.encodeIfPresent(blob.size, forKey: .size)
case .binaryBlob(let blob):
try container.encode("BLOB", forKey: .type)
+ try container.encode("BinaryBlob", forKey: .typename)
try container.encodeIfPresent(blob.id, forKey: .id)
try container.encodeIfPresent(blob.shortId, forKey: .shortId)
try container.encodeIfPresent(blob.size, forKey: .size)