view states.py @ 0:bbeef801409c

minimalistic state concept.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Fri, 20 May 2011 16:16:34 +0200
parents
children beabde937e36
line wrap: on
line source

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

'''introduce the state concept for mercurial changeset

Change can be in the following state:

0 immutable
1 mutable
2 private

name are not fixed yet.
'''


STATES = (0, )
def statename(state):
    return str(STATES)

import mercurial.context
import mercurial.templatekw


# Patch changectx
#############################

def state(ctx):
    return ctx._repo.nodestate(ctx.node())
mercurial.context.changectx.state = state

# improve template
#############################

def showstate(ctx, **args):
    return ctx.state()


mercurial.templatekw.keywords['state'] = showstate

def reposetup(ui, repo):

    if not repo.local():
        return
    class statefulrepo(repo.__class__):

        def nodestate(self, node):
            return STATES[0]

    repo.__class__ = statefulrepo