commit 3b0ebb278320230256ebc2ae83e3696c1113bcba
parent 360711e20d8e71b7dd56a45091eec950ada13f4f
Author: Leah (ctucx) <leah@ctu.cx>
Date: Fri, 19 Mar 2021 13:53:00 +0100
parent 360711e20d8e71b7dd56a45091eec950ada13f4f
Author: Leah (ctucx) <leah@ctu.cx>
Date: Fri, 19 Mar 2021 13:53:00 +0100
tree.nim: new procs wak and entries, yield copys from iterator
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git 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