-
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
Conversation
a5856f2
to
bcd15fb
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
please double check logic still looks right
@@ -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 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.
@@ -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 { |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
please double check logic still looks right
motivation: when working on configuration, CheckoutState data model stood out as one that can be improved changes: * transition CheckoutState from struct with optionals to enum representing the finite states * adust call sites and tests
bcd15fb
to
19e23a0
Compare
@swift-ci please smoke test |
} | ||
case revision(Revision) | ||
case version(Version, revision: Revision) | ||
case branch(String, revision: Revision) |
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.
Should we name the first parameter, too?
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.
I started with naming them but it was a bit awkward in the call site e.g. let checkoutState: CheckoutState = .branch(branch: "main", revision: ...)
vs let checkoutState: CheckoutState = .branch("main", revision: ...)
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.
Right, the first parameter is often unnamed when the enum case makes it obvious, and I agree that that applies here. So I think it should be unnamed.
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.
ended up adding name:
to the branch variant
} | ||
case revision(Revision) | ||
case version(Version, revision: Revision) | ||
case branch(String, revision: Revision) |
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.
Right, the first parameter is often unnamed when the enum case makes it obvious, and I agree that that applies here. So I think it should be unnamed.
@@ -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 { |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct to me.
@swift-ci please smoke test |
motivation: when working on configuration, CheckoutState data model stood out as one that can be improved to be safer
changes: