ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit b618202dea40a066535144ec552259c83d3ea944
parent a2b30f12bd5ae2a4a770b91fb489b4ccaff46c3e
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Mar 2021 00:21:22 +0100

commit.nim: new procs type, shortId
1 file changed, 9 insertions(+), 16 deletions(-)
M
nimgit/commit.nim
|
25
+++++++++----------------
diff --git a/nimgit/commit.nim b/nimgit/commit.nim
@@ -1,6 +1,6 @@
 import times
 import nimgit2
-import types, free, utils, oid
+import types, free, utils, oid, objects
 
 proc lookupCommit* (repo: GitRepository, oid: GitObjectId): GitCommit =
     let error = git_commit_lookup(addr result, repo, oid)

@@ -9,6 +9,8 @@ proc lookupCommit* (repo: GitRepository, oid: GitObjectId): GitCommit =
         free(result)
         raise newException(CatchableError, "Commit lookup failed: " & $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()

@@ -19,6 +21,8 @@ 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)

@@ -53,24 +57,13 @@ proc gpgSignature* (commit: GitCommit): (string, string) =
 
 
 proc time* (commit: GitCommit): GitTime =
-    result.time     = fromUnix(git_commit_time(commit))
-    result.offset   = git_commit_time_offset(commit)
-
-
-proc author* (commit: GitCommit): GitSignature =
-    let author = git_commit_author(commit)
-
-    result.name  = $author.name
-    result.email = $author.email
-    result.when  = parseGitTime(author.when)
+    result.time   = fromUnix(git_commit_time(commit))
+    result.offset = git_commit_time_offset(commit)
 
-proc committer* (commit: GitCommit): GitSignature =
-    let author = git_commit_committer(commit)
 
-    result.name  = $author.name
-    result.email = $author.email
-    result.when  = parseGitTime(author.when)
+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))