annotate hgext3rd/topic/topicmap.py @ 6910:038df334d51a mercurial-6.0

test-compat: merge mercurial-6.1 into mercurial-6.0
author Anton Shestakov <av6@dwimlabs.net>
date Fri, 25 Oct 2024 15:50:15 +0400
parents 1b59ddda3242
children ed00ed185249
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6794
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
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,
6376
5c8196a550b6 topic: make hg stack work for branches with double slashes in them
Anton Shestakov <av6@dwimlabs.net>
parents: 6369
diff changeset
17 discovery,
4536
9837e8d378de topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4464
diff changeset
18 )
9837e8d378de topic: only wrap gettopicrepo for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4464
diff changeset
19
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4803
diff changeset
20 basefilter = set([b'base', b'immutable'])
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
21 def topicfilter(name):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
22 """return a "topic" version of a filter level"""
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
23 if name in basefilter:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
24 return name
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
25 elif name is None:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
26 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
27 elif name.endswith(b'-topic'):
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
28 return name
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
29 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
30 return name + b'-topic'
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
31
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
32 def istopicfilter(filtername):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
33 if filtername is None:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
34 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
35 return filtername.endswith(b'-topic')
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
36
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
37 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
38 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
39 return repo
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
40 filtername = topicfilter(repo.filtername)
6790
38a845d432e9 topic: make sure filtername is not None
Anton Shestakov <av6@dwimlabs.net>
parents: 6789
diff changeset
41 if filtername is None or filtername == repo.filtername:
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
42 return repo
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
43 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
44
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
45 def _setuptopicfilter(ui):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
46 """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
47 funcmap = repoview.filtertable
6387
a87abe69a2f8 topic: branchmap already imports subsettable from repoviewutil
Anton Shestakov <av6@dwimlabs.net>
parents: 6363
diff changeset
48 # hg <= 4.9 (caebe5e7f4bd)
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
49 partialmap = branchmap.subsettable
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:
6790
38a845d432e9 topic: make sure filtername is not None
Anton Shestakov <av6@dwimlabs.net>
parents: 6789
diff changeset
54 # filter level not affected by topic that we should not override
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
55 continue
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
56
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
57 def revsfunc(repo, name=plainname):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
58 return repoview.filterrevs(repo, name)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
59
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
60 base = topicfilter(partialmap[plainname])
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
61
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
62 if newfilter not in funcmap:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
63 funcmap[newfilter] = revsfunc
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
64 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
65 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
66 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
67
1890
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
68 def _phaseshash(repo, maxrev):
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
69 """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
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
6704
3635782b0290 topic: compatibility for phase roots being revnums
Anton Shestakov <av6@dwimlabs.net>
parents: 6547
diff changeset
72 nppr = compat.nonpublicphaseroots(repo)
3635782b0290 topic: compatibility for phase roots being revnums
Anton Shestakov <av6@dwimlabs.net>
parents: 6547
diff changeset
73 # starting with hg 6.7rc0 phase roots are already revs instead of nodes
3635782b0290 topic: compatibility for phase roots being revnums
Anton Shestakov <av6@dwimlabs.net>
parents: 6547
diff changeset
74 # hg <= 6.6 (68289ed170c7)
3635782b0290 topic: compatibility for phase roots being revnums
Anton Shestakov <av6@dwimlabs.net>
parents: 6547
diff changeset
75 if not util.safehasattr(repo._phasecache, '_phaseroots'):
3635782b0290 topic: compatibility for phase roots being revnums
Anton Shestakov <av6@dwimlabs.net>
parents: 6547
diff changeset
76 getrev = compat.getgetrev(cl)
3635782b0290 topic: compatibility for phase roots being revnums
Anton Shestakov <av6@dwimlabs.net>
parents: 6547
diff changeset
77 nppr = set(getrev(n) for n in nppr)
3635782b0290 topic: compatibility for phase roots being revnums
Anton Shestakov <av6@dwimlabs.net>
parents: 6547
diff changeset
78 revs = sorted(set(r for r in nppr if r not in fr and r < maxrev))
1890
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
79 key = nullid
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
80 if revs:
1968
08cbfeb15a1a compat: mercurial dropped alias for hashlib.sha1
timeless@gmail.com
parents: 1953
diff changeset
81 s = hashlib.sha1()
1890
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
82 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
83 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
84 key = s.digest()
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
85 return key
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
86
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
87 def modsetup(ui):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
88 """call at uisetup time to install various wrappings"""
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
89 _setuptopicfilter(ui)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
90 _wrapbmcache(ui)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
91 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
92 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
93
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
94 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
95 """make sure a topicmap is used when applying a changegroup"""
6790
38a845d432e9 topic: make sure filtername is not None
Anton Shestakov <av6@dwimlabs.net>
parents: 6789
diff changeset
96 newfilter = topicfilter(repo.filtername)
38a845d432e9 topic: make sure filtername is not None
Anton Shestakov <av6@dwimlabs.net>
parents: 6789
diff changeset
97 if newfilter is None:
38a845d432e9 topic: make sure filtername is not None
Anton Shestakov <av6@dwimlabs.net>
parents: 6789
diff changeset
98 other = repo
38a845d432e9 topic: make sure filtername is not None
Anton Shestakov <av6@dwimlabs.net>
parents: 6789
diff changeset
99 else:
38a845d432e9 topic: make sure filtername is not None
Anton Shestakov <av6@dwimlabs.net>
parents: 6789
diff changeset
100 other = repo.filtered(newfilter)
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
101 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
102
6547
d13cfd9eb6c0 topic: compatibility for commitstatus(..., **opts)
Anton Shestakov <av6@dwimlabs.net>
parents: 6388
diff changeset
103 def commitstatus(orig, repo, node, branch, bheads=None, tip=None, **opts):
1953
bdc5bb223b50 commit: wrap "commitstatus" to take topic into account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1950
diff changeset
104 # 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
105 ctx = repo[node]
6376
5c8196a550b6 topic: make hg stack work for branches with double slashes in them
Anton Shestakov <av6@dwimlabs.net>
parents: 6369
diff changeset
106 ctxbranch = common.formatfqbn(branch=ctx.branch())
5c8196a550b6 topic: make hg stack work for branches with double slashes in them
Anton Shestakov <av6@dwimlabs.net>
parents: 6369
diff changeset
107 if ctx.topic() and ctxbranch == 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
108 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
109
6376
5c8196a550b6 topic: make hg stack work for branches with double slashes in them
Anton Shestakov <av6@dwimlabs.net>
parents: 6369
diff changeset
110 with discovery.override_context_branch(repo) as repo:
6547
d13cfd9eb6c0 topic: compatibility for commitstatus(..., **opts)
Anton Shestakov <av6@dwimlabs.net>
parents: 6388
diff changeset
111 ret = orig(repo, node, branch, bheads=bheads, tip=tip, **opts)
3397
f7129e3d5a38 topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2655
diff changeset
112
f7129e3d5a38 topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2655
diff changeset
113 # 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
114 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
115 return ret
f7129e3d5a38 topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2655
diff changeset
116 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
117
6547
d13cfd9eb6c0 topic: compatibility for commitstatus(..., **opts)
Anton Shestakov <av6@dwimlabs.net>
parents: 6388
diff changeset
118 if (not opts.get('amend') and bheads and node not in bheads and not any(
6376
5c8196a550b6 topic: make hg stack work for branches with double slashes in them
Anton Shestakov <av6@dwimlabs.net>
parents: 6369
diff changeset
119 p.node() in bheads and common.formatfqbn(branch=p.branch()) == branch
5c8196a550b6 topic: make hg stack work for branches with double slashes in them
Anton Shestakov <av6@dwimlabs.net>
parents: 6369
diff changeset
120 for p in parents
6363
f168c0fdbde9 topic: copy parent branch check in commitstatus() from core
Anton Shestakov <av6@dwimlabs.net>
parents: 5847
diff changeset
121 )):
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4803
diff changeset
122 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
123 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
124
f7129e3d5a38 topic: suggest using topic when user creates a new head on branch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2655
diff changeset
125 return ret
1953
bdc5bb223b50 commit: wrap "commitstatus" to take topic into account
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1950
diff changeset
126
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
127 def _wrapbmcache(ui):
6789
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
128 if util.safehasattr(branchmap, 'BranchCacheV2'):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
129 class TopicCache(_TopicCacheV2, branchmap.BranchCacheV2):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
130 pass
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
131 branchmap.BranchCacheV2 = TopicCache
4459
d46360b8c0dc topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4450
diff changeset
132
6789
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
133 class remotetopiccache(_TopicCacheV2, branchmap.remotebranchcache):
4459
d46360b8c0dc topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4450
diff changeset
134 pass
d46360b8c0dc topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4450
diff changeset
135 branchmap.remotebranchcache = remotetopiccache
6789
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
136 else:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
137 # hg <= 6.7 (ec640dc9cebd)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
138 class topiccache(_topiccache, branchmap.branchcache):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
139 pass
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
140 branchmap.branchcache = topiccache
4459
d46360b8c0dc topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4450
diff changeset
141
6789
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
142 try:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
143 # Mercurial 5.0
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
144 class remotetopiccache(_topiccache, branchmap.remotebranchcache):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
145 pass
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
146 branchmap.remotebranchcache = remotetopiccache
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
147
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
148 def _wrapupdatebmcachemethod(orig, self, repo):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
149 # pass in the bound method as the original
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
150 return _wrapupdatebmcache(orig.__get__(self), repo)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
151 extensions.wrapfunction(branchmap.BranchMapCache, 'updatecache', _wrapupdatebmcachemethod)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
152 except AttributeError:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
153 # hg <= 4.9 (3461814417f3)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
154 extensions.wrapfunction(branchmap, 'updatecache', _wrapupdatebmcache)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
155 # branchcache in hg <= 4.9 doesn't have load method, instead there's a
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
156 # module-level function to read on-disk cache and return a branchcache
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
157 extensions.wrapfunction(branchmap, 'read', _wrapbmread)
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
158
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
159 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
160 previous = getattr(repo, '_autobranchmaptopic', False)
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
161 try:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
162 repo._autobranchmaptopic = False
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
163 return orig(repo)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
164 finally:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
165 repo._autobranchmaptopic = previous
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
166
6794
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
167 if util.safehasattr(branchmap, 'branchcache') and dict in branchmap.branchcache.__mro__:
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
168 # hg <= 4.9 (624d6683c705)
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
169 # let's break infinite recursion in __init__() that uses super()
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
170 orig = branchmap.branchcache
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
171
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
172 @contextlib.contextmanager
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
173 def oldbranchmap():
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
174 current = branchmap.branchcache
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
175 try:
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
176 branchmap.branchcache = orig
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
177 yield
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
178 finally:
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
179 branchmap.branchcache = current
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
180 else:
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
181 oldbranchmap = util.nullcontextmanager
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
182
6795
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
183 if util.safehasattr(branchmap, 'branchcache'):
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
184 allbccls = (branchmap.branchcache,)
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
185 if util.safehasattr(branchmap, 'remotebranchcache'):
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
186 # hg <= 4.9 (eb7ce452e0fb)
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
187 allbccls = (branchmap.branchcache, branchmap.remotebranchcache)
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
188
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
189 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
190
d49f75eab6a3 topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
191 def __init__(self, *args, **kwargs):
6794
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
192 with oldbranchmap():
68f7ba35ea83 topic: bring back oldbranchmap context manager for hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6790
diff changeset
193 super(_topiccache, self).__init__(*args, **kwargs)
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
194 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
195
1890
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
196 def copy(self):
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
197 """return an deep copy of the branchcache object"""
6795
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
198 assert isinstance(self, allbccls) # help pytype
6333
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6271
diff changeset
199 entries = compat.bcentries(self)
f4ffe1e67a9b topic: move compatibility for branchcache._entries to topic/compat.py
Anton Shestakov <av6@dwimlabs.net>
parents: 6271
diff changeset
200 args = (entries, self.tipnode, self.tiprev, self.filteredhash,
5847
ad7c9c0b7a63 topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents: 5665
diff changeset
201 self._closednodes)
ad7c9c0b7a63 topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents: 5665
diff changeset
202 if util.safehasattr(self, '_repo'):
ad7c9c0b7a63 topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents: 5665
diff changeset
203 # hg <= 5.7 (6266d19556ad)
ad7c9c0b7a63 topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents: 5665
diff changeset
204 args = (self._repo,) + args
ad7c9c0b7a63 topic: compatibility for branchcache having a repo argument in 5.8
Anton Shestakov <av6@dwimlabs.net>
parents: 5665
diff changeset
205 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
206 new.phaseshash = self.phaseshash
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
207 return new
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
208
6336
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
209 def load(self, repo, lineiter):
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
210 """call branchmap.load(), and then transform branch names to be in the
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
211 new "//" format
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
212 """
6788
0674b56d3526 topic: drop oldbranchmap context manager, _topiccache is now a mixin
Anton Shestakov <av6@dwimlabs.net>
parents: 6704
diff changeset
213 assert isinstance(self, branchmap.branchcache) # help pytype
6336
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
214 super(_topiccache, self).load(repo, lineiter)
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
215 entries = compat.bcentries(self)
1885
d49f75eab6a3 topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
216
6336
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
217 for branch in tuple(entries):
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
218 formatted = common.formatfqbn(branch=branch)
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
219 if branch != formatted:
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
220 entries[formatted] = entries.pop(branch)
1885
d49f75eab6a3 topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
221
1890
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
222 def validfor(self, repo):
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
223 """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
224
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
225 - 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
226 - True when cache is up to date or a subset of current repo."""
6795
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
227 assert isinstance(self, allbccls) # help pytype
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
228 valid = super(_topiccache, self).validfor(repo)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
229 if not valid:
1890
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
230 return False
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
231 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
232 # phasehash at None means this is a branchmap
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
233 # come from non topic thing
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
234 return True
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
235 else:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
236 try:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
237 valid = self.phaseshash == _phaseshash(repo, self.tiprev)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
238 return valid
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
239 except IndexError:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
240 return False
1890
e846b8f402d0 topicmap: write and read format from disc
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1885
diff changeset
241
1885
d49f75eab6a3 topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
242 def write(self, repo):
6336
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
243 """write cache to disk if it's not topic-only, but first transform
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
244 cache keys from branches in "//" format into bare branch names
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
245 """
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
246 # 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
247 # the time will be fast enough
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
248 if not istopicfilter(repo.filtername):
6336
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
249 cache = self.copy()
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
250 entries = compat.bcentries(cache)
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
251
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
252 for formatted in tuple(entries):
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
253 branch, tns, topic = common.parsefqbn(formatted)
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
254 if branch != formatted:
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
255 entries[branch] = entries.pop(formatted)
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
256
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
257 super(_topiccache, cache).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
258
d49f75eab6a3 topic: take topic in account for all branch head computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
259 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
260 """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
261 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
262 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
263 """
6795
1b59ddda3242 topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Anton Shestakov <av6@dwimlabs.net>
parents: 6794
diff changeset
264 assert isinstance(self, allbccls) # help pytype
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
265 if not istopicfilter(repo.filtername):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
266 return super(_topiccache, self).update(repo, revgen)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2004
diff changeset
267
6336
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
268 # See topic.discovery._headssummary(), where repo.unfiltered gets
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
269 # overridden to return .filtered('unfiltered-topic'). revbranchcache
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
270 # only can be created for unfiltered repo (filtername is None), so we
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
271 # do that here, and this revbranchcache will be cached inside repo.
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
272 # When we get rid of *-topic filters, then this workaround can be
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
273 # removed too.
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
274 repo.unfiltered().revbranchcache()
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
275
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
276 super(_topiccache, self).update(repo, revgen)
453861da6922 topic: use fully qualified branch name during exchange
Anton Shestakov <av6@dwimlabs.net>
parents: 6333
diff changeset
277 self.phaseshash = _phaseshash(repo, self.tiprev)
6385
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
278
6789
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
279 class _TopicCacheV2(object): # combine me with branchmap.BranchCacheV2
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
280
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
281 def __init__(self, *args, **kwargs):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
282 super(_TopicCacheV2, self).__init__(*args, **kwargs)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
283 self.phaseshash = None
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
284
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
285 def _load_heads(self, repo, lineiter):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
286 """call BranchCacheV2._load_heads(), and then transform branch names to
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
287 be in the new "//" format
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
288 """
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
289 assert isinstance(self, branchmap.BranchCacheV2) # help pytype
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
290 super(_TopicCacheV2, self)._load_heads(repo, lineiter)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
291
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
292 for branch in tuple(self._entries):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
293 formatted = common.formatfqbn(branch=branch)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
294 if branch != formatted:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
295 self._entries[formatted] = self._entries.pop(branch)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
296
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
297 def validfor(self, repo):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
298 """Is the cache content valid regarding a repo
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
299
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
300 - False when cached tipnode is unknown or if we detect a strip.
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
301 - True when cache is up to date or a subset of current repo."""
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
302 assert isinstance(self, (branchmap.BranchCacheV2, branchmap.remotebranchcache)) # help pytype
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
303 valid = super(_TopicCacheV2, self).validfor(repo)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
304 if not valid:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
305 return False
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
306 elif not istopicfilter(repo.filtername) or self.phaseshash is None:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
307 # phasehash at None means this is a branchmap
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
308 # come from non topic thing
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
309 return True
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
310 else:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
311 try:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
312 valid = self.phaseshash == _phaseshash(repo, self.tiprev)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
313 return valid
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
314 except IndexError:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
315 return False
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
316
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
317 def write(self, repo):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
318 """write cache to disk if it's not topic-only, but first transform
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
319 cache keys from branches in "//" format into bare branch names
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
320 """
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
321 # we expect mutable set to be small enough to be that computing it all
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
322 # the time will be fast enough
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
323 if not istopicfilter(repo.filtername):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
324 entries = self._entries.copy()
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
325
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
326 for formatted in tuple(entries):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
327 branch, tns, topic = common.parsefqbn(formatted)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
328 if branch != formatted:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
329 entries[branch] = entries.pop(formatted)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
330
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
331 oldentries = self._entries
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
332 try:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
333 self._entries = entries
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
334 super(_TopicCacheV2, self).write(repo)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
335 finally:
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
336 self._entries = oldentries
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
337
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
338 def update(self, repo, revgen):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
339 """Given a branchhead cache, self, that may have extra nodes or be
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
340 missing heads, and a generator of nodes that are strictly a superset of
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
341 heads missing, this function updates self to be correct.
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
342 """
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
343 assert isinstance(self, (branchmap.BranchCacheV2, branchmap.remotebranchcache)) # help pytype
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
344 if not istopicfilter(repo.filtername):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
345 return super(_TopicCacheV2, self).update(repo, revgen)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
346
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
347 # See topic.discovery._headssummary(), where repo.unfiltered gets
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
348 # overridden to return .filtered('unfiltered-topic'). revbranchcache
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
349 # only can be created for unfiltered repo (filtername is None), so we
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
350 # do that here, and this revbranchcache will be cached inside repo.
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
351 # When we get rid of *-topic filters, then this workaround can be
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
352 # removed too.
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
353 repo.unfiltered().revbranchcache()
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
354
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
355 super(_TopicCacheV2, self).update(repo, revgen)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
356 if util.safehasattr(self, 'tiprev'):
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
357 # remotebranchcache doesn't have self.tiprev
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
358 self.phaseshash = _phaseshash(repo, self.tiprev)
cd8e1a697124 topic: compatibility for branchmap.BranchCacheV2
Anton Shestakov <av6@dwimlabs.net>
parents: 6788
diff changeset
359
6385
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
360 def _wrapbmread(orig, repo):
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
361 """call branchmap.read(), and then transform branch names to be in the
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
362 new "//" format
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
363 """
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
364 partial = orig(repo)
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
365 if partial is None:
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
366 # because of IOError or OSError
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
367 return partial
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
368
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
369 entries = compat.bcentries(partial)
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
370
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
371 for branch in tuple(entries):
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
372 formatted = common.formatfqbn(branch=branch)
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
373 if branch != formatted:
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
374 entries[formatted] = entries.pop(branch)
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
375
0bc90758f613 topic: wrap branchmap.read() as well (compatibility for hg <= 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents: 6376
diff changeset
376 return partial