view 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
line wrap: on
line source

# states.py - introduce the state concept for mercurial changeset
#
# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
#                Logilab SA        <contact@logilab.fr>
#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

'''A set of command to make changeset evolve.'''

from mercurial import cmdutil
from mercurial import scmutil
from mercurial import node
from mercurial import error
from mercurial import extensions
from mercurial import commands
from mercurial.i18n import _

### util function
#############################
def noderange(repo, revsets):
    """The same as revrange but return node"""
    return map(repo.changelog.node,
               scmutil.revrange(repo, revsets))

### extension check
#############################

def extsetup(ui):
    try:
        rebase = extensions.find('obsolete')
    except KeyError:
        raise error.Abort(_('evolution extension require obsolete extension.'))

### new command
#############################
cmdtable = {}
command = cmdutil.command(cmdtable)

@command('^kill',
    [],
    '<revs>')
def kill(ui, repo, *revs):
    """mark a changeset as obsolete

    This update the parent directory to a not-killed parent if the current
    working directory parent are killed.

    XXX bookmark support
    XXX handle merge
    XXX check immutable first
    """
    wlock = repo.wlock()
    try:
        targetnodes = set(noderange(repo, revs))
        for n in targetnodes:
            repo.addobsolete(node.nullid, n)
        # update to an unkilled parent
        wdp = repo['.']
        newnode = wdp
        while newnode.obsolete():
            newnode = newnode.parents()[0]
        if newnode.node() != wdp.node():
            commands.update(ui, repo, newnode.rev())
            ui.status(_('working directory now at %s\n') % newnode)

    finally:
        wlock.release()