ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit a2b30f12bd5ae2a4a770b91fb489b4ccaff46c3e
parent 3f964043f3a3f25d54a4f11b39eff93592c31e2c
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Mar 2021 00:17:09 +0100

object.nim: rename proc kind -> type; new proc shortId
1 file changed, 14 insertions(+), 2 deletions(-)
M
nimgit/objects.nim
|
16
++++++++++++++--
diff --git a/nimgit/objects.nim b/nimgit/objects.nim
@@ -21,4 +21,17 @@ proc lookupObject* (repo: GitRepository, name: string): GitObject =
             of grcInvalidSpec: raise newException(CatchableError, "Object lookup was ambiguous")
             else: raise newException(CatchableError, "Object lookup failed: " & $error)
 
-proc kind* (obj: GitObject): GitObjectKind = GitObjectKind(git_object_type(obj) - GIT_OBJECT_ANY)-
\ No newline at end of file
+proc type* (obj: GitObject): GitObjectKind = GitObjectKind(git_object_type(obj) - GIT_OBJECT_ANY)
+
+proc shortId* (obj: GitObject): string =
+    var buffer: git_buf
+
+    let error = git_object_short_id(addr buffer, obj)
+
+    if error != 0:
+        git_buf_dispose(addr buffer);
+        raise newException(CatchableError, "Cannot short id: " & $error.getResultCode)
+
+    result = $buffer.ptr
+
+    git_buf_dispose(addr buffer);