Skip to content

Commit 04f9449

Browse files
committed
[SourceControl] Add RepositorySpecifier: Hashable.
1 parent 11ba855 commit 04f9449

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Sources/SourceControl/Repository.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import Basic
1212

1313
/// Specifies a repository address.
14-
public struct RepositorySpecifier {
14+
public struct RepositorySpecifier: Hashable {
1515
/// The URL of the repository.
1616
public let url: String
1717

@@ -31,6 +31,13 @@ public struct RepositorySpecifier {
3131
let basename = url.components(separatedBy: "/").last!
3232
return basename + "-" + String(url.hashValue)
3333
}
34+
35+
public var hashValue: Int {
36+
return url.hashValue
37+
}
38+
}
39+
public func ==(lhs: RepositorySpecifier, rhs: RepositorySpecifier) -> Bool {
40+
return lhs.url == rhs.url
3441
}
3542

3643
/// A repository provider.

Tests/SourceControlTests/GitRepositoryTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ import TestSupport
1919
@testable import class SourceControl.GitRepository
2020

2121
class GitRepositoryTests: XCTestCase {
22+
/// Test the basic provider functions.
23+
func testRepositorySpecifier() {
24+
let a = RepositorySpecifier(url: "a")
25+
let b = RepositorySpecifier(url: "b")
26+
let a2 = RepositorySpecifier(url: "a")
27+
XCTAssertEqual(a, a)
28+
XCTAssertNotEqual(a, b)
29+
XCTAssertEqual(a, a2)
30+
XCTAssertEqual(Set([a]), Set([a2]))
31+
}
32+
2233
/// Test the basic provider functions.
2334
func testProvider() throws {
2435
mktmpdir { path in
@@ -185,6 +196,7 @@ class GitRepositoryTests: XCTestCase {
185196
}
186197

187198
static var allTests = [
199+
("testRepositorySpecifier", testRepositorySpecifier),
188200
("testProvider", testProvider),
189201
("testGitRepositoryHash", testGitRepositoryHash),
190202
("testRawRepository", testRawRepository),

0 commit comments

Comments
 (0)