annotate hgext/inhibit.py @ 1362:73e5b5280c1c

inhibit: improve performance of transaction wrapping Before this patch, transaction wrapping was the most expensive part of inhibit computation wise. This patch changes the revset that we use in the transaction wrapping to make it ~50x faster to compute: revset #0: obsolete() - hidden() 0) wall 0.000214 comb 0.000000 user 0.000000 sys 0.000000 (best of 11209) vs revset #0: (not hidden()) and obsolete() 0) wall 0.010965 comb 0.010000 user 0.010000 sys 0.000000 (best of 237)
author Laurent Charignon <lcharignon@fb.com>
date Sat, 13 Jun 2015 11:14:27 -0700
parents 9a1415f8b21b
children 9c3ba42c582a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
1 """reduce the changesets evolution feature scope for early and noob friendly ui
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
2
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
3 the full scale changeset evolution have some massive bleeding edge and it is
1224
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
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
5 situation. in order to get some of the benefit sooner, this extension is
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
6 disabling some of the less polished aspect of evolution. it should gradually
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
7 get thinner and thinner as changeset evolution will get more polished. this
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
8 extension is only recommended for large scale organisations. individual user
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
9 should probably stick on using evolution in its current state, understand its
1224
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
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
12 This extension provides the ability to "inhibit" obsolescence markers. obsolete
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
13 revision can be cheaply brought back to life that way.
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
14 However as the inhibitor are not fitting in an append only model, this is
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
15 incompatible with sharing mutable history.
1224
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
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
21 from mercurial import error
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
22 from mercurial import scmutil
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
23 from mercurial import commands
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
24 from mercurial import lock as lockmod
1234
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
25 from mercurial import bookmarks
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
26 from mercurial.i18n import _
1224
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 cmdtable = {}
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
29 command = cmdutil.command(cmdtable)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
30
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
31 def reposetup(ui, repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
32
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
33 class obsinhibitedrepo(repo.__class__):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
34
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
35 @localrepo.storecache('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
36 def _obsinhibit(self):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
37 # 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
38 obsinhibit = set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
39 raw = self.sopener.tryread('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
40 for i in xrange(0, len(raw), 20):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
41 obsinhibit.add(raw[i:i+20])
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
42 return obsinhibit
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
43
1292
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
44 def commit(self, *args, **kwargs):
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
45 newnode = super(obsinhibitedrepo, self).commit(*args, **kwargs)
1346
9a1415f8b21b inhbit: don't crash on commit with no changes
Laurent Charignon <lcharignon@fb.com>
parents: 1339
diff changeset
46 if newnode is not None:
9a1415f8b21b inhbit: don't crash on commit with no changes
Laurent Charignon <lcharignon@fb.com>
parents: 1339
diff changeset
47 _inhibitmarkers(repo, [newnode])
1292
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
48 return newnode
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
49
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
50 repo.__class__ = obsinhibitedrepo
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
51 # Wrapping this to inhibit obsolete revs resulting from a transaction
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
52 extensions.wrapfunction(localrepo.localrepository,
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
53 'transaction', transactioncallback)
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
54
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
55 def _update(orig, ui, repo, *args, **kwargs):
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
56 """
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
57 When moving to a commit we want to inhibit any obsolete commit affecting
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
58 the changeset we are updating to. In other words we don't want any visible
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
59 commit to be obsolete.
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
60 """
1303
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
61 wlock = None
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
62 try:
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
63 # Evolve is running a hook on lock release to display a warning message
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
64 # if the workind dir's parent is obsolete.
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
65 # We take the lock here to make sure that we inhibit the parent before
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
66 # that hook get a chance to run.
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
67 wlock = repo.wlock()
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
68 res = orig(ui, repo, *args, **kwargs)
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
69 newhead = repo['.'].node()
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
70 _inhibitmarkers(repo, [newhead])
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
71 return res
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
72 finally:
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
73 lockmod.release(wlock)
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
74
1234
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
75 def _bookmarkchanged(orig, bkmstoreinst, *args, **kwargs):
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
76 """ Add inhibition markers to every obsolete bookmarks """
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
77 repo = bkmstoreinst._repo
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
78 bkmstorenodes = [repo[v].node() for v in bkmstoreinst.values()]
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
79 _inhibitmarkers(repo, bkmstorenodes)
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
80 return orig(bkmstoreinst, *args, **kwargs)
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
81
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
82 def _bookmark(orig, ui, repo, *bookmarks, **opts):
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
83 """ Add a -D option to the bookmark command, map it to prune -B """
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
84 haspruneopt = opts.get('prune', False)
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
85 if not haspruneopt:
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
86 return orig(ui, repo, *bookmarks, **opts)
1293
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
87
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
88 # Call prune -B
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
89 evolve = extensions.find('evolve')
1293
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
90 optsdict = {
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
91 'new': [],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
92 'succ': [],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
93 'rev': [],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
94 'bookmark': bookmarks[0],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
95 'keep': None,
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
96 'biject': False,
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
97 }
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
98 evolve.cmdprune(ui, repo, **optsdict)
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
99
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
100 # obsolescence inhibitor
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
101 ########################
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
102
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
103 def _schedulewrite(tr, obsinhibit):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
104 """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
105 def writer(fp):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
106 """Serialize the inhibited list to disk.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
107 """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
108 raw = ''.join(obsinhibit)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
109 fp.write(raw)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
110 tr.addfilegenerator('obsinhibit', ('obsinhibit',), writer)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
111 tr.hookargs['obs_inbihited'] = '1'
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
112
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
113 def _filterpublic(repo, nodes):
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
114 """filter out inhibitor on public changeset
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
115
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
116 Public changesets are already immune to obsolescence"""
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
117 getrev = repo.changelog.nodemap.get
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
118 getphase = repo._phasecache.phase
1338
77cbf9121e8a inhibit: handle inhibit marker on stripped revision
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1334
diff changeset
119 return (n for n in repo._obsinhibit
77cbf9121e8a inhibit: handle inhibit marker on stripped revision
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1334
diff changeset
120 if getrev(n) is not None and getphase(repo, getrev(n)))
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
121
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
122 def _inhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
123 """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
124
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
125 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
126 obsolete revision only are created.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
127 """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
128 newinhibit = repo.set('::%ln and obsolete()', nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
129 if newinhibit:
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
130 lock = tr = None
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
131 try:
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
132 lock = repo.lock()
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
133 tr = repo.transaction('obsinhibit')
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
134 repo._obsinhibit.update(c.node() for c in newinhibit)
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
135 _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
136 repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
137 tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
138 finally:
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
139 lockmod.release(tr, lock)
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
140
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
141 def _deinhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
142 """lift obsolescence inhibition on a set of nodes
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
143
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
144 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
145 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
146 """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
147 deinhibited = repo._obsinhibit & set(nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
148 if deinhibited:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
149 tr = repo.transaction('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
150 try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
151 repo._obsinhibit -= deinhibited
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
152 _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
153 repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
154 tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
155 finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
156 tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
157
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
158 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
159 """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
160 # 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
161 tr = repo.transaction('add-obsolescence-marker')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
162 try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
163 orig(repo, relations, flag, date, metadata)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
164 precs = (r[0].node() for r in relations)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
165 _deinhibitmarkers(repo, precs)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
166 tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
167 finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
168 tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
169
1240
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
170 def transactioncallback(orig, repo, *args, **kwargs):
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
171 """ Wrap localrepo.transaction to inhibit new obsolete changes """
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
172 def inhibitposttransaction(transaction):
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
173 # At the end of the transaction we catch all the new visible and
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
174 # obsolete commit to inhibit them
1362
73e5b5280c1c inhibit: improve performance of transaction wrapping
Laurent Charignon <lcharignon@fb.com>
parents: 1346
diff changeset
175 visibleobsolete = repo.revs('obsolete() - hidden()')
1321
8fa74845eb1f inhibit: don't inhibit pinned commits during rebase
Durham Goode <durham@fb.com>
parents: 1303
diff changeset
176 ignoreset = set(getattr(repo, '_rebaseset', []))
8fa74845eb1f inhibit: don't inhibit pinned commits during rebase
Durham Goode <durham@fb.com>
parents: 1303
diff changeset
177 visibleobsolete = list(r for r in visibleobsolete if r not in ignoreset)
1240
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
178 if visibleobsolete:
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
179 _inhibitmarkers(repo, [repo[r].node() for r in visibleobsolete])
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
180 transaction = orig(repo, *args, **kwargs)
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
181 transaction.addpostclose('inhibitposttransaction', inhibitposttransaction)
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
182 return transaction
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
183
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
184 def extsetup(ui):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
185 # lets wrap the computation of the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
186 # We apply inhibition there
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
187 obsfunc = obsolete.cachefuncs['obsolete']
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
188 def _computeobsoleteset(repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
189 """remove any inhibited nodes from the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
190
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
191 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
192 obs = obsfunc(repo)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
193 getrev = repo.changelog.nodemap.get
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
194 for n in repo._obsinhibit:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
195 obs.discard(getrev(n))
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
196 return obs
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
197 try:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
198 extensions.find('directaccess')
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
199 except KeyError:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
200 errormsg = _('Cannot use inhibit without the direct access extension')
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
201 raise error.Abort(errormsg)
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
202 obsolete.cachefuncs['obsolete'] = _computeobsoleteset
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
203 # 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
204 extensions.wrapfunction(obsolete, 'createmarkers', _createmarkers)
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
205 # drop divergence computation since it is incompatible with "light revive"
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
206 obsolete.cachefuncs['divergent'] = lambda repo: set()
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
207 # drop bumped computation since it is incompatible with "light revive"
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
208 obsolete.cachefuncs['bumped'] = lambda repo: set()
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
209 # wrap update to make sure that no obsolete commit is visible after an
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
210 # update
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
211 extensions.wrapcommand(commands.table, 'update', _update)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
212 # There are two ways to save bookmark changes during a transation, we
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
213 # wrap both to add inhibition markers.
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
214 extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
215 extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
216 # Add bookmark -D option
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
217 entry = extensions.wrapcommand(commands.table, 'bookmark', _bookmark)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
218 entry[1].append(('D','prune',None,
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents: 1338
diff changeset
219 _('delete the bookmark and prune the commits underneath')))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
220
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
221 @command('debugobsinhibit', [], '')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
222 def cmddebugobsinhibit(ui, repo, *revs):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
223 """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
224 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
225 _inhibitmarkers(repo, nodes)