summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-18 00:27:18 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-18 00:27:18 +0100
commitc7bde4b62a44ed33e11e3ce3bb28678817e0a7fb (patch)
tree020084d674f5c48eee3d4082cf90eff7fd8a99f1
parentc4dae0726f643688e1c1b05f5b58a1706ed930a4 (diff)
downloadnimgit-c7bde4b62a44ed33e11e3ce3bb28678817e0a7fb.tar.gz
nimgit-c7bde4b62a44ed33e11e3ce3bb28678817e0a7fb.tar.bz2
nimgit-c7bde4b62a44ed33e11e3ce3bb28678817e0a7fb.zip
treeEntry.nim: new procs type, id, name, mode, getObject
-rw-r--r--nimgit/treeEntry.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/nimgit/treeEntry.nim b/nimgit/treeEntry.nim
new file mode 100644
index 0000000..8dd30e2
--- /dev/null
+++ 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)