Changeset - 6fd0e1193f25
[Not reviewed]
default
0 1 0
Mads Kiilerich - 8 years ago 2018-05-11 14:26:48
mads@kiilerich.com
hg: trivial refactorings of annotate functionality

Prepare for changes coming up.
1 file changed with 4 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/hg/changeset.py
Show inline comments
 
@@ -276,57 +276,56 @@ class MercurialChangeset(BaseChangeset):
 
        return self.get_file_history(path, limit=1)[0]
 

	
 
    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, (aline, l) in enumerate(fctx.annotate(linenumber=False)):
 
            ln_no = i + 1
 
        annotations = self._get_filectx(path).annotate(linenumber=False)
 
        for i, (aline, l) in enumerate(annotations):
 
            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 sha=sha, l=l: self.repository.get_changeset(sha), l)
 
            sha = fctx.hex()
 
            yield (i + 1, sha, lambda sha=sha, l=l: 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)