From 995caf75fddfa968073db97aa750882a57a7ea03 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Mon, 12 Oct 2026 17:55:55 +0900 Subject: [PATCH 1/2] Remove code for Mercurial versions older than 5.1 from redminehelper.py --- .../scm/adapters/mercurial/redminehelper.py | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/lib/redmine/scm/adapters/mercurial/redminehelper.py b/lib/redmine/scm/adapters/mercurial/redminehelper.py index e918203ba..4953fa9ff 100644 --- a/lib/redmine/scm/adapters/mercurial/redminehelper.py +++ b/lib/redmine/scm/adapters/mercurial/redminehelper.py @@ -49,10 +49,10 @@ Output example of rhmanifest:: """ import re, time, html, urllib -from mercurial import cmdutil, commands, node, error, hg, registrar +from mercurial import commands, node, error, hg, registrar cmdtable = {} -command = registrar.command(cmdtable) if hasattr(registrar, 'command') else cmdutil.command(cmdtable) +command = registrar.command(cmdtable) _x = lambda s: html.escape(s.decode('utf-8')).encode('utf-8') _u = lambda s: html.escape(urllib.parse.quote(s)).encode('utf-8') @@ -63,19 +63,11 @@ def unquoteplus(*args, **kwargs): def _changectx(repo, rev): if isinstance(rev, bytes): rev = repo.lookup(rev) - if hasattr(repo, 'changectx'): - return repo.changectx(rev) - else: - return repo[rev] + return repo[rev] def _tip(ui, repo): # see mercurial/commands.py:tip - def tiprev(): - try: - return len(repo) - 1 - except TypeError: # Mercurial < 1.1 - return repo.changelog.count() - 1 - tipctx = _changectx(repo, tiprev()) + tipctx = _changectx(repo, len(repo) - 1) ui.write(b'\n' % (tipctx.rev(), _x(node.hex(tipctx.node())))) @@ -96,18 +88,10 @@ def _tags(ui, repo): def _branches(ui, repo): # see mercurial/commands.py:branches def iterbranches(): - if getattr(repo, 'branchtags', None) is not None: - # Mercurial < 2.9 - for t, n in repo.branchtags().iteritems(): - yield t, n, repo.changelog.rev(n) - else: - for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): - yield tag, tip, repo.changelog.rev(tip) + for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): + yield tag, tip, repo.changelog.rev(tip) def branchheads(branch): - try: - return repo.branchheads(branch, closed=False) - except TypeError: # Mercurial < 1.2 - return repo.branchheads(branch) + return repo.branchheads(branch, closed=False) def lookup(rev, n): try: return repo.lookup(str(rev).encode('utf-8')) -- 2.55.0