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