import times import nimgit2 import types, free, utils, oid, objects proc lookupCommit* (repo: GitRepository, oid: GitObjectId): GitCommit = let error = git_commit_lookup(addr result, repo, oid) if error != 0: free(result) raise newException(CatchableError, "Commit lookup failed: " & $error.getResultCode) proc copy* (commit: GitCommit): GitCommit = let error = git_commit_dup(addr result, commit) if error != 0: free(result) raise newException(CatchableError, "Cannot copy GitCommit: " & $error.getResultCode) proc type* (obj: GitCommit): GitObjectKind = cast[GitObject](obj).type proc owner* (commit: GitCommit): GitRepository = git_commit_owner(commit) proc repo* (commit: GitCommit): GitRepository = commit.owner() proc rawHeader* (commit: GitCommit): seq[byte] = cast[seq[byte]](git_commit_raw_header(commit)) proc id* (commit: GitCommit): GitObjectId = git_commit_id(commit) proc `$`* (commit: GitCommit): string = $commit.id() proc shortId* (commit: GitCommit): string = cast[GitObject](commit).shortId() proc summary* (commit: GitCommit): string = $git_commit_summary(commit) proc body* (commit: GitCommit): string = $git_commit_body(commit) proc message* (commit: GitCommit): string = $git_commit_message(commit) proc messageEncoding* (commit: GitCommit): string = $git_commit_message_encoding(commit) proc rawMessage* (commit: GitCommit): seq[byte] = cast[seq[byte]](git_commit_message_raw(commit)) proc gpgSignature* (commit: GitCommit): (string, string) = var signature: git_buf var signedData: git_buf let grc = git_commit_extract_signature(addr signature, addr signedData, commit.owner, commit.id, nil).getResultCode if grc != grcOk: free(addr signature); free(addr signedData); let error = getLastError() if grc == grcNotFound: return ("", "") else: raise newException(CatchableError, "Unkown Error while extracting signature: " & error.message) result = ($signature.ptr, $signed_data.ptr) free(addr signature); free(addr signedData); proc time* (commit: GitCommit): GitTime = result.time = fromUnix(git_commit_time(commit)) result.offset = git_commit_time_offset(commit) proc author* (commit: GitCommit): GitSignature = git_commit_author(commit).parseGitSignature proc committer* (commit: GitCommit): GitSignature = git_commit_committer(commit).parseGitSignature proc hasParents* (commit: GitCommit): bool = cast[bool](git_commit_parentcount(commit)) proc parentCount* (commit: GitCommit): int = cast[int](git_commit_parentcount(commit)) proc parentId* (commit: GitCommit, id: int = 0): GitObjectId = git_commit_parent_id(commit, cuint(id)) proc parentIds* (commit: GitCommit): seq[GitObjectId] = var counter: int let parentCount = commit.parentCount while counter < parentCount: result.add(commit.parentId(counter)) inc(counter) proc parent* (commit: GitCommit, id: int = 0): GitCommit = let error = git_commit_parent(addr result, commit, cuint(id)) if error != 0: free(result) raise newException(CatchableError, "parrent lookup failed: " & $error.getResultCode) proc parents* (commit: GitCommit): seq[GitCommit] = var counter: int let parentCount = commit.parentCount while counter < parentCount: result.add(commit.parent(counter)) inc(counter) proc treeId* (commit: GitCommit): GitObjectId = git_commit_tree_id(commit) proc tree* (commit: GitCommit): GitTree = let error = git_commit_tree(addr result, commit) if error != 0: free(result) raise newException(CatchableError, "tree lookup failed: " & $error.getResultCode)