Skip to content

Commit

Permalink
Remove unnecessary property, use the OID as should be
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnon Keereena committed May 2, 2017
1 parent 4dd24ca commit 500ae6d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions SwiftGit2/CommitIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import libgit2
public class CommitIterator: IteratorProtocol {
public typealias Element = Result<Commit, NSError>
let repo: Repository
private var oid: git_oid
private var revisionWalker: OpaquePointer? = nil

private enum Next {
Expand All @@ -31,19 +30,18 @@ public class CommitIterator: IteratorProtocol {

init(repo: Repository, branch: Branch) {
self.repo = repo
self.oid = branch.oid.oid
setupRevisionWalker()
}

deinit {
git_revwalk_free(self.revisionWalker)
}

private func setupRevisionWalker() {
private func setupRevisionWalker(branch: Branch) {
git_revwalk_new(&revisionWalker, repo.pointer)
git_revwalk_sorting(revisionWalker, GIT_SORT_TOPOLOGICAL.rawValue)
git_revwalk_sorting(revisionWalker, GIT_SORT_TIME.rawValue)
git_revwalk_push(revisionWalker, &oid)
git_revwalk_push(revisionWalker, &branch.oid.oid)
}

private func next(withName name: String, from result: Int32) -> Next {
Expand All @@ -56,14 +54,16 @@ public class CommitIterator: IteratorProtocol {

public func next() -> Element? {
var unsafeCommit: OpaquePointer? = nil
var oid = git_oid()
let revwalkGitResult = git_revwalk_next(&oid, revisionWalker)
let nextResult = next(withName: "git_revwalk_next", from: revwalkGitResult)
if case let .error(error) = nextResult {
return Result.failure(error)
} else if case .over = nextResult {
return nil
}
guard git_commit_lookup(&unsafeCommit, repo.pointer, &oid) == GIT_OK.rawValue,
let lookupGitResult = git_commit_lookup(&unsafeCommit, repo.pointer, &oid)
guard lookupGitResult == GIT_OK.rawValue,
let unwrapCommit = unsafeCommit else {
return nil
}
Expand Down

0 comments on commit 500ae6d

Please sign in to comment.