Mercurial > evolve
annotate hgext3rd/topic/topicmap.py @ 5905:93dc3cb68842 stable 10.3.1
packaging: prepare version 10.3.1
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Sun, 25 Apr 2021 14:13:51 +0800 |
parents | ee242f4a2d73 |
children | 16f6b18b9ec0 f168c0fdbde9 |
rev | line source |
---|---|
1949
79c08d17a3d7
topicmap: move the 'usetopicmap' context manager into the topicmap module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1937
diff
changeset
|
1 import contextlib |
1968
08cbfeb15a1a
compat: mercurial dropped alias for hashlib.sha1
timeless@gmail.com
parents:
1953
diff
changeset
|
2 import hashlib |
1949
79c08d17a3d7
topicmap: move the 'usetopicmap' context manager into the topicmap module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1937
diff
changeset
|
3 |
3397
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
4 from mercurial.i18n import _ |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
5 from mercurial.node import nullid |
1937
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
6 from mercurial import ( |
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
7 branchmap, |
1950
99c1a26abf3f
topicmap: move 'cgapply' wrapping into the topicmap module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1949
diff
changeset
|
8 changegroup, |
99c1a26abf3f
topicmap: move 'cgapply' wrapping into the topicmap module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1949
diff
changeset
|
9 extensions, |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
10 repoview, |
4450
9b0cde5efbc9
topicmap: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents:
4187
diff
changeset
|
11 util, |
1937
60b7de2b3dd1
topicmap: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1928
diff
changeset
|
12 ) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
13 |
4536
9837e8d378de
topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4464
diff
changeset
|
14 from . import ( |
9837e8d378de
topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4464
diff
changeset
|
15 common, |
4929
bb2b4f6c99dc
compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
16 compat, |
4536
9837e8d378de
topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4464
diff
changeset
|
17 ) |
9837e8d378de
topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4464
diff
changeset
|
18 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
19 basefilter = set([b'base', b'immutable']) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
20 def topicfilter(name): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
21 """return a "topic" version of a filter level""" |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
22 if name in basefilter: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
23 return name |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
24 elif name is None: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
25 return None |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
26 elif name.endswith(b'-topic'): |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
27 return name |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
28 else: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
29 return name + b'-topic' |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
30 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
31 def istopicfilter(filtername): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
32 if filtername is None: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
33 return False |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
34 return filtername.endswith(b'-topic') |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
35 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
36 def gettopicrepo(repo): |
4536
9837e8d378de
topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4464
diff
changeset
|
37 if not common.hastopicext(repo): |
9837e8d378de
topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4464
diff
changeset
|
38 return repo |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
39 filtername = topicfilter(repo.filtername) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
40 if filtername == repo.filtername: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
41 return repo |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
42 return repo.filtered(filtername) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
43 |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
44 def _setuptopicfilter(ui): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
45 """extend the filter related mapping with topic related one""" |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
46 funcmap = repoview.filtertable |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
47 partialmap = branchmap.subsettable |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
48 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
49 # filter level not affected by topic that we should not override |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
50 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
51 for plainname in list(funcmap): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
52 newfilter = topicfilter(plainname) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
53 if newfilter == plainname: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
54 continue |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
55 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
56 def revsfunc(repo, name=plainname): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
57 return repoview.filterrevs(repo, name) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
58 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
59 base = topicfilter(partialmap[plainname]) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
60 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
61 if newfilter not in funcmap: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
62 funcmap[newfilter] = revsfunc |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
63 partialmap[newfilter] = base |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
64 funcmap[b'unfiltered-topic'] = lambda repo: frozenset() |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
65 partialmap[b'unfiltered-topic'] = b'visible-topic' |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
66 |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
67 def _phaseshash(repo, maxrev): |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
68 """uniq ID for a phase matching a set of rev""" |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
69 revs = set() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
70 cl = repo.changelog |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
71 fr = cl.filteredrevs |
4929
bb2b4f6c99dc
compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
72 getrev = compat.getgetrev(cl) |
5426
86736040b0ec
topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents:
5193
diff
changeset
|
73 for n in compat.nonpublicphaseroots(repo): |
86736040b0ec
topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents:
5193
diff
changeset
|
74 r = getrev(n) |
86736040b0ec
topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents:
5193
diff
changeset
|
75 if r not in fr and r < maxrev: |
86736040b0ec
topic: compatibility with sparse phaseroots and phasesets in 5.5
Joerg Sonnenberger <joerg@bec.de>
parents:
5193
diff
changeset
|
76 revs.add(r) |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
77 key = nullid |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
78 revs = sorted(revs) |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
79 if revs: |
1968
08cbfeb15a1a
compat: mercurial dropped alias for hashlib.sha1
timeless@gmail.com
parents:
1953
diff
changeset
|
80 s = hashlib.sha1() |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
81 for rev in revs: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
82 s.update(b'%d;' % rev) |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
83 key = s.digest() |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
84 return key |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
85 |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
86 def modsetup(ui): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
87 """call at uisetup time to install various wrappings""" |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
88 _setuptopicfilter(ui) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
89 _wrapbmcache(ui) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
90 extensions.wrapfunction(changegroup.cg1unpacker, 'apply', cgapply) |
5665
dd9dba7c1d00
compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents:
5426
diff
changeset
|
91 compat.overridecommitstatus(commitstatus) |
1949
79c08d17a3d7
topicmap: move the 'usetopicmap' context manager into the topicmap module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1937
diff
changeset
|
92 |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
93 def cgapply(orig, self, repo, *args, **kwargs): |
1950
99c1a26abf3f
topicmap: move 'cgapply' wrapping into the topicmap module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1949
diff
changeset
|
94 """make sure a topicmap is used when applying a changegroup""" |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
95 other = repo.filtered(topicfilter(repo.filtername)) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
96 return orig(self, other, *args, **kwargs) |
1950
99c1a26abf3f
topicmap: move 'cgapply' wrapping into the topicmap module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1949
diff
changeset
|
97 |
5665
dd9dba7c1d00
compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents:
5426
diff
changeset
|
98 def commitstatus(orig, repo, node, branch, bheads=None, tip=None, opts=None): |
1953
bdc5bb223b50
commit: wrap "commitstatus" to take topic into account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1950
diff
changeset
|
99 # wrap commit status use the topic branch heads |
bdc5bb223b50
commit: wrap "commitstatus" to take topic into account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1950
diff
changeset
|
100 ctx = repo[node] |
bdc5bb223b50
commit: wrap "commitstatus" to take topic into account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1950
diff
changeset
|
101 if ctx.topic() and ctx.branch() == branch: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
102 bheads = repo.branchheads(b"%s:%s" % (branch, ctx.topic())) |
3397
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
103 |
5665
dd9dba7c1d00
compat: make topics compatible across change to cmdutil.commitstatus()
Martin von Zweigbergk <martinvonz@google.com>
parents:
5426
diff
changeset
|
104 ret = orig(repo, node, branch, bheads=bheads, tip=tip, opts=opts) |
3397
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
105 |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
106 # logic copy-pasted from cmdutil.commitstatus() |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
107 if opts is None: |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
108 opts = {} |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
109 if ctx.topic(): |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
110 return ret |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
111 parents = ctx.parents() |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
112 |
4803
88472e743c64
python3: add byte prefix for objects that look like kwargs but aren't
Raphaël Gomès <rgomes@octobus.net>
parents:
4758
diff
changeset
|
113 if (not opts.get(b'amend') and bheads and node not in bheads and not |
3397
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
114 [x for x in parents if x.node() in bheads and x.branch() == branch]): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
115 repo.ui.status(_(b"(consider using topic for lightweight branches." |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
116 b" See 'hg help topic')\n")) |
3397
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
117 |
f7129e3d5a38
topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2655
diff
changeset
|
118 return ret |
1953
bdc5bb223b50
commit: wrap "commitstatus" to take topic into account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1950
diff
changeset
|
119 |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
120 def _wrapbmcache(ui): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
121 class topiccache(_topiccache, branchmap.branchcache): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
122 pass |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
123 branchmap.branchcache = topiccache |
4459
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
124 |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
125 try: |
5193
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
4929
diff
changeset
|
126 # Mercurial 5.0 |
4459
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
127 class remotetopiccache(_topiccache, branchmap.remotebranchcache): |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
128 pass |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
129 branchmap.remotebranchcache = remotetopiccache |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
130 |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
131 def _wrapupdatebmcachemethod(orig, self, repo): |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
132 # pass in the bound method as the original |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
133 return _wrapupdatebmcache(orig.__get__(self), repo) |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
134 extensions.wrapfunction(branchmap.BranchMapCache, 'updatecache', _wrapupdatebmcachemethod) |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
135 except AttributeError: |
5193
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
4929
diff
changeset
|
136 # hg <= 4.9 (3461814417f3) |
4459
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
137 extensions.wrapfunction(branchmap, 'updatecache', _wrapupdatebmcache) |
d46360b8c0dc
topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents:
4450
diff
changeset
|
138 |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
139 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
140 def _wrapupdatebmcache(orig, repo): |
2655
417490bdf28a
topic: avoid crash when topic is loaded but not enabled for a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2653
diff
changeset
|
141 previous = getattr(repo, '_autobranchmaptopic', False) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
142 try: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
143 repo._autobranchmaptopic = False |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
144 return orig(repo) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
145 finally: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
146 repo._autobranchmaptopic = previous |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
147 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
148 # needed to prevent reference used for 'super()' call using in branchmap.py to |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
149 # no go into cycle. (yes, URG) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
150 _oldbranchmap = branchmap.branchcache |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
151 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
152 @contextlib.contextmanager |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
153 def oldbranchmap(): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
154 previous = branchmap.branchcache |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
155 try: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
156 branchmap.branchcache = _oldbranchmap |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
157 yield |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
158 finally: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
159 branchmap.branchcache = previous |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
160 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
161 class _topiccache(object): # combine me with branchmap.branchcache |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
162 |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
163 def __init__(self, *args, **kwargs): |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
164 # super() call may fail otherwise |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
165 with oldbranchmap(): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
166 super(_topiccache, self).__init__(*args, **kwargs) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
167 self.phaseshash = None |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
168 |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
169 def copy(self): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
170 """return an deep copy of the branchcache object""" |
4450
9b0cde5efbc9
topicmap: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents:
4187
diff
changeset
|
171 if util.safehasattr(self, '_entries'): |
9b0cde5efbc9
topicmap: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents:
4187
diff
changeset
|
172 _entries = self._entries |
9b0cde5efbc9
topicmap: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents:
4187
diff
changeset
|
173 else: |
5193
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
4929
diff
changeset
|
174 # hg <= 4.9 (624d6683c705+b137a6793c51) |
4450
9b0cde5efbc9
topicmap: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents:
4187
diff
changeset
|
175 _entries = self |
5873
ee242f4a2d73
topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents:
5665
diff
changeset
|
176 args = (_entries, self.tipnode, self.tiprev, self.filteredhash, |
ee242f4a2d73
topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents:
5665
diff
changeset
|
177 self._closednodes) |
ee242f4a2d73
topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents:
5665
diff
changeset
|
178 if util.safehasattr(self, '_repo'): |
ee242f4a2d73
topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents:
5665
diff
changeset
|
179 # hg <= 5.7 (6266d19556ad) |
ee242f4a2d73
topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents:
5665
diff
changeset
|
180 args = (self._repo,) + args |
ee242f4a2d73
topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents:
5665
diff
changeset
|
181 new = self.__class__(*args) |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
182 new.phaseshash = self.phaseshash |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
183 return new |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
184 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
185 def branchtip(self, branch, topic=b''): |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
186 '''Return the tipmost open head on branch head, otherwise return the |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
187 tipmost closed head on branch. |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
188 Raise KeyError for unknown branch.''' |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
189 if topic: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
190 branch = b'%s:%s' % (branch, topic) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
191 return super(_topiccache, self).branchtip(branch) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
192 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
193 def branchheads(self, branch, closed=False, topic=b''): |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
194 if topic: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
195 branch = b'%s:%s' % (branch, topic) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
196 return super(_topiccache, self).branchheads(branch, closed=closed) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
197 |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
198 def validfor(self, repo): |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
199 """Is the cache content valid regarding a repo |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
200 |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
201 - False when cached tipnode is unknown or if we detect a strip. |
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
202 - True when cache is up to date or a subset of current repo.""" |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
203 valid = super(_topiccache, self).validfor(repo) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
204 if not valid: |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
205 return False |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
206 elif not istopicfilter(repo.filtername) or self.phaseshash is None: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
207 # phasehash at None means this is a branchmap |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
208 # come from non topic thing |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
209 return True |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
210 else: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
211 try: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
212 valid = self.phaseshash == _phaseshash(repo, self.tiprev) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
213 return valid |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
214 except IndexError: |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
215 return False |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
216 |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
217 def write(self, repo): |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
218 # we expect mutable set to be small enough to be that computing it all |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
219 # the time will be fast enough |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
220 if not istopicfilter(repo.filtername): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
221 super(_topiccache, self).write(repo) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
222 |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
223 def update(self, repo, revgen): |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
224 """Given a branchhead cache, self, that may have extra nodes or be |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
225 missing heads, and a generator of nodes that are strictly a superset of |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
226 heads missing, this function updates self to be correct. |
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
227 """ |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
228 if not istopicfilter(repo.filtername): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
229 return super(_topiccache, self).update(repo, revgen) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
230 unfi = repo.unfiltered() |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
231 oldgetbranchinfo = unfi.revbranchcache().branchinfo |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
232 |
4187
49d442a2207f
topic: add the changelog argument to branchinfo()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
3397
diff
changeset
|
233 def branchinfo(r, changelog=None): |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
234 info = oldgetbranchinfo(r) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
235 topic = b'' |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
236 ctx = unfi[r] |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
237 if ctx.mutable(): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
238 topic = ctx.topic() |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
239 branch = info[0] |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
240 if topic: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4803
diff
changeset
|
241 branch = b'%s:%s' % (branch, topic) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
242 return (branch, info[1]) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
243 try: |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
244 unfi.revbranchcache().branchinfo = branchinfo |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
245 super(_topiccache, self).update(repo, revgen) |
1890
e846b8f402d0
topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1885
diff
changeset
|
246 self.phaseshash = _phaseshash(repo, self.tiprev) |
1885
d49f75eab6a3
topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
247 finally: |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2004
diff
changeset
|
248 unfi.revbranchcache().branchinfo = oldgetbranchinfo |