author | Martin von Zweigbergk <martinvonz@google.com> |
Fri, 23 Mar 2018 09:08:21 -0700 | |
branch | stable |
changeset 3611 | c912eaf29eec |
parent 3575 | 97530d6e340d |
child 3694 | c0d5e0929f8b |
permissions | -rw-r--r-- |
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 |
3611
c912eaf29eec
compat: call current obsolete.createmarkers(), not one from load time
Martin von Zweigbergk <martinvonz@google.com>
parents:
3575
diff
changeset
|
34 |
originalcreatemarkers = obsolete.createmarkers |
3575
97530d6e340d
compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents:
3570
diff
changeset
|
35 |
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
|
36 |
originalcreatemarkers = originalcreatemarkers.func |
97530d6e340d
compat: make override of createmarkers work on wrapped function
Martin von Zweigbergk <martinvonz@google.com>
parents:
3570
diff
changeset
|
37 |
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
|
38 |
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
|
39 |
operation=None): |
f61a23a84dac
compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents:
3094
diff
changeset
|
40 |
return obsolete.createmarkers(repo, relations, flag, date, metadata) |
3611
c912eaf29eec
compat: call current obsolete.createmarkers(), not one from load time
Martin von Zweigbergk <martinvonz@google.com>
parents:
3575
diff
changeset
|
41 |
else: |
c912eaf29eec
compat: call current obsolete.createmarkers(), not one from load time
Martin von Zweigbergk <martinvonz@google.com>
parents:
3575
diff
changeset
|
42 |
def createmarkers(*args, **kwargs): |
c912eaf29eec
compat: call current obsolete.createmarkers(), not one from load time
Martin von Zweigbergk <martinvonz@google.com>
parents:
3575
diff
changeset
|
43 |
return obsolete.createmarkers(*args, **kwargs) |
3560
f61a23a84dac
compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents:
3094
diff
changeset
|
44 |
|
3064
7a1a4d1f0958
pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2922
diff
changeset
|
45 |
def startpager(ui, cmd): |
7a1a4d1f0958
pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2922
diff
changeset
|
46 |
"""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
|
47 |
try: |
7a1a4d1f0958
pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2922
diff
changeset
|
48 |
ui.pager(cmd) |
7a1a4d1f0958
pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2922
diff
changeset
|
49 |
except AttributeError: |
7a1a4d1f0958
pager: add a function in compats to start pager
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2922
diff
changeset
|
50 |
pass |
3094
e11e018e8338
compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3064
diff
changeset
|
51 |
|
e11e018e8338
compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3064
diff
changeset
|
52 |
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
|
53 |
# 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
|
54 |
# 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
|
55 |
# 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
|
56 |
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
|
57 |
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
|
58 |
moves=moves) |
e11e018e8338
compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3064
diff
changeset
|
59 |
else: |
e11e018e8338
compat: add an abstraction for 'scmutil.cleanupnodes'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3064
diff
changeset
|
60 |
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
|
61 |
for (o, new) in replacements.iteritems()] |
3570
2477bcdd95ff
topics: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents:
3560
diff
changeset
|
62 |
createmarkers(repo, relations, operation=operation) |