hgext3rd/topic/compat.py
author Martin von Zweigbergk <martinvonz@google.com>
Mon, 19 Mar 2018 15:46:17 -0700
changeset 3575 97530d6e340d
parent 3570 2477bcdd95ff
child 3611 c912eaf29eec
permissions -rw-r--r--
compat: make override of createmarkers work on wrapped function If createmarkers() has been wrapped using functools.partial(), the __code__ attribute won't exist. Fix by unwrapping partial functions. I tried to find another attribute to use as proxy for the "__code__.co_argcount < 6", but there were no new functions or similar added in that commit.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2922
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     1
# Copyright 2017 FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     2
#
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     3
# This software may be used and distributed according to the terms of the
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     4
# GNU General Public License version 2 or any later version.
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     5
"""
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     6
Compatibility module
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     7
"""
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     8
from __future__ import absolute_import
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     9
3575
97530d6e340d compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents: 3570
diff changeset
    10
import functools
97530d6e340d compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents: 3570
diff changeset
    11
3094
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    12
from mercurial import (
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    13
    obsolete,
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    14
    scmutil,
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    15
    util,
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    16
)
2922
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    17
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    18
getmarkers = None
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    19
successorssets = None
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    20
try:
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    21
    from mercurial import obsutil
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    22
    getmarkers = getattr(obsutil, 'getmarkers', None)
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    23
    successorssets = getattr(obsutil, 'successorssets', None)
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    24
except ImportError:
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    25
    pass
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    26
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    27
if getmarkers is None:
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    28
    getmarkers = obsolete.getmarkers
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    29
if successorssets is None:
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    30
    successorssets = obsolete.successorssets
3064
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    31
3560
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    32
# Wrap obsolete.creatmarkers and make it accept but ignore "operation" argument
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    33
# for hg < 4.3
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    34
createmarkers = obsolete.createmarkers
3575
97530d6e340d compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents: 3570
diff changeset
    35
originalcreatemarkers = createmarkers
97530d6e340d compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents: 3570
diff changeset
    36
while isinstance(originalcreatemarkers, functools.partial):
97530d6e340d compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents: 3570
diff changeset
    37
    originalcreatemarkers = originalcreatemarkers.func
97530d6e340d compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents: 3570
diff changeset
    38
if originalcreatemarkers.__code__.co_argcount < 6:
3560
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    39
    def createmarkers(repo, relations, flag=0, date=None, metadata=None,
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    40
                      operation=None):
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    41
        return obsolete.createmarkers(repo, relations, flag, date, metadata)
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    42
3064
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    43
def startpager(ui, cmd):
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    44
    """function to start a pager in case ui.pager() exists"""
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    45
    try:
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    46
        ui.pager(cmd)
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    47
    except AttributeError:
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    48
        pass
3094
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    49
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    50
def cleanupnodes(repo, replacements, operation, moves=None):
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    51
    # create obsmarkers and move bookmarks
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    52
    # XXX we should be creating marker as we go instead of only at the end,
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    53
    # this makes the operations more modulars
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    54
    if util.safehasattr(scmutil, 'cleanupnodes'):
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    55
        scmutil.cleanupnodes(repo, replacements, 'changetopics',
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    56
                             moves=moves)
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    57
    else:
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    58
        relations = [(repo[o], tuple(repo[n] for n in new))
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    59
                     for (o, new) in replacements.iteritems()]
3570
2477bcdd95ff topics: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3560
diff changeset
    60
        createmarkers(repo, relations, operation=operation)