def page_text(self, title, revision=None):
"""Read unicode text of a page."""
ctx = self._find_filectx(title, revision)
-
+
if ctx is None:
raise DocumentNotFound(title)
-
+
return ctx.data().decode(self.charset, 'replace'), ctx.filerev()
def page_text_by_tag(self, title, tag):
return st_ino, st_size, st_mtime
@with_working_copy_locked
- def page_meta(self, title):
+ def page_meta(self, title, revision=None):
"""Get page's revision, date, last editor and his edit comment."""
- if not title in self:
- raise DocumentNotFound(title)
+ fctx = self._find_filectx(title, revision)
- filectx_tip = self._find_filectx(title)
- if filectx_tip is None:
+ if fctx is None:
raise DocumentNotFound(title)
- rev = filectx_tip.filerev()
- filectx = filectx_tip.filectx(rev)
- date = datetime.datetime.fromtimestamp(filectx.date()[0])
- author = filectx.user().decode("utf-8", 'replace')
- comment = filectx.description().decode("utf-8", 'replace')
- return rev, date, author, comment
+
+ return {
+ "revision": fctx.filerev(),
+ "date": datetime.datetime.fromtimestamp(fctx.date()[0]),
+ "author": fctx.user().decode("utf-8", 'replace'),
+ "comment": fctx.description().decode("utf-8", 'replace'),
+ }
def repo_revision(self):
return self.repo['tip'].rev()
"""Find the last revision in which the file existed."""
repo_file = self._title_to_file(title)
changectx = self._changectx() # start with tip
+ visited = set()
+
stack = [changectx]
+ visited.add(changectx)
while repo_file not in changectx:
if not stack:
- return None
+ raise DocumentNotFound(title)
changectx = stack.pop()
for parent in changectx.parents():
- if parent != changectx:
+ if parent not in visited:
stack.append(parent)
+ visited.add(parent)
try:
fctx = changectx[repo_file]