-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor CheckoutState #3666
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
refactor CheckoutState #3666
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,13 @@ | |
See http://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Basics | ||
import Dispatch | ||
import PackageModel | ||
import PackageGraph | ||
import PackageModel | ||
import SourceControl | ||
import TSCBasic | ||
import TSCUtility | ||
import SourceControl | ||
|
||
/// Enumeration of the different errors that can arise from the `ResolverPrecomputationProvider` provider. | ||
enum ResolverPrecomputationError: Error { | ||
|
@@ -95,7 +96,7 @@ private struct LocalPackageContainer: PackageContainer { | |
let currentToolsVersion: ToolsVersion | ||
|
||
func versionsAscending() throws -> [Version] { | ||
if let version = dependency?.state.checkout?.version { | ||
if case .version(let version, revision: _) = dependency?.state.checkout { | ||
return [version] | ||
} else { | ||
return [] | ||
|
@@ -121,23 +122,25 @@ private struct LocalPackageContainer: PackageContainer { | |
|
||
func getDependencies(at version: Version, productFilter: ProductFilter) throws -> [PackageContainerConstraint] { | ||
// Because of the implementation of `reversedVersions`, we should only get the exact same version. | ||
precondition(dependency?.checkoutState?.version == version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please double check logic still looks right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks correct to me. |
||
guard case .version(version, revision: _) = dependency?.checkoutState else { | ||
throw InternalError("expected version, but checkout state was \(String(describing: dependency?.checkoutState))") | ||
} | ||
return try manifest.dependencyConstraints(productFilter: productFilter) | ||
} | ||
|
||
func getDependencies(at revision: String, productFilter: ProductFilter) throws -> [PackageContainerConstraint] { | ||
func getDependencies(at revisionString: String, productFilter: ProductFilter) throws -> [PackageContainerConstraint] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please double check logic still looks right |
||
// Return the dependencies if the checkout state matches the revision. | ||
if let checkoutState = dependency?.checkoutState, | ||
checkoutState.version == nil, | ||
checkoutState.revision.identifier == revision { | ||
let revision = Revision(identifier: revisionString) | ||
switch dependency?.checkoutState { | ||
case .branch(_, revision: revision), .revision(revision): | ||
return try manifest.dependencyConstraints(productFilter: productFilter) | ||
default: | ||
throw ResolverPrecomputationError.differentRequirement( | ||
package: self.package, | ||
state: self.dependency?.state, | ||
requirement: .revision(revisionString) | ||
) | ||
} | ||
|
||
throw ResolverPrecomputationError.differentRequirement( | ||
package: self.package, | ||
state: self.dependency?.state, | ||
requirement: .revision(revision) | ||
) | ||
} | ||
|
||
func getUnversionedDependencies(productFilter: ProductFilter) throws -> [PackageContainerConstraint] { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1455,10 +1455,15 @@ extension Workspace { | |
switch managedDependency.state { | ||
case .checkout(let checkoutState): | ||
packageKind = .remote | ||
version = checkoutState.version | ||
switch checkoutState { | ||
case .version(let checkoutVersion, _): | ||
version = checkoutVersion | ||
default: | ||
version = .none | ||
} | ||
case .edited, .local: | ||
packageKind = .local | ||
version = nil | ||
version = .none | ||
} | ||
|
||
// Get the path of the package. | ||
|
@@ -2355,19 +2360,22 @@ extension Workspace { | |
|
||
// If we have a branch and we shouldn't be updating the | ||
// branches, use the revision from pin instead (if present). | ||
if branch != nil { | ||
if let pin = pinsStore.pins.first(where: { $0.packageRef == packageRef }), | ||
!updateBranches, | ||
pin.state.branch == branch { | ||
revision = pin.state.revision | ||
if branch != nil, !updateBranches { | ||
if case .branch(branch, let pinRevision) = pinsStore.pins.first(where: { $0.packageRef == packageRef })?.state { | ||
revision = pinRevision | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please double check logic still looks right |
||
} | ||
} | ||
|
||
// First check if we have this dependency. | ||
if let currentDependency = currentDependency { | ||
// If current state and new state are equal, we don't need | ||
// to do anything. | ||
let newState = CheckoutState(revision: revision, branch: branch) | ||
let newState: CheckoutState | ||
if let branch = branch { | ||
newState = .branch(name: branch, revision: revision) | ||
} else { | ||
newState = .revision(revision) | ||
} | ||
if case .checkout(let checkoutState) = currentDependency.state, checkoutState == newState { | ||
packageStateChanges[packageRef.location] = (packageRef, .unchanged) | ||
} else { | ||
|
@@ -2382,7 +2390,7 @@ extension Workspace { | |
|
||
case .version(let version): | ||
if let currentDependency = currentDependency { | ||
if case .checkout(let checkoutState) = currentDependency.state, checkoutState.version == version { | ||
if case .checkout(let checkoutState) = currentDependency.state, case .version(version, _) = checkoutState { | ||
packageStateChanges[packageRef.location] = (packageRef, .unchanged) | ||
} else { | ||
let newState = PackageStateChange.State(requirement: .version(version), products: products) | ||
|
@@ -2664,10 +2672,13 @@ extension Workspace { | |
throw InternalError("unable to get tag for \(package) \(version); available versions \(try container.versionsDescending())") | ||
} | ||
let revision = try container.getRevision(forTag: tag) | ||
checkoutState = CheckoutState(revision: revision, version: version) | ||
checkoutState = .version(version, revision: revision) | ||
|
||
case .revision(let revision, .none): | ||
checkoutState = .revision(revision) | ||
|
||
case .revision(let revision, let branch): | ||
checkoutState = CheckoutState(revision: revision, branch: branch) | ||
case .revision(let revision, .some(let branch)): | ||
checkoutState = .branch(name: branch, revision: revision) | ||
|
||
case .unversioned: | ||
state.dependencies.add(ManagedDependency.local(packageRef: package)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please double check logic still looks right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct to me.