smartlog: use logcmdutil when hg >= 4.6
ClosedPublic

Authored by cricalix on Aug 29 2018, 3:50 AM.

Details

Reviewers
quark
Group Reviewers
Restricted Project
Commits
rFBHGX385d6eda1ba4: smartlog: use logcmdutil when hg >= 4.6
Summary

Mercurial 4.6 introduces a new module - logcmdutil - and migrates a number of methods from cmdutil over to logcmdutil. Some of these methods get renamed along the way.

Attempting to use smartlog in hg 4.6 or higher results in AttributeErrors being thrown; see https://bitbucket.org/facebook/hg-experimental/issues/14/broken-smartlog

This diff uses a conditional import (I suppose it could just try: the import too) to load logcmdutil if the major.minor is high enough, and then uses try/except handling to squelch the AttributeErrors.

Test Plan

Use setup.py to install the modified extension into two installs of mercurial - 4.7 and 4.4.2. Both versions are able to execute hg sl on the same repository.

Diff Detail

Repository
rFBHGX Facebook Mercurial Extensions
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
cricalix created this revision.Aug 29 2018, 3:50 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptAug 29 2018, 3:50 AM
cricalix edited the summary of this revision. (Show Details)Aug 29 2018, 3:54 AM
cricalix edited the test plan for this revision. (Show Details)
quark added a subscriber: quark.Aug 29 2018, 3:09 PM

Thanks for the change! A more common way to handle this is to catch ImportError to detect old versions, and try to deal with the divergence at import time:

try:
    # >= 4.6
    from mercurial import logcmdutil
    changesetprinter = logcmdutil.changesetprinter
    changesettemplater = logcmdutil.changesettemplater
    displaygraph = logcmdutil.displaygraph
    displayer = logcmdutil.changesetdisplayer
except ImportError:
    changesetprinter = cmdutil.changeset_printer
    changesettemplater = cmdutil.changeset_templater
    displaygraph = cmdutil.displaygraph
    displayer = cmdutil.show_changeset

Those names can then be used to avoid try/except below.

cricalix updated this revision to Diff 10648.Aug 29 2018, 3:25 PM

Apply feedback. Tested in 4.4.2 and 4.7 again, works nicely.

quark accepted this revision.Aug 29 2018, 6:55 PM

Pushed. Thanks!

hgext3rd/smartlog.py
61

I changed this to csdisplayer to be consistent to Mercurial naming convention (no underscores).

This revision is now accepted and ready to land.Aug 29 2018, 6:55 PM
This revision was automatically updated to reflect the committed changes.