summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-19 13:53:00 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-19 13:53:00 +0100
commit3b0ebb278320230256ebc2ae83e3696c1113bcba (patch)
treee92b0d3ba008f048872cd0adeb8afa0399f7005e
parent360711e20d8e71b7dd56a45091eec950ada13f4f (diff)
downloadnimgit-3b0ebb278320230256ebc2ae83e3696c1113bcba.tar.gz
nimgit-3b0ebb278320230256ebc2ae83e3696c1113bcba.tar.bz2
nimgit-3b0ebb278320230256ebc2ae83e3696c1113bcba.zip
tree.nim: new procs wak and entries, yield copys from iterator
-rw-r--r--nimgit/tree.nim23
1 files changed, 20 insertions, 3 deletions
diff --git a/nimgit/tree.nim b/nimgit/tree.nim
index 27dedaa..9a8c86b 100644
--- a/nimgit/tree.nim
+++ b/nimgit/tree.nim
@@ -1,5 +1,6 @@
+import sequtils
import nimgit2
-import types, free, utils, objects
+import types, free, objects, treeEntry
proc lookupTree* (repo: GitRepository, id: GitObjectId): GitTree =
let error = git_tree_lookup(addr result, repo, id)
@@ -47,5 +48,21 @@ iterator items* (tree: GitTree): GitTreeEntry =
let treeLen = tree.len
while counter < treeLen:
- yield tree.entry(counter)
- inc(counter) \ No newline at end of file
+ yield tree.entry(counter).copy()
+ inc(counter)
+
+proc walk* (tree: GitTree, path: string = ""): seq[(string, GitTreeEntry)] =
+ for entry in tree:
+ result.add((path, entry))
+
+ if entry.type == goTree:
+ let subtree = tree.owner.lookupTree(entry.id)
+ result = result.concat(subtree.walk(path & entry.name & "/"))
+ free(subtree)
+
+
+proc entries* (tree: GitTree): seq[string] =
+ for element in tree.walk:
+ let (dir, entry) = element
+ result.add(dir&entry.name)
+ free(entry) \ No newline at end of file