summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-18 00:17:09 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-18 00:17:09 +0100
commita2b30f12bd5ae2a4a770b91fb489b4ccaff46c3e (patch)
tree85ea080ca53c3073fde409e107915c5d242e3096
parent3f964043f3a3f25d54a4f11b39eff93592c31e2c (diff)
downloadnimgit-a2b30f12bd5ae2a4a770b91fb489b4ccaff46c3e.tar.gz
nimgit-a2b30f12bd5ae2a4a770b91fb489b4ccaff46c3e.tar.bz2
nimgit-a2b30f12bd5ae2a4a770b91fb489b4ccaff46c3e.zip
object.nim: rename proc kind -> type; new proc shortId
-rw-r--r--nimgit/objects.nim15
1 files changed, 14 insertions, 1 deletions
diff --git a/nimgit/objects.nim b/nimgit/objects.nim
index 93792e8..bc6792d 100644
--- 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);