Skip to content

Convert git WorkingCopy API to async #8681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Sources/Commands/Utilities/APIDigester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct APIDigesterBaselineDumper {
// Clone the current package in a sandbox and checkout the baseline revision.
let repositoryProvider = GitRepositoryProvider()
let specifier = RepositorySpecifier(path: baselinePackageRoot)
let workingCopy = try repositoryProvider.createWorkingCopy(
let workingCopy = try await repositoryProvider.createWorkingCopy(
repository: specifier,
sourcePath: packageRoot,
at: baselinePackageRoot,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceControl/GitRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public struct GitRepositoryProvider: RepositoryProvider, Cancellable {
sourcePath: Basics.AbsolutePath,
at destinationPath: Basics.AbsolutePath,
editable: Bool
) throws -> WorkingCheckout {
) async throws -> WorkingCheckout {
if editable {
// For editable clones, i.e. the user is expected to directly work on them, first we create
// a clone from our cache of repositories and then we replace the remote to the one originally
Expand Down
4 changes: 2 additions & 2 deletions Sources/SourceControl/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public protocol RepositoryProvider: Cancellable {
repository: RepositorySpecifier,
sourcePath: AbsolutePath,
at destinationPath: AbsolutePath,
editable: Bool) throws -> WorkingCheckout
editable: Bool) async throws -> WorkingCheckout

/// Returns true if a working repository exists at `path`
func workingCopyExists(at path: AbsolutePath) throws -> Bool
Expand All @@ -131,7 +131,7 @@ public protocol RepositoryProvider: Cancellable {
/// - Parameters:
/// - path: The location of the repository on disk, at which the repository
/// has previously been created via `copyToWorkingDirectory`.
func openWorkingCopy(at path: AbsolutePath) throws -> WorkingCheckout
func openWorkingCopy(at path: AbsolutePath) async throws -> WorkingCheckout

/// Copies the repository at path `from` to path `to`.
/// - Parameters:
Expand Down
14 changes: 7 additions & 7 deletions Sources/SourceControl/RepositoryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public class RepositoryManager: Cancellable {
}
}
}

// We are expecting handle.repository.url to always be a resolved absolute path.
let shouldCacheLocalPackages = Environment.current["SWIFTPM_TESTS_PACKAGECACHE"] == "1" || cacheLocalPackages

Expand Down Expand Up @@ -409,8 +409,8 @@ public class RepositoryManager: Cancellable {
}

/// Open a working copy checkout at a path
public func openWorkingCopy(at path: Basics.AbsolutePath) throws -> WorkingCheckout {
try self.provider.openWorkingCopy(at: path)
public func openWorkingCopy(at path: Basics.AbsolutePath) async throws -> WorkingCheckout {
try await self.provider.openWorkingCopy(at: path)
}

/// Validate a working copy check is aligned with its repository setup
Expand All @@ -433,8 +433,8 @@ public class RepositoryManager: Cancellable {
_ handle: RepositoryHandle,
at destinationPath: Basics.AbsolutePath,
editable: Bool
) throws -> WorkingCheckout {
try self.provider.createWorkingCopy(
) async throws -> WorkingCheckout {
try await self.provider.createWorkingCopy(
repository: handle.repository,
sourcePath: self.path.appending(handle.subpath),
at: destinationPath,
Expand Down Expand Up @@ -548,8 +548,8 @@ extension RepositoryManager {
/// expected to be non-existent when called.
///
/// - editable: The clone is expected to be edited by user.
public func createWorkingCopy(at path: Basics.AbsolutePath, editable: Bool) throws -> WorkingCheckout {
return try self.manager.createWorkingCopy(self, at: path, editable: editable)
public func createWorkingCopy(at path: Basics.AbsolutePath, editable: Bool) async throws -> WorkingCheckout {
return try await self.manager.createWorkingCopy(self, at: path, editable: editable)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Workspace/Workspace+Editing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extension Workspace {
throw WorkspaceDiagnostics.RevisionDoesNotExist(revision: revision.identifier)
}

let workingCopy = try handle.createWorkingCopy(at: destination, editable: true)
let workingCopy = try await handle.createWorkingCopy(at: destination, editable: true)
try workingCopy.checkout(revision: revision ?? checkoutState.revision)

// Checkout to the new branch if provided.
Expand Down Expand Up @@ -187,7 +187,7 @@ extension Workspace {
let path = self.location.editSubdirectory(for: dependency)
// Check for uncommitted and unpushed changes if force removal is off.
if !forceRemove {
let workingCopy = try repositoryManager.openWorkingCopy(at: path)
let workingCopy = try await repositoryManager.openWorkingCopy(at: path)
guard !workingCopy.hasUncommittedChanges() else {
throw WorkspaceDiagnostics.UncommittedChanges(repositoryPath: path)
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Workspace/Workspace+SourceControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension Workspace {
)

// Check out the given revision.
let workingCopy = try self.repositoryManager.openWorkingCopy(at: checkoutPath)
let workingCopy = try await self.repositoryManager.openWorkingCopy(at: checkoutPath)

// Inform the delegate that we're about to start.
delegate?.willCheckOut(
Expand Down Expand Up @@ -147,7 +147,7 @@ extension Workspace {
// This can become invalid if the build directory is moved.
fetch: if self.fileSystem.isDirectory(checkoutPath) {
// Fetch the checkout in case there are updates available.
let workingCopy = try self.repositoryManager.openWorkingCopy(at: checkoutPath)
let workingCopy = try await self.repositoryManager.openWorkingCopy(at: checkoutPath)

// Ensure that the alternative object store is still valid.
guard try self.repositoryManager.isValidWorkingCopy(workingCopy, for: repository) else {
Expand Down Expand Up @@ -198,7 +198,7 @@ extension Workspace {
let start = DispatchTime.now()

// Create the working copy.
_ = try handle.createWorkingCopy(at: checkoutPath, editable: false)
_ = try await handle.createWorkingCopy(at: checkoutPath, editable: false)

// Inform the delegate that we're done.
let duration = start.distance(to: .now())
Expand All @@ -213,14 +213,14 @@ extension Workspace {
}

/// Removes the clone and checkout of the provided specifier.
func removeRepository(dependency: ManagedDependency) throws {
func removeRepository(dependency: ManagedDependency) async throws {
guard case .sourceControlCheckout = dependency.state else {
throw InternalError("cannot remove repository for \(dependency) with state \(dependency.state)")
}

// Remove the checkout.
let dependencyPath = self.location.repositoriesCheckoutSubdirectory(for: dependency)
let workingCopy = try self.repositoryManager.openWorkingCopy(at: dependencyPath)
let workingCopy = try await self.repositoryManager.openWorkingCopy(at: dependencyPath)
guard !workingCopy.hasUncommittedChanges() else {
throw WorkspaceDiagnostics.UncommittedChanges(repositoryPath: dependencyPath)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ extension Workspace {
case .localSourceControl:
break // NOOP
case .remoteSourceControl:
try self.removeRepository(dependency: dependencyToRemove)
try await self.removeRepository(dependency: dependencyToRemove)
case .registry:
try self.removeRegistryArchive(for: dependencyToRemove)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/_InternalTestSupport/InMemoryGitRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ extension InMemoryGitRepository: FileSystem {
try self.head.fileSystem.createDirectory(path, recursive: recursive)
}
}

public func createSymbolicLink(_ path: TSCAbsolutePath, pointingAt destination: TSCAbsolutePath, relative: Bool) throws {
throw FileSystemError(.unsupported, path)
}
Expand Down Expand Up @@ -458,7 +458,7 @@ public final class InMemoryGitRepositoryProvider: RepositoryProvider {
sourcePath: AbsolutePath,
at destinationPath: AbsolutePath,
editable: Bool
) throws -> WorkingCheckout {
) async throws -> WorkingCheckout {
guard let checkout = fetchedMap[sourcePath] else {
throw InternalError("unknown checkout at \(sourcePath)")
}
Expand All @@ -471,7 +471,7 @@ public final class InMemoryGitRepositoryProvider: RepositoryProvider {
return checkoutsMap.contains(path)
}

public func openWorkingCopy(at path: AbsolutePath) throws -> WorkingCheckout {
public func openWorkingCopy(at path: AbsolutePath) async throws -> WorkingCheckout {
guard let checkout = checkoutsMap[path] else {
throw InternalError("unknown checkout at \(path)")
}
Expand Down
Loading