##// END OF EJS Templates
py3: fixed few mercurial cases
super-admin -
r1050:bf6aa61b python3
parent child Browse files
Show More
@@ -24,6 +24,8 b' from mercurial import demandimport'
24
24
25 # patch demandimport, due to bug in mercurial when it always triggers
25 # patch demandimport, due to bug in mercurial when it always triggers
26 # demandimport.enable()
26 # demandimport.enable()
27 from vcsserver.utils import safe_bytes
28
27 demandimport.enable = lambda *args, **kwargs: 1
29 demandimport.enable = lambda *args, **kwargs: 1
28
30
29 from mercurial import ui
31 from mercurial import ui
@@ -70,6 +72,7 b' from mercurial import strip as hgext_str'
70
72
71
73
72 def get_ctx(repo, ref):
74 def get_ctx(repo, ref):
75 ref = safe_bytes(ref)
73 try:
76 try:
74 ctx = repo[ref]
77 ctx = repo[ref]
75 except (ProgrammingError, TypeError):
78 except (ProgrammingError, TypeError):
@@ -39,7 +39,7 b' from vcsserver.hgcompat import ('
39 patch, peer, revrange, ui, hg_tag, Abort, LookupError, RepoError,
39 patch, peer, revrange, ui, hg_tag, Abort, LookupError, RepoError,
40 RepoLookupError, InterventionRequired, RequirementError,
40 RepoLookupError, InterventionRequired, RequirementError,
41 alwaysmatcher, patternmatcher, hgutil, hgext_strip)
41 alwaysmatcher, patternmatcher, hgutil, hgext_strip)
42 from vcsserver.utils import ascii_bytes, ascii_str, safe_str
42 from vcsserver.utils import ascii_bytes, ascii_str, safe_str, safe_bytes
43 from vcsserver.vcs_base import RemoteBase
43 from vcsserver.vcs_base import RemoteBase
44
44
45 log = logging.getLogger(__name__)
45 log = logging.getLogger(__name__)
@@ -479,7 +479,7 b' class HgRemote(RemoteBase):'
479 repo = self._factory.repo(wire)
479 repo = self._factory.repo(wire)
480
480
481 ctx = self._get_ctx(repo, revision)
481 ctx = self._get_ctx(repo, revision)
482 fctx = ctx.filectx(path)
482 fctx = ctx.filectx(safe_bytes(path))
483
483
484 def history_iter():
484 def history_iter():
485 limit_rev = fctx.rev()
485 limit_rev = fctx.rev()
@@ -510,7 +510,7 b' class HgRemote(RemoteBase):'
510 def _node_history_until(_context_uid, _repo_id):
510 def _node_history_until(_context_uid, _repo_id):
511 repo = self._factory.repo(wire)
511 repo = self._factory.repo(wire)
512 ctx = self._get_ctx(repo, revision)
512 ctx = self._get_ctx(repo, revision)
513 fctx = ctx.filectx(path)
513 fctx = ctx.filectx(safe_bytes(path))
514
514
515 file_log = list(fctx.filelog())
515 file_log = list(fctx.filelog())
516 if limit:
516 if limit:
@@ -524,7 +524,7 b' class HgRemote(RemoteBase):'
524 def fctx_annotate(self, wire, revision, path):
524 def fctx_annotate(self, wire, revision, path):
525 repo = self._factory.repo(wire)
525 repo = self._factory.repo(wire)
526 ctx = self._get_ctx(repo, revision)
526 ctx = self._get_ctx(repo, revision)
527 fctx = ctx.filectx(path)
527 fctx = ctx.filectx(safe_bytes(path))
528
528
529 result = []
529 result = []
530 for i, annotate_obj in enumerate(fctx.annotate(), 1):
530 for i, annotate_obj in enumerate(fctx.annotate(), 1):
@@ -538,18 +538,19 b' class HgRemote(RemoteBase):'
538 def fctx_node_data(self, wire, revision, path):
538 def fctx_node_data(self, wire, revision, path):
539 repo = self._factory.repo(wire)
539 repo = self._factory.repo(wire)
540 ctx = self._get_ctx(repo, revision)
540 ctx = self._get_ctx(repo, revision)
541 fctx = ctx.filectx(path)
541 fctx = ctx.filectx(safe_bytes(path))
542 return fctx.data_queue()
542 return fctx.data()
543
543
544 @reraise_safe_exceptions
544 @reraise_safe_exceptions
545 def fctx_flags(self, wire, commit_id, path):
545 def fctx_flags(self, wire, commit_id, path):
546 cache_on, context_uid, repo_id = self._cache_on(wire)
546 cache_on, context_uid, repo_id = self._cache_on(wire)
547 region = self._region(wire)
547 region = self._region(wire)
548
548 @region.conditional_cache_on_arguments(condition=cache_on)
549 @region.conditional_cache_on_arguments(condition=cache_on)
549 def _fctx_flags(_repo_id, _commit_id, _path):
550 def _fctx_flags(_repo_id, _commit_id, _path):
550 repo = self._factory.repo(wire)
551 repo = self._factory.repo(wire)
551 ctx = self._get_ctx(repo, commit_id)
552 ctx = self._get_ctx(repo, commit_id)
552 fctx = ctx.filectx(path)
553 fctx = ctx.filectx(safe_bytes(path))
553 return fctx.flags()
554 return fctx.flags()
554
555
555 return _fctx_flags(repo_id, commit_id, path)
556 return _fctx_flags(repo_id, commit_id, path)
@@ -558,11 +559,12 b' class HgRemote(RemoteBase):'
558 def fctx_size(self, wire, commit_id, path):
559 def fctx_size(self, wire, commit_id, path):
559 cache_on, context_uid, repo_id = self._cache_on(wire)
560 cache_on, context_uid, repo_id = self._cache_on(wire)
560 region = self._region(wire)
561 region = self._region(wire)
562
561 @region.conditional_cache_on_arguments(condition=cache_on)
563 @region.conditional_cache_on_arguments(condition=cache_on)
562 def _fctx_size(_repo_id, _revision, _path):
564 def _fctx_size(_repo_id, _revision, _path):
563 repo = self._factory.repo(wire)
565 repo = self._factory.repo(wire)
564 ctx = self._get_ctx(repo, commit_id)
566 ctx = self._get_ctx(repo, commit_id)
565 fctx = ctx.filectx(path)
567 fctx = ctx.filectx(safe_bytes(path))
566 return fctx.size()
568 return fctx.size()
567 return _fctx_size(repo_id, commit_id, path)
569 return _fctx_size(repo_id, commit_id, path)
568
570
@@ -574,7 +576,6 b' class HgRemote(RemoteBase):'
574 @region.conditional_cache_on_arguments(condition=cache_on)
576 @region.conditional_cache_on_arguments(condition=cache_on)
575 def _get_all_commit_ids(_context_uid, _repo_id, _name):
577 def _get_all_commit_ids(_context_uid, _repo_id, _name):
576 repo = self._factory.repo(wire)
578 repo = self._factory.repo(wire)
577 repo = repo.filtered(name)
578 revs = [ascii_str(repo[x].hex()) for x in repo.filtered(b'visible').changelog.revs()]
579 revs = [ascii_str(repo[x].hex()) for x in repo.filtered(b'visible').changelog.revs()]
579 return revs
580 return revs
580 return _get_all_commit_ids(context_uid, repo_id, name)
581 return _get_all_commit_ids(context_uid, repo_id, name)
@@ -591,7 +592,7 b' class HgRemote(RemoteBase):'
591
592
592 @region.conditional_cache_on_arguments(condition=cache_on)
593 @region.conditional_cache_on_arguments(condition=cache_on)
593 def _is_large_file(_context_uid, _repo_id, _commit_id, _path):
594 def _is_large_file(_context_uid, _repo_id, _commit_id, _path):
594 return largefiles.lfutil.isstandin(path)
595 return largefiles.lfutil.isstandin(safe_bytes(path))
595
596
596 return _is_large_file(context_uid, repo_id, commit_id, path)
597 return _is_large_file(context_uid, repo_id, commit_id, path)
597
598
@@ -604,7 +605,7 b' class HgRemote(RemoteBase):'
604 def _is_binary(_repo_id, _sha, _path):
605 def _is_binary(_repo_id, _sha, _path):
605 repo = self._factory.repo(wire)
606 repo = self._factory.repo(wire)
606 ctx = self._get_ctx(repo, revision)
607 ctx = self._get_ctx(repo, revision)
607 fctx = ctx.filectx(path)
608 fctx = ctx.filectx(safe_bytes(path))
608 return fctx.isbinary()
609 return fctx.isbinary()
609
610
610 return _is_binary(repo_id, revision, path)
611 return _is_binary(repo_id, revision, path)
@@ -637,8 +638,8 b' class HgRemote(RemoteBase):'
637 @reraise_safe_exceptions
638 @reraise_safe_exceptions
638 def lookup(self, wire, revision, both):
639 def lookup(self, wire, revision, both):
639 cache_on, context_uid, repo_id = self._cache_on(wire)
640 cache_on, context_uid, repo_id = self._cache_on(wire)
641 region = self._region(wire)
640
642
641 region = self._region(wire)
642 @region.conditional_cache_on_arguments(condition=cache_on)
643 @region.conditional_cache_on_arguments(condition=cache_on)
643 def _lookup(_context_uid, _repo_id, _revision, _both):
644 def _lookup(_context_uid, _repo_id, _revision, _both):
644
645
@@ -696,12 +697,15 b' class HgRemote(RemoteBase):'
696 @reraise_safe_exceptions
697 @reraise_safe_exceptions
697 def rev_range(self, wire, commit_filter):
698 def rev_range(self, wire, commit_filter):
698 cache_on, context_uid, repo_id = self._cache_on(wire)
699 cache_on, context_uid, repo_id = self._cache_on(wire)
700 region = self._region(wire)
699
701
700 region = self._region(wire)
701 @region.conditional_cache_on_arguments(condition=cache_on)
702 @region.conditional_cache_on_arguments(condition=cache_on)
702 def _rev_range(_context_uid, _repo_id, _filter):
703 def _rev_range(_context_uid, _repo_id, _filter):
703 repo = self._factory.repo(wire)
704 repo = self._factory.repo(wire)
704 revisions = [rev for rev in revrange(repo, commit_filter)]
705 revisions = [
706 ascii_str(repo[rev].hex())
707 for rev in revrange(repo, list(map(ascii_bytes, commit_filter)))
708 ]
705 return revisions
709 return revisions
706
710
707 return _rev_range(context_uid, repo_id, sorted(commit_filter))
711 return _rev_range(context_uid, repo_id, sorted(commit_filter))
@@ -720,7 +724,7 b' class HgRemote(RemoteBase):'
720 return len(repo) - 1, 0
724 return len(repo) - 1, 0
721
725
722 stop, start = get_revs(repo, [node + ':'])
726 stop, start = get_revs(repo, [node + ':'])
723 revs = [hex(repo[r].node()) for r in range(start, stop + 1)]
727 revs = [ascii_str(repo[r].hex()) for r in range(start, stop + 1)]
724 return revs
728 return revs
725
729
726 @reraise_safe_exceptions
730 @reraise_safe_exceptions
@@ -774,6 +778,7 b' class HgRemote(RemoteBase):'
774 def tags(self, wire):
778 def tags(self, wire):
775 cache_on, context_uid, repo_id = self._cache_on(wire)
779 cache_on, context_uid, repo_id = self._cache_on(wire)
776 region = self._region(wire)
780 region = self._region(wire)
781
777 @region.conditional_cache_on_arguments(condition=cache_on)
782 @region.conditional_cache_on_arguments(condition=cache_on)
778 def _tags(_context_uid, _repo_id):
783 def _tags(_context_uid, _repo_id):
779 repo = self._factory.repo(wire)
784 repo = self._factory.repo(wire)
@@ -1050,7 +1055,7 b' class HgRemote(RemoteBase):'
1050 mode = b'x' in flags and 0o755 or 0o644
1055 mode = b'x' in flags and 0o755 or 0o644
1051 is_link = b'l' in flags
1056 is_link = b'l' in flags
1052
1057
1053 yield ArchiveNode(file_path, mode, is_link, ctx[fn].data_queue)
1058 yield ArchiveNode(file_path, mode, is_link, ctx[fn].data)
1054
1059
1055 return archive_repo(file_walker, archive_dest_path, kind, mtime, archive_at_path,
1060 return archive_repo(file_walker, archive_dest_path, kind, mtime, archive_at_path,
1056 archive_dir_name, commit_id)
1061 archive_dir_name, commit_id)
General Comments 0
You need to be logged in to leave comments. Login now