diff --git a/kallithea/lib/vcs/backends/hg/changeset.py b/kallithea/lib/vcs/backends/hg/changeset.py --- a/kallithea/lib/vcs/backends/hg/changeset.py +++ b/kallithea/lib/vcs/backends/hg/changeset.py @@ -1,22 +1,15 @@ import os import posixpath +from kallithea.lib.vcs.backends.base import BaseChangeset from kallithea.lib.vcs.conf import settings -from kallithea.lib.vcs.backends.base import BaseChangeset -from kallithea.lib.vcs.exceptions import ( - ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, - NodeDoesNotExistError, VCSError -) +from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError from kallithea.lib.vcs.nodes import ( - AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, - NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode -) -from kallithea.lib.vcs.utils import safe_str, safe_unicode, date_fromtimestamp + AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode) +from kallithea.lib.vcs.utils import date_fromtimestamp, safe_str, safe_unicode +from kallithea.lib.vcs.utils.hgcompat import archival, hex, obsutil from kallithea.lib.vcs.utils.lazy import LazyProperty from kallithea.lib.vcs.utils.paths import get_dirs_for_path -from kallithea.lib.vcs.utils.hgcompat import archival, hex - -from mercurial import obsolete class MercurialChangeset(BaseChangeset): @@ -88,13 +81,7 @@ class MercurialChangeset(BaseChangeset): @LazyProperty def successors(self): - try: - # This works starting from Mercurial 4.3: the function `successorssets` was moved to the mercurial.obsutil module and gained the `closest` parameter. - from mercurial import obsutil - successors = obsutil.successorssets(self._ctx._repo, self._ctx.node(), closest=True) - except ImportError: - # fallback for older versions - successors = obsolete.successorssets(self._ctx._repo, self._ctx.node()) + successors = obsutil.successorssets(self._ctx._repo, self._ctx.node(), closest=True) if successors: # flatten the list here handles both divergent (len > 1) # and the usual case (len = 1) @@ -104,19 +91,7 @@ class MercurialChangeset(BaseChangeset): @LazyProperty def predecessors(self): - try: - # This works starting from Mercurial 4.3: the function `closestpredecessors` was added. - from mercurial import obsutil - return [hex(n)[:12] for n in obsutil.closestpredecessors(self._ctx._repo, self._ctx.node())] - except ImportError: - # fallback for older versions - predecessors = set() - nm = self._ctx._repo.changelog.nodemap - for p in self._ctx._repo.obsstore.precursors.get(self._ctx.node(), ()): - pr = nm.get(p[0]) - if pr is not None: - predecessors.add(hex(p[0])[:12]) - return predecessors + return [hex(n)[:12] for n in obsutil.closestpredecessors(self._ctx._repo, self._ctx.node())] @LazyProperty def bookmarks(self): @@ -320,10 +295,7 @@ class MercurialChangeset(BaseChangeset): try: annotation_lines = [(annotateline.fctx, annotateline.text) for annotateline in annotations] except AttributeError: # annotateline was introduced in Mercurial 4.6 (b33b91ca2ec2) - try: - annotation_lines = [(aline.fctx, l) for aline, l in annotations] - except AttributeError: # aline.fctx was introduced in Mercurial 4.4 - annotation_lines = [(aline[0], l) for aline, l in annotations] + annotation_lines = [(aline.fctx, l) for aline, l in annotations] for i, (fctx, l) in enumerate(annotation_lines): sha = fctx.hex() yield (i + 1, sha, lambda sha=sha, l=l: self.repository.get_changeset(sha), l) @@ -348,7 +320,7 @@ class MercurialChangeset(BaseChangeset): allowed_kinds = settings.ARCHIVE_SPECS.keys() if kind not in allowed_kinds: raise ImproperArchiveTypeError('Archive kind not supported use one' - 'of %s', allowed_kinds) + 'of %s' % allowed_kinds) if stream is None: raise VCSError('You need to pass in a valid stream for filling'