Skip to content

Commit c147814

Browse files
committed
Fix Mercurial 7.2 API compatibility for cmdutil.findpossible
The cmdutil.findpossible function was removed in Mercurial 7.2. Instead of introspecting the command table to get diff defaults, use mdiff.diffopts.defaults directly which is more stable.
1 parent d3bad8e commit c147814

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

lib/tool_shed/webapp/controllers/repository.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from datetime import date
77

88
from mercurial import (
9-
cmdutil,
10-
commands,
119
mdiff,
1210
patch,
1311
)
@@ -75,14 +73,14 @@
7573

7674

7775
def get_mercurial_default_options_dict(command):
78-
"""Borrowed from repoman - get default parameters for a mercurial command."""
79-
possible = cmdutil.findpossible(command, commands.table)
80-
# Mercurial >= 3.4 returns a tuple whose first element is the old return dict
81-
if type(possible) is tuple:
82-
possible = possible[0]
83-
if len(possible) != 1:
84-
raise Exception(f'unable to find mercurial command "{command}"')
85-
return {r[1].replace(b"-", b"_"): r[2] for r in next(iter(possible.values()))[1][1]}
76+
"""Get default parameters for a mercurial command."""
77+
# Use mdiff.diffopts defaults directly instead of introspecting command table
78+
# (the old cmdutil.findpossible API was removed in Mercurial 7.2)
79+
if command == b"diff":
80+
# Convert byte keys to strings but preserve value types (int, bool)
81+
# as mdiff.diffopts expects properly typed values
82+
return {(k.decode("utf-8") if isinstance(k, bytes) else k): v for k, v in mdiff.diffopts.defaults.items()}
83+
raise Exception(f'unable to find mercurial command "{command}"')
8684

8785

8886
class RepositoryController(BaseUIController, ratings_util.ItemRatings):
@@ -2366,10 +2364,8 @@ def view_changeset(self, trans, id, ctx_str, **kwd):
23662364
else:
23672365
ctx_child = None
23682366
diffs = []
2367+
# Get default diff options with string keys and properly typed values
23692368
options_dict = get_mercurial_default_options_dict(b"diff")
2370-
# Not quite sure if the following settings make any difference, but with a combination of them and the size check on each
2371-
# diff, we don't run out of memory when viewing the changelog of the cisortho2 repository on the test tool shed.
2372-
options_dict = {util.unicodify(k): util.unicodify(v) for k, v in options_dict.items()}
23732369
options_dict["maxfile"] = basic_util.MAXDIFFSIZE
23742370
options_dict["maxtotal"] = basic_util.MAXDIFFSIZE
23752371
diffopts = mdiff.diffopts(**options_dict)

0 commit comments

Comments
 (0)