- repo_file = self._title_to_file(title)
- changectx = self._changectx()
- stack = [changectx]
- while repo_file not in changectx:
- if not stack:
- return None
- changectx = stack.pop()
- for parent in changectx.parents():
- if parent != changectx:
- stack.append(parent)
- return changectx[repo_file]
+ def tree_search(tip, repo_file):
+ logging.info("Searching for %r", repo_file)
+ current = tip
+ visited = set()
+
+ stack = [current]
+ visited.add(current)
+
+ while repo_file not in current:
+ if not stack:
+ raise LookupError
+
+ current = stack.pop()
+ for parent in current.parents():
+ if parent not in visited:
+ stack.append(parent)
+ visited.add(parent)
+
+ fctx = current[repo_file]
+ if rev is not None:
+ fctx = fctx.filectx(rev)
+ fctx.filerev()
+ return fctx
+
+ try:
+ return tree_search(tip, self._title_to_file(title))
+ except (IndexError, LookupError) as e:
+ logging.info("XML file not found, trying plain")
+ try:
+ return tree_search(tip, self._title_to_file(title, type=''))
+ except (IndexError, LookupError) as e:
+ raise DocumentNotFound(title)