ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit 8794e7fd1122448a76317eba2a6a67675788554d
parent 99a8c00d819526186dd7ceb7d1eae30c85158bc2
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Mar 2021 00:23:35 +0100

blob.nim: add procs lookupBlob, type, owner, id, shortId, content, size, isBinary
1 file changed, 23 insertions(+), 0 deletions(-)
A
nimgit/blob.nim
|
23
+++++++++++++++++++++++
diff --git a/nimgit/blob.nim b/nimgit/blob.nim
@@ -0,0 +1,23 @@
+import nimgit2
+import types, free, objects
+
+proc lookupBlob* (repo: GitRepository, id: GitObjectId): GitBlob =
+    let error = git_blob_lookup(addr result, repo, id)
+
+    if error != 0:
+        free(result)
+        raise newException(CatchableError, "Blob lookup failed: " & $error.getResultCode)
+
+proc type* (obj: GitBlob): GitObjectKind = cast[GitObject](obj).type
+
+proc owner* (blob: GitBlob): GitRepository = git_blob_owner(blob)
+
+proc id* (blob: GitBlob): GitObjectId = git_blob_id(blob)
+
+proc shortId* (blob: GitBlob): string = cast[GitObject](blob).shortId()
+
+proc content* (blob: GitBlob): string = cast[string](git_blob_rawcontent(blob))
+
+proc size* (blob: GitBlob): int = cast[int](git_blob_rawsize(blob))
+
+proc isBinary* (blob: GitBlob): bool = cast[bool](git_blob_is_binary(blob))