ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

commit c7bde4b62a44ed33e11e3ce3bb28678817e0a7fb
parent c4dae0726f643688e1c1b05f5b58a1706ed930a4
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Mar 2021 00:27:18 +0100

treeEntry.nim: new procs type, id, name, mode, getObject
1 file changed, 17 insertions(+), 0 deletions(-)
A
nimgit/treeEntry.nim
|
17
+++++++++++++++++
diff --git a/nimgit/treeEntry.nim b/nimgit/treeEntry.nim
@@ -0,0 +1,17 @@
+import nimgit2
+import types, free, utils
+
+proc type* (entry: GitTreeEntry): GitObjectKind = GitObjectKind(git_tree_entry_type(entry) - GIT_OBJECT_ANY)
+
+proc id* (entry: GitTreeEntry): GitObjectId = git_tree_entry_id(entry)
+
+proc name* (entry: GitTreeEntry): string = $git_tree_entry_name(entry)
+
+proc mode* (entry: GitTreeEntry): int = cast[int](git_tree_entry_filemode(entry))
+
+proc getObject* (repo: GitRepository, entry: GitTreeEntry): GitObject =
+    let error = git_tree_entry_to_object(addr result, repo, entry)
+
+    if error != 0:
+        free(result)
+        raise newException(CatchableError, "Cannot convert tree-entry into object: " & $error.getResultCode)