Changeset - c326db109854
[Not reviewed]
default
0 1 0
Mads Kiilerich - 8 years ago 2017-10-23 00:57:28
mads@kiilerich.com
vcs: add support for Mercurial annotate in Mercurial 4.4

Mercurial fctx.annotate() returns tuples with two elements: info about the
annotate line and the actual line. The code is changed to clarify that.

After Mercurial 4.4 with https://www.mercurial-scm.org/repo/hg/rev/2e32c6a31cc7 ,
the info is no longer a tuple but an attr object. Assume fctx is available as
an attribute, but catch exceptions and fall back to indexing as before.

That can't easily be done in hgcompat, so we do it inline.
1 file changed with 7 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/hg/changeset.py
Show inline comments
 
@@ -273,52 +273,56 @@ class MercurialChangeset(BaseChangeset):
 

	
 
    def get_file_history(self, path, limit=None):
 
        """
 
        Returns history of file as reversed list of ``Changeset`` objects for
 
        which file at given ``path`` has been modified.
 
        """
 
        fctx = self._get_filectx(path)
 
        hist = []
 
        cnt = 0
 
        for cs in reversed([x for x in fctx.filelog()]):
 
            cnt += 1
 
            hist.append(hex(fctx.filectx(cs).node()))
 
            if limit is not None and cnt == limit:
 
                break
 

	
 
        return [self.repository.get_changeset(node) for node in hist]
 

	
 
    def get_file_annotate(self, path):
 
        """
 
        Returns a generator of four element tuples with
 
            lineno, sha, changeset lazy loader and line
 
        """
 

	
 
        fctx = self._get_filectx(path)
 
        for i, annotate_data in enumerate(fctx.annotate(linenumber=False)):
 
        for i, (aline, l) in enumerate(fctx.annotate(linenumber=False)):
 
            ln_no = i + 1
 
            sha = hex(annotate_data[0][0].node())
 
            yield (ln_no, sha, lambda: self.repository.get_changeset(sha), annotate_data[1],)
 
            try:
 
                fctx = aline.fctx
 
            except AttributeError: # aline.fctx was introduced in Mercurial 4.4
 
                fctx = aline[0]
 
            sha = hex(fctx.node())
 
            yield (ln_no, sha, lambda: self.repository.get_changeset(sha), l)
 

	
 
    def fill_archive(self, stream=None, kind='tgz', prefix=None,
 
                     subrepos=False):
 
        """
 
        Fills up given stream.
 

	
 
        :param stream: file like object.
 
        :param kind: one of following: ``zip``, ``tgz`` or ``tbz2``.
 
            Default: ``tgz``.
 
        :param prefix: name of root directory in archive.
 
            Default is repository name and changeset's raw_id joined with dash
 
            (``repo-tip.<KIND>``).
 
        :param subrepos: include subrepos in this archive.
 

	
 
        :raise ImproperArchiveTypeError: If given kind is wrong.
 
        :raise VcsError: If given stream is None
 
        """
 

	
 
        allowed_kinds = settings.ARCHIVE_SPECS.keys()
 
        if kind not in allowed_kinds:
 
            raise ImproperArchiveTypeError('Archive kind not supported use one'
 
                'of %s', allowed_kinds)
 

	
 
        if stream is None:
0 comments (0 inline, 0 general)