comparison hgext/inhibit.py @ 1241:3625d006e81b

inhibit: Add -D option to the bookmark command The -D option for bookmark is similar to the -B option for strip. It deletes the bookmark and prunes the changes underneath it that are not reachable.
author Laurent Charignon <lcharignon@fb.com>
date Tue, 31 Mar 2015 14:17:46 -0700
parents e1347ce2f954
children f96dad835054
comparison
equal deleted inserted replaced
1240:e1347ce2f954 1241:3625d006e81b
28 from mercurial import repoview 28 from mercurial import repoview
29 from mercurial import revset 29 from mercurial import revset
30 from mercurial import error 30 from mercurial import error
31 from mercurial import commands 31 from mercurial import commands
32 from mercurial import bookmarks 32 from mercurial import bookmarks
33 from mercurial.i18n import _
33 34
34 cmdtable = {} 35 cmdtable = {}
35 command = cmdutil.command(cmdtable) 36 command = cmdutil.command(cmdtable)
36 37
37 def reposetup(ui, repo): 38 def reposetup(ui, repo):
70 """ Add inhibition markers to every obsolete bookmarks """ 71 """ Add inhibition markers to every obsolete bookmarks """
71 repo = bkmstoreinst._repo 72 repo = bkmstoreinst._repo
72 bkmstorenodes = [repo[v].node() for v in bkmstoreinst.values()] 73 bkmstorenodes = [repo[v].node() for v in bkmstoreinst.values()]
73 _inhibitmarkers(repo, bkmstorenodes) 74 _inhibitmarkers(repo, bkmstorenodes)
74 return orig(bkmstoreinst, *args, **kwargs) 75 return orig(bkmstoreinst, *args, **kwargs)
76
77 def _bookmark(orig, ui, repo, *bookmarks, **opts):
78 """ Add a -D option to the bookmark command, map it to prune -B """
79 def getdefaultopts(module, command):
80 """ Get default options of a command from a module """
81 cmds = [v for k,v in module.cmdtable.items() if command in k]
82 assert len(cmds) == 1, "Ambiguous command"
83 # Options of the first command that matched
84 cmdopts = cmds[0][1]
85 optsdict = {}
86 for d in cmdopts:
87 optsdict[d[1]] = d[2]
88 return optsdict
89
90 haspruneopt = opts.get('prune', False)
91
92 if not haspruneopt:
93 return orig(ui, repo, *bookmarks, **opts)
94 # Call prune -B
95 evolve = extensions.find('evolve')
96 optsdict = getdefaultopts(evolve, 'prune|obsolete')
97 optsdict['bookmark'] = bookmarks[0]
98 evolve.cmdprune(ui, repo, **optsdict)
75 99
76 # obsolescence inhibitor 100 # obsolescence inhibitor
77 ######################## 101 ########################
78 102
79 def _schedulewrite(tr, obsinhibit): 103 def _schedulewrite(tr, obsinhibit):
180 extensions.wrapcommand(commands.table, 'update', _update) 204 extensions.wrapcommand(commands.table, 'update', _update)
181 # There are two ways to save bookmark changes during a transation, we 205 # There are two ways to save bookmark changes during a transation, we
182 # wrap both to add inhibition markers. 206 # wrap both to add inhibition markers.
183 extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged) 207 extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged)
184 extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged) 208 extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged)
209 # Add bookmark -D option
210 entry = extensions.wrapcommand(commands.table, 'bookmark', _bookmark)
211 entry[1].append(('D','prune',None,
212 _('delete the bookmark and prune the commits underneath')))
213
185 214
186 215
187 def gethashsymbols(tree): 216 def gethashsymbols(tree):
188 # Returns the list of symbols of the tree that look like hashes 217 # Returns the list of symbols of the tree that look like hashes
189 # for example for the revset 3::abe3ff it will return ('abe3ff') 218 # for example for the revset 3::abe3ff it will return ('abe3ff')