ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit 998d8ef5a4bf37fbdcfef9b55f8d279df6e62855
parent b2fc1ab137ddf5da457942d018ce002037bd7b39
Author: Leah (ctucx) <leah@ctu.cx>
Date: Wed, 17 Mar 2021 02:25:42 +0100

commit.nim: new procs: $, getParrentCount, getParrentId, getTree
1 file changed, 13 insertions(+), 1 deletion(-)
M
nimgit/commit.nim
|
14
+++++++++++++-
diff --git a/nimgit/commit.nim b/nimgit/commit.nim
@@ -11,6 +11,7 @@ proc lookupCommit* (repo: GitRepository, oid: GitObjectId): GitCommit =
 
 proc getObjectId* (commit: GitCommit): GitObjectId = git_commit_id(commit)
 
+proc `$`* (commit: GitCommit): string = $commit.getObjectId()
 
 proc getSummary* (commit: GitCommit): string = $git_commit_summary(commit)
 

@@ -26,7 +27,6 @@ proc getAuthor* (commit: GitCommit): GitSignature =
     result.email = $author.email
     result.when  = parseGitTime(author.when)
 
-
 proc getCommitter* (commit: GitCommit): GitSignature =
     let author = git_commit_committer(commit)
 

@@ -35,9 +35,21 @@ proc getCommitter* (commit: GitCommit): GitSignature =
     result.when  = parseGitTime(author.when)
 
 
+proc getParrentCount* (commit: GitCommit): int = cast[int](git_commit_parentcount(commit))
+
+proc getParrentId* (commit: GitCommit): GitObjectId = git_commit_parent_id(commit, 0)
+
 proc getParrent* (commit: GitCommit): GitCommit =
     let error = git_commit_parent(addr result, commit, 0)
 
     if error != 0:
         free(result)
         raise newException(CatchableError, "parrent lookup failed: " & $error.getResultCode)
+
+
+proc getTree* (commit: GitCommit): GitTree =
+    let error = git_commit_tree(addr result, commit)
+
+    if error != 0:
+        free(result)
+        raise newException(CatchableError, "tree lookup failed: " & $error.getResultCode)