hgext3rd/topic/compat.py
author Martin von Zweigbergk <martinvonz@google.com>
Mon, 12 Mar 2018 15:41:51 -0700
changeset 3570 2477bcdd95ff
parent 3560 f61a23a84dac
child 3575 97530d6e340d
permissions -rw-r--r--
topics: include "operation" metadata in obsmarkers
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
3094
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    10
from mercurial import (
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    11
    obsolete,
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    12
    scmutil,
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    13
    util,
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    14
)
2922
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    15
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    16
getmarkers = None
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    17
successorssets = None
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    18
try:
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    19
    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
    20
    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
    21
    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
    22
except ImportError:
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    23
    pass
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    24
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    25
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
    26
    getmarkers = obsolete.getmarkers
66357d4d03b2 topic: centralize compatibility logic between hg versions into compat module
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    27
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
    28
    successorssets = obsolete.successorssets
3064
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    29
3560
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    30
# 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
    31
# 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
    32
createmarkers = obsolete.createmarkers
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    33
if obsolete.createmarkers.__code__.co_argcount < 6:
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    34
    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
    35
                      operation=None):
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3094
diff changeset
    36
        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
    37
3064
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    38
def startpager(ui, cmd):
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    39
    """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
    40
    try:
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    41
        ui.pager(cmd)
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    42
    except AttributeError:
7a1a4d1f0958 pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2922
diff changeset
    43
        pass
3094
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    44
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    45
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
    46
    # 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
    47
    # 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
    48
    # 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
    49
    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
    50
        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
    51
                             moves=moves)
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    52
    else:
e11e018e8338 compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3064
diff changeset
    53
        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
    54
                     for (o, new) in replacements.iteritems()]
3570
2477bcdd95ff topics: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3560
diff changeset
    55
        createmarkers(repo, relations, operation=operation)