- addr = self._file_path(title)
- mime, encoding = mimetypes.guess_type(addr, strict=False)
- if encoding:
- mime = 'archive/%s' % encoding
- if mime is None:
- mime = 'text/x-wiki'
- return mime
-
- def _changectx(self):
- """Get the changectx of the tip."""
- 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')
-
- def _find_filectx(self, title):
- """Find the last revision in which the file existed."""
-
- repo_file = self._title_to_file(title)
- changectx = self._changectx()
- stack = [changectx]
- while repo_file not in changectx:
- if not stack:
- return None
- changectx = stack.pop()
- for parent in changectx.parents():
- if parent != changectx:
- stack.append(parent)
- return changectx[repo_file]
+ def _find_filectx(self, title, rev=None):
+ """
+ Find the revision of the file in repo.
+ Only look for files still existing in repo's tip.
+ """
+ tip = self._changectx()
+ file = self._title_to_file(title)
+ logging.info('Looking for %s', file)
+ if file in tip:
+ fctx = tip[file]
+ else:
+ file = self._title_to_file(title, type='')
+ logging.info('.xml not found, trying plain')
+ if file in tip:
+ fctx = tip[file]
+ else:
+ raise DocumentNotFound(title)
+
+ if rev is not None:
+ fctx = fctx.filectx(rev)
+ fctx.filerev()
+ return fctx