Mercurial > evolve
annotate hgext/inhibit.py @ 1224:859a854cedc3
add a 'inhibit' extension
This extension will be used to reduce the scope of evolve in order to make some
of its features available to the mass earlier.
See extension documentation for details.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 06 Mar 2015 21:25:44 -0800 |
parents | |
children | 577f5340be6f |
rev | line source |
---|---|
1224
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
1 """Reduce the changesets evolution feature scope for early and noob friendly UI |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
2 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
3 The full scale changeset evolution have some massive bleeding edge and it is |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
4 very easy for people not very intimate with the concept to end up in intricate |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
5 situation. In order to get some of the benefit sooner, this extension is |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
6 disabling some of the less polished aspect of evolution. It should gradually |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
7 get thinner and thinner as changeset evolution will get more polished. This |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
8 extension is only recommended for large scale organisations. Individual user |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
9 should probably stick on using Evolution in its current state, understand its |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
10 concept and provide feedback |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
11 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
12 The first feature provided by this extension is the ability to "inhibit" |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
13 obsolescence markers. Obsolete revision can be cheaply brought back to life |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
14 that way. However as the inhibitor are not fitting in an append only model, |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
15 this is incompatible with sharing mutable history. |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
16 """ |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
17 from mercurial import localrepo |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
18 from mercurial import obsolete |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
19 from mercurial import extensions |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
20 from mercurial import cmdutil |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
21 from mercurial import scmutil |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
22 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
23 cmdtable = {} |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
24 command = cmdutil.command(cmdtable) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
25 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
26 def reposetup(ui, repo): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
27 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
28 class obsinhibitedrepo(repo.__class__): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
29 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
30 @localrepo.storecache('obsinhibit') |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
31 def _obsinhibit(self): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
32 # XXX we should make sure it is invalidated by transaction failure |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
33 obsinhibit = set() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
34 raw = self.sopener.tryread('obsinhibit') |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
35 for i in xrange(0, len(raw), 20): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
36 obsinhibit.add(raw[i:i+20]) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
37 return obsinhibit |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
38 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
39 repo.__class__ = obsinhibitedrepo |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
40 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
41 # obsolescence inhibitor |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
42 ######################## |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
43 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
44 def _schedulewrite(tr, obsinhibit): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
45 """Make sure on disk content will be updated on transaction commit""" |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
46 def writer(fp): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
47 """Serialize the inhibited list to disk. |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
48 """ |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
49 raw = ''.join(obsinhibit) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
50 fp.write(raw) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
51 tr.addfilegenerator('obsinhibit', ('obsinhibit',), writer) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
52 tr.hookargs['obs_inbihited'] = '1' |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
53 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
54 def _inhibitmarkers(repo, nodes): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
55 """add marker inhibitor for all obsolete revision under <nodes> |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
56 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
57 Content of <nodes> and all mutable ancestors are considered. Marker for |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
58 obsolete revision only are created. |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
59 """ |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
60 newinhibit = repo.set('::%ln and obsolete()', nodes) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
61 if newinhibit: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
62 tr = repo.transaction('obsinhibit') |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
63 try: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
64 repo._obsinhibit.update(c.node() for c in newinhibit) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
65 _schedulewrite(tr, repo._obsinhibit) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
66 repo.invalidatevolatilesets() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
67 tr.close() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
68 finally: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
69 tr.release() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
70 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
71 def _deinhibitmarkers(repo, nodes): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
72 """lift obsolescence inhibition on a set of nodes |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
73 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
74 This will be triggered when inhibited nodes received new obsolescence |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
75 markers. Otherwise the new obsolescence markers would also be inhibited. |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
76 """ |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
77 deinhibited = repo._obsinhibit & set(nodes) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
78 if deinhibited: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
79 tr = repo.transaction('obsinhibit') |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
80 try: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
81 repo._obsinhibit -= deinhibited |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
82 _schedulewrite(tr, repo._obsinhibit) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
83 repo.invalidatevolatilesets() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
84 tr.close() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
85 finally: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
86 tr.release() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
87 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
88 def _createmarkers(orig, repo, relations, flag=0, date=None, metadata=None): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
89 """wrap markers create to make sure we de-inhibit target nodes""" |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
90 # wrapping transactio to unify the one in each function |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
91 tr = repo.transaction('add-obsolescence-marker') |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
92 try: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
93 orig(repo, relations, flag, date, metadata) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
94 precs = (r[0].node() for r in relations) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
95 _deinhibitmarkers(repo, precs) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
96 tr.close() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
97 finally: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
98 tr.release() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
99 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
100 def extsetup(ui): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
101 # lets wrap the computation of the obsolete set |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
102 # We apply inhibition there |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
103 obsfunc = obsolete.cachefuncs['obsolete'] |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
104 def _computeobsoleteset(repo): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
105 """remove any inhibited nodes from the obsolete set |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
106 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
107 This will trickle down to other part of mercurial (hidden, log, etc)""" |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
108 obs = obsfunc(repo) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
109 getrev = repo.changelog.nodemap.get |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
110 for n in repo._obsinhibit: |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
111 obs.discard(getrev(n)) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
112 return obs |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
113 obsolete.cachefuncs['obsolete'] = _computeobsoleteset |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
114 # drop divergence computation since it is incompatible with "light revive" |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
115 obsolete.cachefuncs['divergent'] = lambda repo: set() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
116 # drop bumped computation since it is incompatible with "light revive" |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
117 obsolete.cachefuncs['bumped'] = lambda repo: set() |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
118 # wrap create marker to make it able to lift the inhibition |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
119 extensions.wrapfunction(obsolete, 'createmarkers', _createmarkers) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
120 |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
121 @command('debugobsinhibit', [], '') |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
122 def cmddebugobsinhibit(ui, repo, *revs): |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
123 """inhibit obsolescence markers effect on a set of revs""" |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
124 nodes = (repo[r].node() for r in scmutil.revrange(repo, revs)) |
859a854cedc3
add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
125 _inhibitmarkers(repo, nodes) |