Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,7 @@ Lithe 在工作台视图中持有 `WorkbenchToolContentStore`,本次用于 Git
- `macos/Tests/LitheGitModuleTests/Fixtures/GitGraphIDEA/`
- `macos/Tests/LitheTests/Fixtures/GitGraph/`
- `macos/Resources/GitGraph/`

## 后续:布局下沉到 Rust Core(#1662 GIT-18/19)

本文描述的 DFS、head 排序、定色、过滤后的虚线拓扑和 missing parents 算法已搬进 `rust/lithe-core/src/git/graph.rs`,由 `git.graphProjection` 统一提供,规则以 `shared/fixtures/git/graph-projection-v1.json` 为准。文中提到的 Swift/TS 实现文件已删除;两端只保留绘制、像素和颜色 ID 到主题色的映射。
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,7 @@ ResizeObserver(浏览器按帧合并的尺寸观察器)服务已挂载行,
- `macos/Sources/LitheGitModule/Services/GitGraphHeadOrdering.swift`
- `macos/Sources/LitheGitModule/Services/GitGraphProjection.swift`
- `macos/Tests/LitheGitModuleTests/Fixtures/GitGraphIDEA/`

## 后续:布局下沉到 Rust Core(#1662 GIT-18/19)

本文描述的 DFS、head 排序、定色、过滤后的虚线拓扑和 missing parents 算法已搬进 `rust/lithe-core/src/git/graph.rs`,由 `git.graphProjection` 统一提供,规则以 `shared/fixtures/git/graph-projection-v1.json` 为准。文中提到的 Swift/TS 实现文件已删除;两端只保留绘制、像素和颜色 ID 到主题色的映射。
13 changes: 3 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ let package = Package(
.library(name: "LitheWorkspaceModule", targets: ["LitheWorkspaceModule"]),
.library(name: "LithePluginPackageSigning", targets: ["LithePluginPackageSigning"]),
.executable(name: "LitheCoreVerifier", targets: ["LitheCoreVerifier"]),
.executable(name: "LitheGitGraphVerifier", targets: ["LitheGitGraphVerifier"]),
.executable(name: "LitheGitPerformanceVerifier", targets: ["LitheGitPerformanceVerifier"]),
.executable(name: "LitheOfficialPluginVerifier", targets: ["LitheOfficialPluginVerifier"]),
.executable(name: "LithePluginPackageSigner", targets: ["LithePluginPackageSigner"])
Expand Down Expand Up @@ -147,7 +146,7 @@ let package = Package(
),
.target(
name: "LitheGitTestSupport",
dependencies: ["LitheGitModule"],
dependencies: ["LitheGitModule", "LitheRustCore"],
path: "macos/Tests/LitheGitTestSupport",
swiftSettings: [.swiftLanguageMode(.v6)]
),
Expand Down Expand Up @@ -198,7 +197,6 @@ let package = Package(
name: "LitheGitModuleTests",
dependencies: ["LitheGitTestSupport", "LitheGitModule", "LitheApplicationKernel", "LitheRustCore", .product(name: "Testing", package: "swift-testing")],
path: "macos/Tests/LitheGitModuleTests",
resources: [.copy("Fixtures")],
swiftSettings: [.swiftLanguageMode(.v6)]
),
.target(
Expand All @@ -214,6 +212,7 @@ let package = Package(
"Lithe",
"LitheGitModule",
"LitheGitPerformanceSupport",
"LitheGitTestSupport",
.product(name: "Testing", package: "swift-testing")
],
path: "macos/Tests/LitheGitPerformanceTests",
Expand Down Expand Up @@ -249,15 +248,9 @@ let package = Package(
path: "macos/Tests/LitheCoreVerifier",
swiftSettings: [.swiftLanguageMode(.v6)]
),
.executableTarget(
name: "LitheGitGraphVerifier",
dependencies: ["LitheGitModule"],
path: "macos/Tests/LitheGitGraphVerifier",
swiftSettings: [.swiftLanguageMode(.v6)]
),
.executableTarget(
name: "LitheGitPerformanceVerifier",
dependencies: ["LitheGitModule", "LitheGitPerformanceSupport"],
dependencies: ["LitheGitModule", "LitheGitPerformanceSupport", "LitheGitTestSupport"],
path: "macos/Tests/LitheGitPerformanceVerifier",
swiftSettings: [.swiftLanguageMode(.v6)]
),
Expand Down
3 changes: 2 additions & 1 deletion macos/Sources/Lithe/Views/Git/GitGraphReferenceGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Apache-2.0.
// See Resources/GitGraph/NOTICE.txt.
import AppKit
import LitheCoreContracts
import LitheGitModule

/// IDEA's default compact reference display. The original names remain intact
Expand Down Expand Up @@ -40,7 +41,7 @@ struct GitGraphReferenceGroup: Equatable, Sendable {
}
let sorted = labels.sorted {
rank($0) == rank($1)
? GitGraphHeadOrdering.naturalCompare(Array($0.title.utf16), Array($1.title.utf16)) < 0
? NaturalNameOrder.compare(Array($0.title.utf16), Array($1.title.utf16)) < 0
: rank($0) < rank($1)
}
let locals = sorted.filter { $0.kind == .branch }
Expand Down
19 changes: 13 additions & 6 deletions macos/Sources/Lithe/Views/Git/GitLogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,31 @@ struct GitLogView: View {
let visibleHashes = visibleCommitHashes
let options: GitGraphDisplayOptions = showLongGraphEdges ? .expanded : .compact
let highlightsCurrentBranch = graphProjectionIdentity.highlightsCurrentBranch
let task = UserActionContext.detached(priority: .userInitiated) {
let layout = GitGraphLayoutService.layout(commits: commits, references: references,
repositoryCommits: repositoryCommits, visibleHashes: visibleHashes, options: options)
let currentBranch = highlightsCurrentBranch
? references.first(where: { $0.kind == .local && $0.isCurrent })?.shortName : nil
let projector = feature.graphProjector
// One Core call projects the whole loaded window; layout runs off the main actor.
let task = UserActionContext.detached(priority: .userInitiated) { () -> GitGraphPresentation? in
guard let layout = await GitGraphLayoutService.layout(
commits: commits, references: references, repositoryCommits: repositoryCommits,
visibleHashes: visibleHashes, options: options, currentBranch: currentBranch,
project: projector
) else { return nil }
let referenceIndex = GitGraphReferenceGroup.ReferenceIndex(references)
return GitGraphPresentation(rows: layout.rows,
routingSnapshot: GitGraphLayoutService.routingSnapshot(for: layout),
hasMissingParents: layout.hasMissingParents,
referenceGroups: Dictionary(uniqueKeysWithValues: layout.rows.map {
($0.commit.hash, GitGraphReferenceGroup(labels: $0.labels, index: referenceIndex))
}),
currentBranchHashes: highlightsCurrentBranch
? GitGraphLayoutService.currentBranchHashes(commits: commits, repositoryCommits: repositoryCommits, references: references) : [])
currentBranchHashes: layout.currentBranchHashes)
}
let presentation = await withTaskCancellationHandler {
let result = await withTaskCancellationHandler {
await task.value
} onCancel: {
task.cancel()
}
guard let presentation = result else { return }
guard !Task.isCancelled, graphProjectionIdentity == identity else { return }
presentationCache.store(presentation, for: identity)
graphPresentation = presentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,20 @@ package struct BuildTestResults: Equatable, Sendable, Decodable {
package let suite: String?
package let testCase: String?
private enum CodingKeys: String, CodingKey { case project, suite; case testCase = "case" }

/// The contract forbids a case without its suite (Core rejects it too),
/// so a scope that names one is malformed rather than guessed at.
package init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
project = try values.decode(String.self, forKey: .project)
suite = try values.decodeIfPresent(String.self, forKey: .suite)
testCase = try values.decodeIfPresent(String.self, forKey: .testCase)
if testCase != nil, suite == nil {
throw DecodingError.dataCorruptedError(
forKey: .testCase, in: values,
debugDescription: "A coverage case requires its suite.")
}
}
}
package let coverage: [Coverage]?
package struct TestCase: Equatable, Identifiable, Sendable, Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,35 @@ public struct TestRunVerdict: Codable, Equatable, Sendable {
public let exitCode: Int32?
}

/// What a run replaces in the stored test history: exact result ids and id
/// prefixes. The provider adapter builds it; Core only compares strings.
public struct TestOutcomeMergeScope: Codable, Equatable, Sendable {
public var ids: [String]
public var prefixes: [String]

public init(ids: [String] = [], prefixes: [String] = []) {
self.ids = ids
self.prefixes = prefixes
}
}

/// One merged result: its position in the `previous` or `incoming` input.
public struct TestOutcomeMergeEntry: Codable, Equatable, Sendable {
public enum Source: String, Codable, Sendable { case previous, incoming }
public let source: Source
public let index: Int
}

/// Reduces a finished test run to the verdict both platforms show.
public protocol TestRunOutcomeResolving: Sendable {
/// `build.mergeTestOutcomes`: which stored and which reported results
/// make up the new history, in display order.
func mergeTestOutcomes(
previous: [String],
incoming: [String],
scope: TestOutcomeMergeScope
) throws -> [TestOutcomeMergeEntry]

func resolveTestRunOutcome(
termination: TestRunTermination,
scope: TestRunScopeKind,
Expand Down Expand Up @@ -83,6 +110,30 @@ public extension TestRunOutcomeCoreCommandExecuting {
}
}

public extension TestRunOutcomeCoreCommandExecuting {
func mergeTestOutcomes(
previous: [String],
incoming: [String],
scope: TestOutcomeMergeScope
) throws -> [TestOutcomeMergeEntry] {
let response: MergeTestOutcomesResponse = try executeTestRunOutcomeCommand(
"build.mergeTestOutcomes",
payload: MergeTestOutcomesPayload(previous: previous, incoming: incoming, scope: scope)
)
return response.entries
}
}

private struct MergeTestOutcomesPayload: Encodable {
let previous: [String]
let incoming: [String]
let scope: TestOutcomeMergeScope
}

private struct MergeTestOutcomesResponse: Decodable {
let entries: [TestOutcomeMergeEntry]
}

private struct ResolveTestRunOutcomeTermination: Encodable {
let kind: String
let exitCode: Int32?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,20 @@ package final class LanguageTestService: ObservableObject {
resultsWorkspaceURL = workspaceURL.standardizedFileURL
// Only the backend can say that a whole suite/project completed.
// Legacy reports without coverage replace their exact returned cases.
let keys = Set(result.reports.flatMap(\.tests).map(BuildTestCaseKey.init))
// Core merges by id; this adapter only names the ids and prefixes.
let previous = testOutcomesByProviderID[providerID] ?? []
let coverage = result.reports.flatMap { $0.coverage ?? [] }
var outcomes = testOutcomesByProviderID[providerID] ?? []
outcomes.removeAll { outcome in
keys.contains(BuildTestCaseKey(outcome))
|| coverage.contains { scope in
scope.project == outcome.project
&& (scope.suite == nil || scope.suite == outcome.suite)
&& (scope.testCase == nil || scope.testCase == outcome.name)
}
let merged = try outcomeResolver.mergeTestOutcomes(
previous: previous.map(\.id),
incoming: report.tests.map(\.id),
scope: TestOutcomeMergeScope(
ids: report.tests.map(\.id),
prefixes: coverage.map(Self.coveragePrefix)
)
)
testOutcomesByProviderID[providerID] = merged.map {
$0.source == .previous ? previous[$0.index] : report.tests[$0.index]
}
testOutcomesByProviderID[providerID] = outcomes + report.tests
applyVerdict(
termination: .exited(result.exitCode),
scope: scope,
Expand All @@ -330,6 +332,16 @@ package final class LanguageTestService: ObservableObject {
}
}

/// A coverage scope is a prefix of the ids it completed: a project, one of
/// its suites, or (with a case name) exactly one test. `TestCase.id` is
/// length-prefixed per part, so a shorter scope never matches another name.
private static func coveragePrefix(_ scope: BuildTestResults.Coverage) -> String {
// Decoding rejects a case without its suite, so levels are contiguous.
[scope.project, scope.suite, scope.testCase]
.compactMap { $0.map { "\($0.utf8.count):" + $0 } }
.joined()
}

package func sourceURL(for test: BuildTestResults.TestCase) -> URL? {
guard let root = resultsWorkspaceURL, let path = test.path,
!path.hasPrefix("/"), !path.contains("\\"),
Expand Down
1 change: 1 addition & 0 deletions macos/Sources/LitheGitModule/Models/GitCorePlans.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package enum GitCorePlanCommand: String, Sendable {
case rebasePlanPreview = "git.rebasePlanPreview"
case updatePlan = "git.updatePlan"
case historyWindow = "git.historyWindow"
case graphProjection = "git.graphProjection"
}

// MARK: - git.normalizeChangeTargets
Expand Down
18 changes: 12 additions & 6 deletions macos/Sources/LitheGitModule/Models/GitGraphModels.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Foundation

/// How much of a long edge the graph draws. Core owns the thresholds
/// (`git.graphProjection` `displayMode`); the host only picks the mode.
package struct GitGraphDisplayOptions: Hashable, Sendable {
package static let compact = Self(longEdgeSize: 30, visiblePartSize: 1, edgeWithArrowSize: Int.max)
package static let expanded = Self(longEdgeSize: 1_000, visiblePartSize: 250, edgeWithArrowSize: 30)
package static let compact = Self(mode: "compact")
package static let expanded = Self(mode: "expanded")

let longEdgeSize: Int
let visiblePartSize: Int
let edgeWithArrowSize: Int
let mode: String
}

package enum GitGraphReferenceKind: String, Hashable, Sendable {
Expand Down Expand Up @@ -74,12 +74,18 @@ package struct GitGraphLayout: Sendable {
package let laneCount: Int
package let hasMissingParents: Bool
package let recommendedLaneCount: Int
/// Ancestry of the requested current branch, for the row background highlight.
package let currentBranchHashes: Set<String>

package init(rows: [GitGraphRow], laneCount: Int, hasMissingParents: Bool, recommendedLaneCount: Int = 0) {
package init(
rows: [GitGraphRow], laneCount: Int, hasMissingParents: Bool, recommendedLaneCount: Int = 0,
currentBranchHashes: Set<String> = []
) {
self.rows = rows
self.laneCount = laneCount
self.hasMissingParents = hasMissingParents
self.recommendedLaneCount = recommendedLaneCount
self.currentBranchHashes = currentBranchHashes
}
}

Expand Down
86 changes: 86 additions & 0 deletions macos/Sources/LitheGitModule/Models/GitGraphProjectionModels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import Foundation

// Wire types for Core's `git.graphProjection`. Core owns lanes, colors, routes, and
// labels (`shared/fixtures/git/graph-projection-v1.json`); the host builds the request
// and turns the response into its drawing models.

package struct GitGraphProjectionRequest: Encodable, Sendable, Equatable {
package struct Commit: Encodable, Sendable, Equatable {
package let hash: String
package let parentHashes: [String]
package let decorations: String

package init(hash: String, parentHashes: [String], decorations: String) {
self.hash = hash
self.parentHashes = parentHashes
self.decorations = decorations
}
}

package let commits: [Commit]
package let remoteNames: [String]
package let repositoryCommits: [Commit]
package let visibleHashes: [String]?
package let displayMode: String
package let currentBranch: String?

package init(
commits: [Commit], remoteNames: [String] = [], repositoryCommits: [Commit] = [],
visibleHashes: [String]? = nil, displayMode: String = "compact", currentBranch: String? = nil
) {
self.commits = commits
self.remoteNames = remoteNames
self.repositoryCommits = repositoryCommits
self.visibleHashes = visibleHashes
self.displayMode = displayMode
self.currentBranch = currentBranch
}
}

package struct GitGraphProjectionResponse: Decodable, Sendable {
package struct Label: Decodable, Sendable {
package let title: String
package let kind: String
}

package struct ParentEdge: Decodable, Sendable {
package let id: String
package let parentHash: String
package let targetLane: Int?
package let colorId: Int
package let isMissing: Bool
}

package struct PrintElement: Decodable, Sendable {
package let id: String
package let position: Int
package let adjacentPosition: Int
package let direction: String
package let colorId: Int
package let isDotted: Bool
package let hasArrow: Bool
package let isTerminal: Bool
package let targetHash: String?
}

package struct Row: Decodable, Sendable {
package let commitHash: String
package let lane: Int
package let laneCount: Int
package let colorId: Int
package let layoutIndex: Int
package let incomingLaneColors: [Int]
package let parentEdges: [ParentEdge]
package let labels: [Label]
package let printElements: [PrintElement]
}

package let rows: [Row]
package let laneCount: Int
package let recommendedLaneCount: Int
package let hasMissingParents: Bool
package let currentBranchHashes: [String]
}

/// Runs one `git.graphProjection` call; `nil` means Core rejected the request.
package typealias GitGraphProjector = @Sendable (GitGraphProjectionRequest) async -> GitGraphProjectionResponse?
Loading
Loading