Skip to content

Commit de10175

Browse files
committed
cleanup
1 parent b9f638f commit de10175

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,14 @@ extension PackageGraph {
3636

3737
// Create a map of the manifests, keyed by their identity.
3838
let rootManifestsMap = root.manifests
39-
//let externalManifestsMap = externalManifests.map{ (identityResolver.resolveIdentity(for: $0.packageLocation), $0) }
40-
//let manifestMap = rootManifestsMap.merging(externalManifests, uniquingKeysWith: { lhs, rhs in
41-
// return lhs
42-
//})
43-
44-
// prefer roots
4539
var manifestMap = rootManifestsMap
4640
externalManifests.forEach {
41+
// prefer roots
4742
if !manifestMap.keys.contains($0.key) {
4843
manifestMap[$0.key] = $0.value
4944
}
5045
}
5146

52-
5347
let successors: (GraphLoadingNode) -> [GraphLoadingNode] = { node in
5448
node.requiredDependencies().compactMap{ dependency in
5549
return manifestMap[dependency.identity].map { manifest in

Sources/Workspace/ManagedDependency.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ extension Workspace {
154154
}
155155

156156
public subscript(identity: PackageIdentity) -> ManagedDependency? {
157-
//self.dependencies.values.first(where: { $0.packageRef.identity == identity })
158157
return self.dependencies[identity]
159158
}
160159

161-
public subscript(package: PackageReference) -> ManagedDependency? {
160+
// When loading manifests in Workspace, there are cases where we must also compare the location
161+
// as it may attempt to load manifests for dependencies that have the same identity but from a different location
162+
// (e.g. dependency is changed to a fork with the same identity)
163+
public subscript(comparingLocation package: PackageReference) -> ManagedDependency? {
162164
if let dependency = self.dependencies[package.identity], dependency.packageRef.location == package.location {
163165
return dependency
164166
}

Sources/Workspace/Workspace.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,6 @@ extension Workspace {
11761176
_ = try clone(package: dependency.packageRef, at: checkoutState)
11771177
} else {
11781178
// The original dependency was removed, update the managed dependency state.
1179-
//self.state.dependencies.remove(forURL: dependency.packageRef.location)
11801179
self.state.dependencies.remove(dependency.packageRef.identity)
11811180
try self.state.save()
11821181
}
@@ -1562,8 +1561,6 @@ extension Workspace {
15621561

15631562
/// Loads the given manifests, if it is present in the managed dependencies.
15641563
private func loadManagedManifests(for packages: [PackageReference], diagnostics: DiagnosticsEngine, completion: @escaping (Result<[PackageIdentity: Manifest], Error>) -> Void) {
1565-
// this is allot of boilerplate code but its is important for performance
1566-
//let lock = Lock()
15671564
let sync = DispatchGroup()
15681565
let manifests = ThreadSafeKeyValueStore<PackageIdentity, Manifest>()
15691566
Set(packages).forEach { package in
@@ -1588,7 +1585,7 @@ extension Workspace {
15881585
// dependencies that have the same identity but from a different location
15891586
// which is an error case we diagnose an report about in the GraphLoading part which
15901587
// is prepared to handle the case where not all manifest are available
1591-
guard let managedDependency = self.state.dependencies[package] else {
1588+
guard let managedDependency = self.state.dependencies[comparingLocation: package] else {
15921589
return completion(.none)
15931590
}
15941591

@@ -2039,8 +2036,8 @@ extension Workspace {
20392036
// We require cloning if there is no checkout or if the checkout doesn't
20402037
// match with the pin.
20412038
let requiredPins = pinsStore.pins.filter{ pin in
2042-
//guard let dependency = state.dependencies[forURL: pin.packageRef.location] else {
2043-
guard let dependency = state.dependencies[pin.packageRef] else {
2039+
// also compare the location in case it has changed
2040+
guard let dependency = state.dependencies[comparingLocation: pin.packageRef] else {
20442041
return true
20452042
}
20462043
switch dependency.state {
@@ -2416,8 +2413,8 @@ extension Workspace {
24162413
if case .edited(let basedOn, _) = currentDependency?.state, let originalReference = basedOn?.packageRef {
24172414
packageStateChanges[originalReference.identity] = (originalReference, .unchanged)
24182415
} else {
2419-
// if not edited, also lookup by location since it may have changed
2420-
currentDependency = self.state.dependencies[packageRef]
2416+
// if not edited, also compare by location since it may have changed
2417+
currentDependency = self.state.dependencies[comparingLocation: packageRef]
24212418
}
24222419

24232420
switch binding {
@@ -2659,7 +2656,8 @@ extension Workspace {
26592656
/// - Throws: If the operation could not be satisfied.
26602657
private func fetch(package: PackageReference) throws -> AbsolutePath {
26612658
// If we already have it, fetch to update the repo from its remote.
2662-
if let dependency = self.state.dependencies[package] {
2659+
// also compare the location as it may have changed
2660+
if let dependency = self.state.dependencies[comparingLocation: package] {
26632661
let path = self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
26642662

26652663
// Make sure the directory is not missing (we will have to clone again
@@ -2797,7 +2795,7 @@ extension Workspace {
27972795

27982796
/// Removes the clone and checkout of the provided specifier.
27992797
fileprivate func remove(package: PackageReference) throws {
2800-
guard let dependency = self.state.dependencies[package] else {
2798+
guard let dependency = self.state.dependencies[package.identity] else {
28012799
throw InternalError("trying to remove \(package.identity) which isn't in workspace")
28022800
}
28032801

Sources/Workspace/WorkspaceState.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ fileprivate struct WorkspaceStateStorage {
188188
state: state,
189189
subpath: subpath
190190
)
191-
192191
}
193192

194193
func encode(to encoder: Encoder) throws {

0 commit comments

Comments
 (0)