Closed Bug 1824417 Opened 1 year ago Closed 1 year ago

firefoxtree extension triggers "AttributeError: module 'mercurial.hg' has no attribute '_peerorrepo'" on all hg operations, with Mercurial 6.4

Categories

(Developer Services :: Mercurial: firefoxtree, defect)

defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: dholbert, Assigned: sheehan)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Mercurial 6.4 was released today, March 24:
https://www.mercurial-scm.org/wiki/WhatsNew#Mercurial_6.4_.282023-03-24.29

I upgraded to it using the following command:

python3 -m pip install --user -U mercurial

(I was previously using v6.3.3, also installed via pip)

And now all of my hg commands include this error-logging:

Traceback (most recent call last):
  File "/home/dholbert/.local/lib/python3.10/site-packages/mercurial/extensions.py", line 270, in _runextsetup
    extsetup(ui)
  File "/scratch/work/builds/.mozbuild/version-control-tools/hgext/firefoxtree/__init__.py", line 705, in extsetup
    extensions.wrapfunction(hg, b"_peerorrepo", peerorrepo)
  File "/home/dholbert/.local/lib/python3.10/site-packages/mercurial/extensions.py", line 675, in wrapfunction
    origfn = getattr(container, funcname)
  File "/home/dholbert/.local/lib/python3.10/site-packages/mercurial/pycompat.py", line 358, in w
    return f(object, sysstr(name), *args)
AttributeError: module 'mercurial.hg' has no attribute '_peerorrepo'
*** failed to set up extension firefoxtree: module 'mercurial.hg' has no attribute '_peerorrepo'

That seems to originate with this line in the firefoxtree extension:

def extsetup(ui):
    extensions.wrapfunction(hg, b"_peerorrepo", peerorrepo)

https://github.com/mozilla/version-control-tools/blob/e439b2ce89556411c23f7119bae5a40f7cd8f5e7/hgext/firefoxtree/__init__.py#L705

That seems to be looking for some core mercurial thing that no-longer-exists as of version 6.4, I guess?

My workaround right now is to downgrade back to mercurial 6.3.3, like so:

python3 -m pip install --user -U mercurial==6.3.3

It looks like our peerorrepo override here dates back to this commit:
https://github.com/mozilla/version-control-tools/commit/ce5f01e938c3b88292c6632e451d61e5b026a3b5

It looks like peerorrepo is the hook that allows us to e.g. do hg pull autoland and have that Just Work.

If I remove the extensions.wrapfunction(hg, b"_peerorrepo", peerorrepo) from my firefoxtree python source, then the Mercurial 6.4 errors go away -- but also, not too surprisingly, hg pull autoland stops working. (It fails with abort: repository autoland not found.)

I can reproduce this as well. Investigating a fix now.

Assignee: nobody → sheehan
Blocks: mach-busted

Looks like this was the relevant change in the Mercurial sources, where this thing was removed:
https://www.mercurial-scm.org/repo/hg/rev/c4731eee1c8f4ce936311329b71546370ff0919e

Quoting:

peer-or-repo: remove the now unused function

We do not need it anymore.
[...]
-def _peerorrepo(
-    ui, path, create=False, presetupfuncs=None, intents=None, createopts=None
-):
-    """return a repository object for the specified path"""
-    cls = _peerlookup(path)
-    obj = cls.instance(ui, path, create, intents=intents, createopts=createopts)
-    _setup_repo_or_peer(ui, obj, presetupfuncs)
-    return obj

The commit message is a bit enigmatic; I wonder if there's just a different supported hook that we're supposed to use for this functionality now?

(In reply to Daniel Holbert [:dholbert] from comment #4)

Looks like this was the relevant change in the Mercurial sources, where this thing was removed:
https://www.mercurial-scm.org/repo/hg/rev/c4731eee1c8f4ce936311329b71546370ff0919e

Quoting:

peer-or-repo: remove the now unused function

We do not need it anymore.
[...]
-def _peerorrepo(
-    ui, path, create=False, presetupfuncs=None, intents=None, createopts=None
-):
-    """return a repository object for the specified path"""
-    cls = _peerlookup(path)
-    obj = cls.instance(ui, path, create, intents=intents, createopts=createopts)
-    _setup_repo_or_peer(ui, obj, presetupfuncs)
-    return obj

The commit message is a bit enigmatic; I wonder if there's just a different supported hook that we're supposed to use for this functionality now?

From the successor commits to this one, it looks like the "peer" and "repo" functionality were pulled out into separate functions. We need to wrap the "peer" function to map tree names to https://hg.mozilla.org URIs.

_peerorrepo is deprecated in Mercurial 6.4 and the functionality is moved to
separate functions for creating peer and repo objects. Add a wrapper around
hg.peer that accomplishes the same functionality for Mercurial 6.4+.

Also rename our local peerorrepo to wrapped_peerorrepo to match the
convention used elsewhere.

I'm also getting this error now (on macOS). I am cheering you all on and I'm happy to try out prospective fixes. I can't successfully apply D173568 locally.

I've also been bitten by this.

Just posted an updated version of the patch for review. Sorry for the delay, I had some trouble debugging this but it turned out to be mostly PEBCAK. :)

Pushed by cosheehan@mozilla.com:
https://hg.mozilla.org/hgcustom/version-control-tools/rev/97c4e1397bef
firefoxtree: wrap hg.peer to try tree shortnames since _peerorrepo is deprecated r=dholbert

Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
See Also: → 1826402

This should be fixed now, please run mach vcs-setup to update your copy of version-control-tools to the latest. If you run into any problems please re-open this bug. Cheers.

(In reply to Connor Sheehan [:sheehan] from comment #11)

This should be fixed now, please run mach vcs-setup to update your copy of version-control-tools to the latest

I just tried this and confirmed that this works on my end, BTW. Thanks for fixing this!

(Notably: I did see the _peerorrepo error logging during this ./mach vcs-setup execution, but the command still proceeds and successfully updates my clone of the version-control-tools repo, which addresses this issue from that point onward.)

Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: