Mercurial > hatta-flask
changeset 2383:773ac61f2ac6
Fix #45: Use the repository for page existence checks.
Note: The merging and subdirectory stroage still need files in the workingdir
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 11 May 2013 21:46:47 +0200 |
| parents | 823a6789db17 |
| children | b2bf2087cedb |
| files | hatta/storage.py |
| diffstat | 1 files changed, 28 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/hatta/storage.py Sat May 11 19:54:08 2013 +0200 +++ b/hatta/storage.py Sat May 11 21:46:47 2013 +0200 @@ -105,11 +105,13 @@ # Create the repository if needed. mercurial.hg.repository(self.ui, self.repo_path, create=True) self._repos = {} + self._tips = {} def reopen(self): """Close and reopen the repo, to make sure we are up to date.""" self._repos = {} + self._tips = {} @property def repo(self): @@ -168,9 +170,8 @@ return werkzeug.url_unquote(name) def __contains__(self, title): - if title: - file_path = self._file_path(title) - return os.path.isfile(file_path) and not os.path.islink(file_path) + repo_file = self._title_to_file(title) + return repo_file in self._changectx() def __iter__(self): return self.all_pages() @@ -262,6 +263,8 @@ match = mercurial.match.exact(self.repo_path, '', list(files)) return self.repo.commit(match=match, text=text, user=user, force=True) + finally: + self._tips = {} def save_data(self, title, data, author=u'', comment=u'', parent=None): """Save data as specified page.""" @@ -369,12 +372,18 @@ def _changectx(self): """Get the changectx of the tip.""" + thread_id = thread.get_ident() try: - # This is for Mercurial 1.0 - return self.repo.changectx() - except TypeError: - # Mercurial 1.3 (and possibly earlier) needs an argument - return self.repo.changectx('tip') + return self._tips[thread_id] + except KeyError: + try: + # This is for Mercurial 1.0 + tip = self.repo.changectx() + except TypeError: + # Mercurial 1.3 (and possibly earlier) needs an argument + tip = self.repo.changectx('tip') + self._tips[thread_id] = tip + return tip def _find_filectx(self, title): """Find the last revision in which the file existed.""" @@ -451,13 +460,11 @@ def all_pages(self): """Iterate over the titles of all pages in the wiki.""" - for filename in os.listdir(self.path): - file_path = os.path.join(self.path, filename) - file_repopath = os.path.join(self.repo_prefix, filename) - if (os.path.isfile(file_path) - and not os.path.islink(file_path) - and not filename.startswith('.')): - yield self._file_to_title(file_repopath) + for repo_file in self._changectx(): + if (repo_file.startswith(self.repo_prefix) and + '/' not in repo_file[len(self.repo_prefix):]): + title = self._file_to_title(repo_file) + yield title def changed_since(self, rev): """ @@ -585,18 +592,10 @@ raise def all_pages(self): - """ - Iterate over the titles of all pages in the wiki. - Include subdirectories but skip over index. - """ + """Iterate over the titles of all pages in the wiki.""" - for (dirpath, dirnames, filenames) in os.walk(self.path): - path = dirpath[len(self.path) + 1:] - if path.startswith('.'): - continue - for name in filenames: - filepath = os.path.join(dirpath, name) - repopath = os.path.join(self.repo_prefix, path, name) - if (os.path.isfile(filepath) - and not name.startswith('.')): - yield self._file_to_title(repopath) + for repo_file in self._changectx(): + if repo_file.startswith(self.repo_prefix): + title = self._file_to_title(repo_file) + yield title +
