Skip to content

Commit ecb9716

Browse files
committed
[Workspace] Eliminate suffix from checkouts dirname
We don't expect to ever have two checkouts with same name at a time so there is no need of a suffix for them. <rdar://problem/46423708>
1 parent 1fab572 commit ecb9716

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Sources/SourceControl/Repository.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ public struct RepositorySpecifier: Hashable {
2525
/// This identifier is suitable for use in a file system path, and
2626
/// unique for each repository.
2727
public var fileSystemIdentifier: String {
28-
var basename = url.components(separatedBy: "/").last!
29-
if basename.hasSuffix(".git") {
30-
basename = String(basename.dropLast(4))
31-
}
32-
3328
// Use first 8 chars of a stable hash.
3429
let hash = SHA256(url).digestString()
3530
let suffix = hash.dropLast(hash.count - 8)
3631

3732
return basename + "-" + suffix
3833
}
34+
35+
/// Returns the cleaned basename for the specifier.
36+
public var basename: String {
37+
var basename = url.components(separatedBy: "/").last!
38+
if basename.hasSuffix(".git") {
39+
basename = String(basename.dropLast(4))
40+
}
41+
return basename
42+
}
3943
}
4044

4145
extension RepositorySpecifier: CustomStringConvertible {

Sources/Workspace/Workspace.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,17 @@ extension Workspace {
16831683
return
16841684
}
16851685

1686+
// First remove the checkouts that are no longer required.
1687+
for (packageRef, state) in packageStateChanges {
1688+
diagnostics.wrap {
1689+
switch state {
1690+
case .added, .updated, .unchanged: break
1691+
case .removed:
1692+
try remove(package: packageRef)
1693+
}
1694+
}
1695+
}
1696+
16861697
// Update or clone new packages.
16871698
for (packageRef, state) in packageStateChanges {
16881699
diagnostics.wrap {
@@ -1691,9 +1702,7 @@ extension Workspace {
16911702
_ = try clone(package: packageRef, requirement: requirement)
16921703
case .updated(let requirement):
16931704
_ = try clone(package: packageRef, requirement: requirement)
1694-
case .removed:
1695-
try remove(package: packageRef)
1696-
case .unchanged: break
1705+
case .removed, .unchanged: break
16971706
}
16981707
}
16991708
}
@@ -1745,7 +1754,7 @@ extension Workspace {
17451754
}
17461755

17471756
// Clone the repository into the checkouts.
1748-
let path = checkoutsPath.appending(component: package.repository.fileSystemIdentifier)
1757+
let path = checkoutsPath.appending(component: package.repository.basename)
17491758

17501759
try fileSystem.chmod(.userWritable, path: path, options: [.recursive, .onlyFiles])
17511760
try fileSystem.removeFileTree(path)

0 commit comments

Comments
 (0)