X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3eec01e4c2a842c7383857e49d68664f04759c1f..f1aa11d3c90925a0ecc4f7db2df571aabf99fc3e:/lib/vstorage.py diff --git a/lib/vstorage.py b/lib/vstorage.py index 1060bc25..00f844ad 100644 --- a/lib/vstorage.py +++ b/lib/vstorage.py @@ -144,11 +144,11 @@ class VersionedStorage(object): return urlunquote(name) def __contains__(self, title): - return os.path.exists(self._file_path(title)) + return urlquote(title) in self.repo.dirstate def __iter__(self): - return self.all_pages() - + return self.all_pages() + def merge_changes(self, changectx, repo_file, text, user, parent): """Commits and merges conflicting changes in the repository.""" tip_node = changectx.node() @@ -165,16 +165,19 @@ class VersionedStorage(object): if p1 == p2: return text - # TODO: Check if merge was successful - mercurial.merge.update(self.repo, tip_node, True, False, partial) - + try: + mercurial.merge.update(self.repo, tip_node, True, False, partial) + msg = 'merge of edit conflict' + except mercurial.util.Abort: + msg = 'failed merge of edit conflict' + self.repo.dirstate.setparents(tip_node, node) # Mercurial 1.1 and later need updating the merge state try: mercurial.merge.mergestate(self.repo).mark(repo_file, "r") except (AttributeError, KeyError): pass - return u'merge of edit conflict' + return msg @locked_repo def save_file(self, title, file_name, author=u'', comment=u'', parent=None): @@ -261,6 +264,9 @@ class VersionedStorage(object): self._commit([repo_file], text, user) def open_page(self, title): + if title not in self: + raise DocumentNotFound() + try: return open(self._file_path(title), "rb") except IOError: @@ -278,11 +284,12 @@ class VersionedStorage(object): def page_meta(self, title): """Get page's revision, date, last editor and his edit comment.""" - + if not title in self: + raise DocumentNotFound() + filectx_tip = self._find_filectx(title) if filectx_tip is None: raise DocumentNotFound() - #return -1, None, u'', u'' rev = filectx_tip.filerev() filectx = filectx_tip.filectx(rev) date = datetime.datetime.fromtimestamp(filectx.date()[0]) @@ -381,11 +388,10 @@ class VersionedStorage(object): def all_pages(self): """Iterate over the titles of all pages in the wiki.""" - - for filename in os.listdir(self.path): - if (os.path.isfile(os.path.join(self.path, filename)) - and not filename.startswith('.')): - yield urlunquote(filename) + status = self.repo.status(self.repo[None], None, None, True, True, True) + clean_files = status[6] + for filename in clean_files: + yield urlunquote(filename) def changed_since(self, rev): """Return all pages that changed since specified repository revision."""