Changing from using if to evaluates returned enum

to switch case syntax instead
This commit is contained in:
Arnon Keereena 2017-05-04 22:41:32 +02:00
parent 9520fa03a6
commit 8d1aaa672f
2 changed files with 14 additions and 12 deletions

View File

@ -47,23 +47,25 @@ public class CommitIterator: IteratorProtocol, Sequence {
} }
public func next() -> Element? { public func next() -> Element? {
var unsafeCommit: OpaquePointer? = nil
var oid = git_oid() var oid = git_oid()
let revwalkGitResult = git_revwalk_next(&oid, revisionWalker) let revwalkGitResult = git_revwalk_next(&oid, revisionWalker)
let nextResult = Next(revwalkGitResult, name: "git_revwalk_next") let nextResult = Next(revwalkGitResult, name: "git_revwalk_next")
if case let .error(error) = nextResult { switch nextResult {
case let .error(error):
return Result.failure(error) return Result.failure(error)
} else if case .over = nextResult { case .over:
return nil return nil
case .ok:
var unsafeCommit: OpaquePointer? = nil
let lookupGitResult = git_commit_lookup(&unsafeCommit, repo.pointer, &oid)
guard lookupGitResult == GIT_OK.rawValue,
let unwrapCommit = unsafeCommit else {
return Result.failure(NSError(gitError: lookupGitResult, pointOfFailure: "git_commit_lookup"))
}
let result: Element = Result.success(Commit(unwrapCommit))
git_commit_free(unsafeCommit)
return result
} }
let lookupGitResult = git_commit_lookup(&unsafeCommit, repo.pointer, &oid)
guard lookupGitResult == GIT_OK.rawValue,
let unwrapCommit = unsafeCommit else {
return Result.failure(NSError(gitError: lookupGitResult, pointOfFailure: "git_commit_lookup"))
}
let result: Element = Result.success(Commit(unwrapCommit))
git_commit_free(unsafeCommit)
return result
} }
public func makeIterator() -> CommitIterator { public func makeIterator() -> CommitIterator {

View File

@ -601,7 +601,7 @@ class RepositorySpec: QuickSpec {
} }
} }
fdescribe("Repository.allCommits(in:)") { describe("Repository.allCommits(in:)") {
it("should return all (9) commits") { it("should return all (9) commits") {
let repo = Fixtures.simpleRepository let repo = Fixtures.simpleRepository
let branches = repo.localBranches().value! let branches = repo.localBranches().value!