summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-18 00:23:35 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-18 00:23:35 +0100
commit8794e7fd1122448a76317eba2a6a67675788554d (patch)
treec64ff8c7fee9fd2736c33ba290f8fd68aa87d83f
parent99a8c00d819526186dd7ceb7d1eae30c85158bc2 (diff)
downloadnimgit-8794e7fd1122448a76317eba2a6a67675788554d.tar.gz
nimgit-8794e7fd1122448a76317eba2a6a67675788554d.tar.bz2
nimgit-8794e7fd1122448a76317eba2a6a67675788554d.zip
blob.nim: add procs lookupBlob, type, owner, id, shortId, content, size, isBinary
-rw-r--r--nimgit/blob.nim23
1 files changed, 23 insertions, 0 deletions
diff --git a/nimgit/blob.nim b/nimgit/blob.nim
new file mode 100644
index 0000000..e209ce1
--- /dev/null
+++ 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))