# HG changeset patch # User RhodeCode Admin # Date 2023-03-03 20:14:41 # Node ID bf6aa61b61d2996aac210e19234f13b3f9b7befa # Parent 7b409ede251bd02ff88898aef46e61547ea07d05 py3: fixed few mercurial cases diff --git a/vcsserver/hgcompat.py b/vcsserver/hgcompat.py --- a/vcsserver/hgcompat.py +++ b/vcsserver/hgcompat.py @@ -24,6 +24,8 @@ from mercurial import demandimport # patch demandimport, due to bug in mercurial when it always triggers # demandimport.enable() +from vcsserver.utils import safe_bytes + demandimport.enable = lambda *args, **kwargs: 1 from mercurial import ui @@ -70,6 +72,7 @@ from mercurial import strip as hgext_str def get_ctx(repo, ref): + ref = safe_bytes(ref) try: ctx = repo[ref] except (ProgrammingError, TypeError): diff --git a/vcsserver/remote/hg.py b/vcsserver/remote/hg.py --- a/vcsserver/remote/hg.py +++ b/vcsserver/remote/hg.py @@ -39,7 +39,7 @@ from vcsserver.hgcompat import ( patch, peer, revrange, ui, hg_tag, Abort, LookupError, RepoError, RepoLookupError, InterventionRequired, RequirementError, alwaysmatcher, patternmatcher, hgutil, hgext_strip) -from vcsserver.utils import ascii_bytes, ascii_str, safe_str +from vcsserver.utils import ascii_bytes, ascii_str, safe_str, safe_bytes from vcsserver.vcs_base import RemoteBase log = logging.getLogger(__name__) @@ -479,7 +479,7 @@ class HgRemote(RemoteBase): repo = self._factory.repo(wire) ctx = self._get_ctx(repo, revision) - fctx = ctx.filectx(path) + fctx = ctx.filectx(safe_bytes(path)) def history_iter(): limit_rev = fctx.rev() @@ -510,7 +510,7 @@ class HgRemote(RemoteBase): def _node_history_until(_context_uid, _repo_id): repo = self._factory.repo(wire) ctx = self._get_ctx(repo, revision) - fctx = ctx.filectx(path) + fctx = ctx.filectx(safe_bytes(path)) file_log = list(fctx.filelog()) if limit: @@ -524,7 +524,7 @@ class HgRemote(RemoteBase): def fctx_annotate(self, wire, revision, path): repo = self._factory.repo(wire) ctx = self._get_ctx(repo, revision) - fctx = ctx.filectx(path) + fctx = ctx.filectx(safe_bytes(path)) result = [] for i, annotate_obj in enumerate(fctx.annotate(), 1): @@ -538,18 +538,19 @@ class HgRemote(RemoteBase): def fctx_node_data(self, wire, revision, path): repo = self._factory.repo(wire) ctx = self._get_ctx(repo, revision) - fctx = ctx.filectx(path) - return fctx.data_queue() + fctx = ctx.filectx(safe_bytes(path)) + return fctx.data() @reraise_safe_exceptions def fctx_flags(self, wire, commit_id, path): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _fctx_flags(_repo_id, _commit_id, _path): repo = self._factory.repo(wire) ctx = self._get_ctx(repo, commit_id) - fctx = ctx.filectx(path) + fctx = ctx.filectx(safe_bytes(path)) return fctx.flags() return _fctx_flags(repo_id, commit_id, path) @@ -558,11 +559,12 @@ class HgRemote(RemoteBase): def fctx_size(self, wire, commit_id, path): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _fctx_size(_repo_id, _revision, _path): repo = self._factory.repo(wire) ctx = self._get_ctx(repo, commit_id) - fctx = ctx.filectx(path) + fctx = ctx.filectx(safe_bytes(path)) return fctx.size() return _fctx_size(repo_id, commit_id, path) @@ -574,7 +576,6 @@ class HgRemote(RemoteBase): @region.conditional_cache_on_arguments(condition=cache_on) def _get_all_commit_ids(_context_uid, _repo_id, _name): repo = self._factory.repo(wire) - repo = repo.filtered(name) revs = [ascii_str(repo[x].hex()) for x in repo.filtered(b'visible').changelog.revs()] return revs return _get_all_commit_ids(context_uid, repo_id, name) @@ -591,7 +592,7 @@ class HgRemote(RemoteBase): @region.conditional_cache_on_arguments(condition=cache_on) def _is_large_file(_context_uid, _repo_id, _commit_id, _path): - return largefiles.lfutil.isstandin(path) + return largefiles.lfutil.isstandin(safe_bytes(path)) return _is_large_file(context_uid, repo_id, commit_id, path) @@ -604,7 +605,7 @@ class HgRemote(RemoteBase): def _is_binary(_repo_id, _sha, _path): repo = self._factory.repo(wire) ctx = self._get_ctx(repo, revision) - fctx = ctx.filectx(path) + fctx = ctx.filectx(safe_bytes(path)) return fctx.isbinary() return _is_binary(repo_id, revision, path) @@ -637,8 +638,8 @@ class HgRemote(RemoteBase): @reraise_safe_exceptions def lookup(self, wire, revision, both): cache_on, context_uid, repo_id = self._cache_on(wire) + region = self._region(wire) - region = self._region(wire) @region.conditional_cache_on_arguments(condition=cache_on) def _lookup(_context_uid, _repo_id, _revision, _both): @@ -696,12 +697,15 @@ class HgRemote(RemoteBase): @reraise_safe_exceptions def rev_range(self, wire, commit_filter): cache_on, context_uid, repo_id = self._cache_on(wire) + region = self._region(wire) - region = self._region(wire) @region.conditional_cache_on_arguments(condition=cache_on) def _rev_range(_context_uid, _repo_id, _filter): repo = self._factory.repo(wire) - revisions = [rev for rev in revrange(repo, commit_filter)] + revisions = [ + ascii_str(repo[rev].hex()) + for rev in revrange(repo, list(map(ascii_bytes, commit_filter))) + ] return revisions return _rev_range(context_uid, repo_id, sorted(commit_filter)) @@ -720,7 +724,7 @@ class HgRemote(RemoteBase): return len(repo) - 1, 0 stop, start = get_revs(repo, [node + ':']) - revs = [hex(repo[r].node()) for r in range(start, stop + 1)] + revs = [ascii_str(repo[r].hex()) for r in range(start, stop + 1)] return revs @reraise_safe_exceptions @@ -774,6 +778,7 @@ class HgRemote(RemoteBase): def tags(self, wire): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _tags(_context_uid, _repo_id): repo = self._factory.repo(wire) @@ -1050,7 +1055,7 @@ class HgRemote(RemoteBase): mode = b'x' in flags and 0o755 or 0o644 is_link = b'l' in flags - yield ArchiveNode(file_path, mode, is_link, ctx[fn].data_queue) + yield ArchiveNode(file_path, mode, is_link, ctx[fn].data) return archive_repo(file_walker, archive_dest_path, kind, mtime, archive_at_path, archive_dir_name, commit_id)