annotate hgext/evolution.py @ 81:5cec25ce019c

Basic kill command
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 14 Sep 2011 22:29:19 +0200
parents
children 8108d566a8b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
1 # states.py - introduce the state concept for mercurial changeset
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
2 #
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
3 # Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
4 # Logilab SA <contact@logilab.fr>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
5 # Pierre-Yves David <pierre-yves.david@ens-lyon.org>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
6 #
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
7 # This software may be used and distributed according to the terms of the
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
8 # GNU General Public License version 2 or any later version.
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
9
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
10 '''A set of command to make changeset evolve.'''
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
11
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
12 from mercurial import cmdutil
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
13 from mercurial import scmutil
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
14 from mercurial import node
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
15 from mercurial import error
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
16 from mercurial import extensions
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
17 from mercurial import commands
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
18 from mercurial.i18n import _
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
19
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
20 ### util function
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
21 #############################
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
22 def noderange(repo, revsets):
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
23 """The same as revrange but return node"""
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
24 return map(repo.changelog.node,
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
25 scmutil.revrange(repo, revsets))
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
26
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
27 ### extension check
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
28 #############################
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
29
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
30 def extsetup(ui):
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
31 try:
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
32 rebase = extensions.find('obsolete')
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
33 except KeyError:
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
34 raise error.Abort(_('evolution extension require obsolete extension.'))
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
35
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
36 ### new command
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
37 #############################
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
38 cmdtable = {}
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
39 command = cmdutil.command(cmdtable)
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
40
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
41 @command('^kill',
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
42 [],
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
43 '<revs>')
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
44 def kill(ui, repo, *revs):
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
45 """mark a changeset as obsolete
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
46
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
47 This update the parent directory to a not-killed parent if the current
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
48 working directory parent are killed.
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
49
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
50 XXX bookmark support
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
51 XXX handle merge
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
52 XXX check immutable first
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
53 """
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
54 wlock = repo.wlock()
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
55 try:
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
56 targetnodes = set(noderange(repo, revs))
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
57 for n in targetnodes:
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
58 repo.addobsolete(node.nullid, n)
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
59 # update to an unkilled parent
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
60 wdp = repo['.']
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
61 newnode = wdp
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
62 while newnode.obsolete():
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
63 newnode = newnode.parents()[0]
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
64 if newnode.node() != wdp.node():
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
65 commands.update(ui, repo, newnode.rev())
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
66 ui.status(_('working directory now at %s\n') % newnode)
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
67
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
68 finally:
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
69 wlock.release()
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
70