X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/00a90d6175599e055f5a84697c8388d81ac1b007..404bfe407798a8a83fa02dc1742a315400b7c00b:/lib/vstorage.py diff --git a/lib/vstorage.py b/lib/vstorage.py index f3480744..b4acaf3a 100644 --- a/lib/vstorage.py +++ b/lib/vstorage.py @@ -269,6 +269,10 @@ class VersionedStorage(object): 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): @@ -293,20 +297,19 @@ class VersionedStorage(object): 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() @@ -325,16 +328,20 @@ class VersionedStorage(object): """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]