Skip to content
Open
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
51 changes: 43 additions & 8 deletions macos/Sources/Lithe/Core/Rust/RustCoreBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1720,11 +1720,24 @@ struct RustCoreBridge: Sendable {
let input: String?
}

private struct GitReferenceRequest: Encodable {
let fullName: String
let shortName: String
let kind: String

init(_ reference: GitReference) {
fullName = reference.fullName
shortName = reference.shortName
kind = reference.kind.rawValue
}
}

private struct GitWriteRequest: Encodable {
let root: String
let operation: String
let paths: [String]
let reference: String?
let gitReference: GitReferenceRequest?
let referenceKind: String?
let revision: String?
let name: String?
Expand All @@ -1743,6 +1756,8 @@ struct RustCoreBridge: Sendable {
let root: String
let pathspecs: [String]
let reference: String?
let gitReference: GitReferenceRequest?
let targetGitReference: GitReferenceRequest?
let commit: String?
let staged: Bool
let untracked: Bool
Expand Down Expand Up @@ -1774,7 +1789,9 @@ struct RustCoreBridge: Sendable {

private struct GitComparisonRequest: Encodable {
let root: String
let reference: String
let reference: String?
let gitReference: GitReferenceRequest?
let targetGitReference: GitReferenceRequest?
}

private struct GitStashesRequest: Encodable {
Expand All @@ -1783,7 +1800,7 @@ struct RustCoreBridge: Sendable {

private struct GitCheckoutPreflightRequest: Encodable {
let root: String
let reference: String
let gitReference: GitReferenceRequest
}

private struct GitOperationStateRequest: Encodable {
Expand All @@ -1800,7 +1817,8 @@ struct RustCoreBridge: Sendable {

private struct GitIntegrationPreflightRequest: Encodable {
let root: String
let reference: String
let reference: String?
let gitReference: GitReferenceRequest?
let operation: String
}

Expand Down Expand Up @@ -2613,6 +2631,7 @@ struct RustCoreBridge: Sendable {
operation: String,
paths: [String] = [],
reference: String? = nil,
gitReference: GitReference? = nil,
referenceKind: String? = nil,
revision: String? = nil,
name: String? = nil,
Expand All @@ -2633,6 +2652,7 @@ struct RustCoreBridge: Sendable {
operation: operation,
paths: paths,
reference: reference,
gitReference: gitReference.map(GitReferenceRequest.init),
referenceKind: referenceKind,
revision: revision,
name: name,
Expand All @@ -2649,12 +2669,12 @@ struct RustCoreBridge: Sendable {
)
}

func gitCheckoutPreflight(at rootURL: URL, reference: String) -> GitCheckoutPreflightPayload? {
func gitCheckoutPreflight(at rootURL: URL, reference: GitReference) -> GitCheckoutPreflightPayload? {
execute(
command: "git.checkoutPreflight",
payload: GitCheckoutPreflightRequest(
root: rootURL.standardizedFileURL.path,
reference: reference
gitReference: GitReferenceRequest(reference)
)
)
}
Expand Down Expand Up @@ -2688,14 +2708,16 @@ struct RustCoreBridge: Sendable {

func gitIntegrationPreflight(
at rootURL: URL,
reference: String,
reference: String? = nil,
gitReference: GitReference? = nil,
operation: String
) -> GitIntegrationPreflightPayload? {
execute(
command: "git.integrationPreflight",
payload: GitIntegrationPreflightRequest(
root: rootURL.standardizedFileURL.path,
reference: reference,
gitReference: gitReference.map(GitReferenceRequest.init),
operation: operation
)
)
Expand All @@ -2706,6 +2728,7 @@ struct RustCoreBridge: Sendable {
operation: String,
paths: [String] = [],
reference: String? = nil,
gitReference: GitReference? = nil,
referenceKind: String? = nil,
revision: String? = nil,
name: String? = nil,
Expand All @@ -2726,6 +2749,7 @@ struct RustCoreBridge: Sendable {
operation: operation,
paths: paths,
reference: reference,
gitReference: gitReference.map(GitReferenceRequest.init),
referenceKind: referenceKind,
revision: revision,
name: name,
Expand All @@ -2746,6 +2770,8 @@ struct RustCoreBridge: Sendable {
at rootURL: URL,
pathspecs: [String],
reference: String? = nil,
gitReference: GitReference? = nil,
targetGitReference: GitReference? = nil,
commit: String? = nil,
staged: Bool,
untracked: Bool,
Expand All @@ -2758,6 +2784,8 @@ struct RustCoreBridge: Sendable {
root: rootURL.standardizedFileURL.path,
pathspecs: pathspecs,
reference: reference,
gitReference: gitReference.map(GitReferenceRequest.init),
targetGitReference: targetGitReference.map(GitReferenceRequest.init),
commit: commit,
staged: staged,
untracked: untracked,
Expand Down Expand Up @@ -2829,12 +2857,19 @@ struct RustCoreBridge: Sendable {
)
}

func gitComparison(at rootURL: URL, reference: String) -> GitComparisonPayload? {
func gitComparison(
at rootURL: URL,
reference: String? = nil,
gitReference: GitReference? = nil,
targetGitReference: GitReference? = nil
) -> GitComparisonPayload? {
execute(
command: "git.comparison",
payload: GitComparisonRequest(
root: rootURL.standardizedFileURL.path,
reference: reference
reference: reference,
gitReference: gitReference.map(GitReferenceRequest.init),
targetGitReference: targetGitReference.map(GitReferenceRequest.init)
)
)
}
Expand Down
97 changes: 70 additions & 27 deletions macos/Sources/Lithe/Core/Rust/RustGitOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct RustGitOperations: GitOperations, Sendable {
operation: String,
paths: [String] = [],
reference: String? = nil,
gitReference: GitReference? = nil,
referenceKind: GitReferenceKind? = nil,
revision: String? = nil,
name: String? = nil,
Expand All @@ -78,6 +79,7 @@ struct RustGitOperations: GitOperations, Sendable {
operation: operation,
paths: paths,
reference: reference,
gitReference: gitReference,
referenceKind: referenceKind?.rawValue,
revision: revision,
name: name,
Expand Down Expand Up @@ -134,39 +136,30 @@ struct RustGitOperations: GitOperations, Sendable {
write(
at: rootURL,
operation: "createBranch",
reference: reference.fullName,
gitReference: reference,
name: name,
checkout: checkout
)
}

func renameBranch(_ reference: GitReference, to name: String, at rootURL: URL) -> GitProcessResult? {
write(at: rootURL, operation: "renameBranch", reference: reference.fullName, name: name)
write(at: rootURL, operation: "renameBranch", gitReference: reference, name: name)
}

func deleteBranch(_ reference: GitReference, at rootURL: URL) -> GitProcessResult? {
write(at: rootURL, operation: "deleteBranch", reference: reference.fullName)
write(at: rootURL, operation: "deleteBranch", gitReference: reference)
}

func mergeBranch(_ reference: GitReference, at rootURL: URL) -> GitProcessResult? {
write(at: rootURL, operation: "merge", reference: reference.fullName)
write(at: rootURL, operation: "merge", gitReference: reference)
}

func rebaseCurrentBranch(onto reference: GitReference, at rootURL: URL) -> GitProcessResult? {
write(at: rootURL, operation: "rebase", reference: reference.fullName)
write(at: rootURL, operation: "rebase", gitReference: reference)
}

func checkoutAndRebase(_ reference: GitReference, at rootURL: URL) -> GitProcessResult? {
write(
at: rootURL,
operation: "checkoutAndRebase",
reference: reference.fullName,
referenceKind: reference.kind
)
}

func updateCurrentBranch(at rootURL: URL, strategy: GitPullStrategy = .ffOnly) -> GitProcessResult? {
write(at: rootURL, operation: "pull", mode: strategy.rawValue)
write(at: rootURL, operation: "checkoutAndRebase", gitReference: reference)
}

func pullRemoteReference(
Expand All @@ -177,12 +170,15 @@ struct RustGitOperations: GitOperations, Sendable {
write(
at: rootURL,
operation: "pull",
reference: reference.fullName,
referenceKind: reference.kind,
gitReference: reference,
mode: strategy.rawValue
)
}

func updateCurrentBranch(at rootURL: URL, strategy: GitPullStrategy = .ffOnly) -> GitProcessResult? {
write(at: rootURL, operation: "pull", mode: strategy.rawValue)
}

/// Staged files still containing conflict markers.
func conflictMarkerPaths(at rootURL: URL) -> [String] {
core.gitConflictMarkerPaths(at: rootURL)?.paths ?? []
Expand All @@ -194,11 +190,22 @@ struct RustGitOperations: GitOperations, Sendable {
operation: GitIntegrationOperation,
at rootURL: URL
) -> GitIntegrationPreflightState? {
guard let payload = core.gitIntegrationPreflight(
at: rootURL,
reference: target.revision,
operation: operation.rawValue
) else { return nil }
let payload: RustCoreBridge.GitIntegrationPreflightPayload?
switch target {
case .reference(let reference):
payload = core.gitIntegrationPreflight(
at: rootURL,
gitReference: reference,
operation: operation.rawValue
)
case .commit:
payload = core.gitIntegrationPreflight(
at: rootURL,
reference: target.revision,
operation: operation.rawValue
)
}
guard let payload else { return nil }
return GitIntegrationPreflightState(
blockingPaths: payload.blockingPaths,
blocksEntirely: payload.blocksEntirely
Expand Down Expand Up @@ -230,16 +237,15 @@ struct RustGitOperations: GitOperations, Sendable {
write(
at: rootURL,
operation: "checkout",
reference: reference.fullName,
referenceKind: reference.kind,
gitReference: reference,
force: force,
autoStash: autoStash
)
}

/// Returns the working-tree paths that would block checking out `reference`.
func checkoutBlockingPaths(for reference: GitReference, at rootURL: URL) -> [String] {
core.gitCheckoutPreflight(at: rootURL, reference: reference.fullName)?.blockingPaths ?? []
core.gitCheckoutPreflight(at: rootURL, reference: reference)?.blockingPaths ?? []
}

func operationState(at rootURL: URL) -> GitOperationState? {
Expand Down Expand Up @@ -273,7 +279,7 @@ struct RustGitOperations: GitOperations, Sendable {
}

func push(_ reference: GitReference, at rootURL: URL) -> GitProcessResult? {
write(at: rootURL, operation: "push", reference: reference.fullName)
write(at: rootURL, operation: "push", gitReference: reference)
}

func cloneRepository(from remote: String, to destination: URL) -> GitProcessResult? {
Expand Down Expand Up @@ -382,6 +388,24 @@ struct RustGitOperations: GitOperations, Sendable {
)?.makeDocument()
}

func comparisonDiffDocument(
at rootURL: URL,
reference: GitReference,
targetReference: GitReference?,
pathspecs: [String],
whitespace: GitDiffWhitespaceMode = .doNotIgnore
) -> DiffDocument? {
core.gitDiff(
at: rootURL,
pathspecs: pathspecs,
gitReference: reference,
targetGitReference: targetReference,
staged: false,
untracked: false,
ignoreAllWhitespace: whitespace == .ignoreAllWhitespace
)?.makeDocument()
}

func applyPatch(
_ patch: String,
at rootURL: URL,
Expand Down Expand Up @@ -421,7 +445,7 @@ struct RustGitOperations: GitOperations, Sendable {
for reference: GitReference,
at rootURL: URL
) -> GitBranchComparison? {
guard let payload = core.gitComparison(at: rootURL, reference: reference.fullName) else {
guard let payload = core.gitComparison(at: rootURL, gitReference: reference) else {
return nil
}
return GitBranchComparison(
Expand All @@ -432,6 +456,25 @@ struct RustGitOperations: GitOperations, Sendable {
)
}

func comparison(
from reference: GitReference,
to target: GitReference,
at rootURL: URL
) -> GitBranchComparison? {
guard let payload = core.gitComparison(
at: rootURL,
gitReference: reference,
targetGitReference: target
) else { return nil }
return GitBranchComparison(
reference: reference,
targetReference: target,
files: payload.files.map { file in
GitBranchComparisonFile(status: file.status, path: file.path)
}
)
}

func stashes(at rootURL: URL) -> [GitStash]? {
core.gitStashes(at: rootURL)?.stashes.map { stash in
GitStash(
Expand Down
Loading
Loading