X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/d64a8451dafc98e8f71455a55d123d22f3368ef9..3b5377ca573c6406bc525d0d5d1993a50e74c56d:/lib/vstorage.py diff --git a/lib/vstorage.py b/lib/vstorage.py index 24d5ec9d..b4acaf3a 100644 --- a/lib/vstorage.py +++ b/lib/vstorage.py @@ -269,10 +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): @@ -297,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() @@ -329,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]