mirror of
https://github.com/gosticks/SwiftGit2.git
synced 2025-10-16 11:55:34 +00:00
Changing from using if to evaluates returned enum
to switch case syntax instead
This commit is contained in:
parent
9520fa03a6
commit
8d1aaa672f
@ -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 {
|
||||||
|
|||||||
@ -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!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user