# HG changeset patch # User Marcin Kuzminski # Date 2019-03-05 19:05:53 # Node ID f4b31a7a9b8f964074bb3fee4a4e960a539d25e5 # Parent c518c95af1d55d895122c86c4c6d9ea0f39bc20b hg: added compat for fetching revision using new hg 4.9 code diff --git a/vcsserver/hg.py b/vcsserver/hg.py --- a/vcsserver/hg.py +++ b/vcsserver/hg.py @@ -32,11 +32,11 @@ import vcsserver from vcsserver import exceptions from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original from vcsserver.hgcompat import ( - archival, bin, clone, config as hgconfig, diffopts, hex, revsymbol, + archival, bin, clone, config as hgconfig, diffopts, hex, get_ctx, hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler, makepeer, instance, match, memctx, exchange, memfilectx, nullrev, patch, peer, revrange, ui, hg_tag, Abort, LookupError, RepoError, - RepoLookupError, ProgrammingError, InterventionRequired, RequirementError) + RepoLookupError, InterventionRequired, RequirementError) log = logging.getLogger(__name__) @@ -141,6 +141,9 @@ class HgRemote(object): "_file_paths": self.ctx_list, } + def _get_ctx(self, repo, ref): + return get_ctx(repo, ref) + @reraise_safe_exceptions def discover_hg_version(self): from mercurial import util @@ -257,74 +260,74 @@ class HgRemote(object): @reraise_safe_exceptions def ctx_branch(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.branch() @reraise_safe_exceptions def ctx_children(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return [child.rev() for child in ctx.children()] @reraise_safe_exceptions def ctx_date(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.date() @reraise_safe_exceptions def ctx_description(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.description() @reraise_safe_exceptions def ctx_files(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.files() @reraise_safe_exceptions def ctx_list(self, path, revision): repo = self._factory.repo(path) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return list(ctx) @reraise_safe_exceptions def ctx_parents(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return [parent.rev() for parent in ctx.parents()] @reraise_safe_exceptions def ctx_phase(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) # public=0, draft=1, secret=3 return ctx.phase() @reraise_safe_exceptions def ctx_obsolete(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.obsolete() @reraise_safe_exceptions def ctx_hidden(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.hidden() @reraise_safe_exceptions def ctx_substate(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.substate @reraise_safe_exceptions def ctx_status(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) status = repo[ctx.p1().node()].status(other=ctx.node()) # object of status (odd, custom named tuple in mercurial) is not # correctly serializable, we make it a list, as the underling @@ -334,7 +337,7 @@ class HgRemote(object): @reraise_safe_exceptions def ctx_user(self, wire, revision): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) return ctx.user() @reraise_safe_exceptions @@ -424,7 +427,7 @@ class HgRemote(object): def node_history(self, wire, revision, path, limit): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) fctx = ctx.filectx(path) def history_iter(): @@ -445,7 +448,7 @@ class HgRemote(object): @reraise_safe_exceptions def node_history_untill(self, wire, revision, path, limit): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) fctx = ctx.filectx(path) file_log = list(fctx.filelog()) @@ -458,7 +461,7 @@ class HgRemote(object): @reraise_safe_exceptions def fctx_annotate(self, wire, revision, path): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) fctx = ctx.filectx(path) result = [] @@ -472,21 +475,21 @@ class HgRemote(object): @reraise_safe_exceptions def fctx_data(self, wire, revision, path): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) fctx = ctx.filectx(path) return fctx.data() @reraise_safe_exceptions def fctx_flags(self, wire, revision, path): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) fctx = ctx.filectx(path) return fctx.flags() @reraise_safe_exceptions def fctx_size(self, wire, revision, path): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) fctx = ctx.filectx(path) return fctx.size() @@ -555,12 +558,7 @@ class HgRemote(object): if revision <= 0: revision = revision + -1 try: - try: - ctx = repo[revision] - except ProgrammingError: - # we're unable to find the rev using a regular lookup, we fallback - # to slower, but backward compat revsymbol usage - ctx = revsymbol(repo, revision) + ctx = self._get_ctx(repo, revision) except (TypeError, RepoLookupError) as e: e._org_exc_tb = traceback.format_exc() raise exceptions.LookupException(e)(revision) @@ -611,7 +609,7 @@ class HgRemote(object): @reraise_safe_exceptions def revision(self, wire, rev): repo = self._factory.repo(wire) - ctx = repo[rev] + ctx = self._get_ctx(repo, rev) return ctx.rev() @reraise_safe_exceptions @@ -652,7 +650,7 @@ class HgRemote(object): @reraise_safe_exceptions def strip(self, wire, revision, update, backup): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) hgext_strip( repo.baseui, repo, ctx.node(), update=update, backup=backup) @@ -675,7 +673,7 @@ class HgRemote(object): def tag(self, wire, name, revision, message, local, user, tag_time, tag_timezone): repo = self._factory.repo(wire) - ctx = repo[revision] + ctx = self._get_ctx(repo, revision) node = ctx.node() date = (tag_time, tag_timezone) diff --git a/vcsserver/hgcompat.py b/vcsserver/hgcompat.py --- a/vcsserver/hgcompat.py +++ b/vcsserver/hgcompat.py @@ -61,3 +61,14 @@ from hgext import largefiles # those authnadlers are patched for python 2.6.5 bug an # infinit looping when given invalid resources from mercurial.url import httpbasicauthhandler, httpdigestauthhandler + + +def get_ctx(repo, ref): + try: + ctx = repo[ref] + except ProgrammingError: + # we're unable to find the rev using a regular lookup, we fallback + # to slower, but backward compat revsymbol usage + ctx = revsymbol(repo, ref) + + return ctx diff --git a/vcsserver/hooks.py b/vcsserver/hooks.py --- a/vcsserver/hooks.py +++ b/vcsserver/hooks.py @@ -33,6 +33,7 @@ import mercurial.node import simplejson as json from vcsserver import exceptions, subprocessio, settings +from vcsserver.hgcompat import get_ctx log = logging.getLogger(__name__) @@ -177,11 +178,11 @@ def _rev_range_hash(repo, node, check_he commits = [] revs = [] - start = repo[node].rev() + start = get_ctx(repo, node).rev() end = len(repo) for rev in range(start, end): revs.append(rev) - ctx = repo[rev] + ctx = get_ctx(repo, rev) commit_id = mercurial.node.hex(ctx.node()) branch = ctx.branch() commits.append((commit_id, branch)) @@ -204,12 +205,12 @@ def _check_heads(repo, start, end, commi parents.add(p) for p in parents: - branch = repo[p].branch() + branch = get_ctx(repo, p).branch() # The heads descending from that parent, on the same branch parent_heads = set([p]) reachable = set([p]) for x in xrange(p + 1, end): - if repo[x].branch() != branch: + if get_ctx(repo, x).branch() != branch: continue for pp in changelog.parentrevs(x): if pp in reachable: @@ -385,7 +386,7 @@ def post_push_ssh(ui, repo, node, **kwar def key_push(ui, repo, **kwargs): if kwargs['new'] != '0' and kwargs['namespace'] == 'bookmarks': # store new bookmarks in our UI object propagated later to post_push - ui._rc_pushkey_branches = repo[kwargs['key']].bookmarks() + ui._rc_pushkey_branches = get_ctx(repo, kwargs['key']).bookmarks() return