summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-17 18:27:33 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-17 18:27:33 +0100
commitb84069a736b112dc50f1a371d890e9c1003f1ac7 (patch)
treee23625e76d5211bcb00d5da97ccd10d7391420b9
parentc563d6b781509730e3f1a34e9135d79043555b77 (diff)
downloadnimgit-b84069a736b112dc50f1a371d890e9c1003f1ac7.tar.gz
nimgit-b84069a736b112dc50f1a371d890e9c1003f1ac7.tar.bz2
nimgit-b84069a736b112dc50f1a371d890e9c1003f1ac7.zip
commit.nim: new procs rawHeader, rawMessage, gpgSignature, time, parentIds, parents
-rw-r--r--nimgit/commit.nim50
1 files changed, 50 insertions, 0 deletions
diff --git a/nimgit/commit.nim b/nimgit/commit.nim
index a990ca7..f0f7a05 100644
--- a/nimgit/commit.nim
+++ b/nimgit/commit.nim
@@ -1,3 +1,4 @@
+import times
import nimgit2
import types, free, utils, oid
@@ -12,6 +13,8 @@ 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()
@@ -24,6 +27,36 @@ 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 =
let author = git_commit_author(commit)
@@ -45,6 +78,14 @@ proc parentCount* (commit: GitCommit): int = cast[int](git_commit_parentcount(co
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))
@@ -52,6 +93,15 @@ proc parent* (commit: GitCommit, id: int = 0): GitCommit =
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 =