states.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 07 Jul 2011 11:10:05 +0200
changeset 27 31906bc290ff
parent 26 c9da15600775
child 28 0918e3b54f0b
permissions -rw-r--r--
Working directory is draft.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
# states.py - introduce the state concept for mercurial changeset
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
#
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
# Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
#                Logilab SA        <contact@logilab.fr>
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
#                Augie Fackler     <durin42@gmail.com>
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
#
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
# This software may be used and distributed according to the terms of the
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
# GNU General Public License version 2 or any later version.
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
'''introduce the state concept for mercurial changeset
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    12
Change can be in the following state:
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
0 immutable
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
1 mutable
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    16
2 private
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    17
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    18
name are not fixed yet.
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
'''
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
    20
import os
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    21
from functools import partial
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
    22
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    23
from mercurial.i18n import _
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    24
from mercurial import cmdutil
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    25
from mercurial import scmutil
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    26
from mercurial import context
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    27
from mercurial import revset
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    28
from mercurial import templatekw
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    29
from mercurial import util
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    30
from mercurial import node
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
    31
from mercurial.node import nullid, hex, short
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    32
from mercurial import discovery
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    33
from mercurial import extensions
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
    34
from mercurial import wireproto
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
    35
from mercurial import pushkey
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
    36
from mercurial.lock import release
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    37
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    38
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    39
_NOSHARE=2
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
    40
_MUTABLE=1
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    41
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    42
class state(object):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    43
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    44
    def __init__(self, name, properties=0, next=None):
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    45
        self.name = name
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    46
        self.properties = properties
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    47
        assert next is None or self < next
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    48
        self.next = next
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    49
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    50
    def __repr__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    51
        return 'state(%s)' % self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    52
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    53
    def __str__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    54
        return self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    55
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    56
    @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    57
    def trackheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    58
        """Do we need to track heads of changeset in this state ?
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    59
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    60
        We don't need to track heads for the last state as this is repos heads"""
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    61
        return self.next is not None
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    62
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    63
    def __cmp__(self, other):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    64
        return cmp(self.properties, other.properties)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    65
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    66
    @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    67
    def _revsetheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    68
        """function to be used by revset to finds heads of this states"""
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    69
        assert self.trackheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    70
        def revsetheads(repo, subset, x):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    71
            args = revset.getargs(x, 0, 0, 'publicheads takes no arguments')
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    72
            heads = map(repo.changelog.rev, repo._statesheads[self])
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    73
            heads.sort()
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    74
            return heads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    75
        return revsetheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    76
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    77
    @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    78
    def headssymbol(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    79
        """name of the revset symbols"""
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    80
        if self.trackheads:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    81
            return "%sheads" % self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    82
        else:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    83
            return 'heads'
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    84
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    85
ST2 = state('draft', _NOSHARE | _MUTABLE)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    86
ST1 = state('ready', _MUTABLE, next=ST2)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    87
ST0 = state('published', next=ST1)
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    88
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    89
STATES = (ST0, ST1, ST2)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    90
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
    91
@util.cachefunc
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    92
def laststatewithout(prop):
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    93
    for state in STATES:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    94
        if not state.properties & prop:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    95
            candidate = state
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    96
        else:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    97
            return candidate
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    98
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
    99
# util function
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   100
#############################
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   101
def noderange(repo, revsets):
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   102
    return map(repo.changelog.node,
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   103
               scmutil.revrange(repo, revsets))
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   104
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   105
# Patch changectx
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   106
#############################
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   107
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   108
def state(ctx):
27
31906bc290ff Working directory is draft.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 26
diff changeset
   109
    if ctx.node()is None:
31906bc290ff Working directory is draft.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 26
diff changeset
   110
        return STATES[-1]
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   111
    return ctx._repo.nodestate(ctx.node())
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   112
context.changectx.state = state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   113
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   114
# improve template
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   115
#############################
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   116
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   117
def showstate(ctx, **args):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   118
    return ctx.state()
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   119
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   120
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   121
# New commands
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   122
#############################
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   123
26
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   124
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   125
def cmdstates(ui, repo, *states, **opt):
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   126
    """show enabled states"""
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   127
    if not states:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   128
        for st in sorted(repo._enabledstates):
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   129
            ui.write('%s\n' % st)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   130
    else:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   131
        off = opt.get('off', False)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   132
        for state_name in states:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   133
            for st in STATES:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   134
                if st.name == state_name:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   135
                    break
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   136
            else:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   137
                ui.write_err(_('no state named %s\n') % state_name)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   138
                return 1
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   139
            if off and st in repo._enabledstates:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   140
                repo._enabledstates.remove(st)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   141
            else:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   142
                repo._enabledstates.add(st)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   143
        repo._writeenabledstates()
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   144
    return 0
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   145
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   146
cmdtable = {'states': (cmdstates, [ ('', 'off', False, _('desactivate the state') )], '<state>')}
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
   147
#cmdtable = {'states': (cmdstates, [], '<state>')}
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   148
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   149
def makecmd(state):
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   150
    def cmdmoveheads(ui, repo, *changesets):
25
b372166d460d Add docstring to move head command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 24
diff changeset
   151
        """set a revision in %s state""" % state
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   152
        revs = scmutil.revrange(repo, changesets)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   153
        repo.setstate(state, [repo.changelog.node(rev) for rev in revs])
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   154
        return 0
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   155
    return cmdmoveheads
24
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   156
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   157
for state in STATES:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   158
    if state.trackheads:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   159
        cmdmoveheads = makecmd(state)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   160
        cmdtable[state.name] = (cmdmoveheads, [], '<revset>')
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   161
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   162
# Pushkey mechanism for mutable
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   163
#########################################
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   164
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   165
def pushimmutableheads(repo, key, old, new):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   166
    st = ST0
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   167
    w = repo.wlock()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   168
    try:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   169
        #print 'pushing', key
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   170
        repo.setstate(ST0, [node.bin(key)])
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   171
    finally:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   172
        w.release()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   173
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   174
def listimmutableheads(repo):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   175
    return dict.fromkeys(map(node.hex, repo.stateheads(ST0)), '1')
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   176
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   177
pushkey.register('immutableheads', pushimmutableheads, listimmutableheads)
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   178
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   179
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   180
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   181
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   182
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   183
def uisetup(ui):
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   184
    def filterprivateout(orig, repo, *args,**kwargs):
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   185
        common, heads = orig(repo, *args, **kwargs)
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   186
        return common, repo._reducehead(heads)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   187
    def filterprivatein(orig, repo, remote, *args, **kwargs):
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   188
        common, anyinc, heads = orig(repo, remote, *args, **kwargs)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   189
        heads = remote._reducehead(heads)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   190
        return common, anyinc, heads
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   191
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   192
    extensions.wrapfunction(discovery, 'findcommonoutgoing', filterprivateout)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   193
    extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   194
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   195
    # Write protocols
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   196
    ####################
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   197
    def heads(repo, proto):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   198
        st = laststatewithout(_NOSHARE)
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   199
        h = repo.stateheads(st)
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   200
        return wireproto.encodelist(h) + "\n"
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   201
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   202
    def _reducehead(wirerepo, heads):
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   203
        """heads filtering is done repo side"""
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   204
        return heads
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   205
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   206
    wireproto.wirerepository._reducehead = _reducehead
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   207
    wireproto.commands['heads'] = (heads, '')
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   208
17
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
   209
    templatekw.keywords['state'] = showstate
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
   210
14
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   211
def extsetup(ui):
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   212
    for state in STATES:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   213
        if state.trackheads:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   214
            revset.symbols[state.headssymbol] = state._revsetheads
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   215
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   216
def reposetup(ui, repo):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   217
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   218
    if not repo.local():
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   219
        return
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   220
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   221
    ocancopy =repo.cancopy
22
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   222
    opull = repo.pull
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   223
    opush = repo.push
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   224
    o_tag = repo._tag
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   225
    orollback = repo.rollback
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   226
    o_writejournal = repo._writejournal
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   227
    class statefulrepo(repo.__class__):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   228
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   229
        def nodestate(self, node):
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   230
            rev = self.changelog.rev(node)
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   231
            for state in STATES[::-1]:
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   232
                # XXX avoid for untracked heads
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   233
                if state.next is not None:
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   234
                    for head in self.stateheads(state):
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   235
                        revhead = self.changelog.rev(head)
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   236
                        if self.changelog.descendant(revhead, rev):
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   237
                            return state.next
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   238
            return state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   239
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   240
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   241
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   242
        def stateheads(self, state):
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   243
            # look for a relevant state
24
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   244
            while state.trackheads and state.next not in self._enabledstates:
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   245
                state = state.next
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   246
            # last state have no cached head.
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   247
            if state.trackheads:
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   248
                return self._statesheads[state]
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   249
            return self.heads()
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   250
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   251
        @util.propertycache
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   252
        def _statesheads(self):
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   253
            return self._readstatesheads()
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   254
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   255
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   256
        def _readheadsfile(self, filename):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   257
            heads = [nullid]
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   258
            try:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   259
                f = self.opener(filename)
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   260
                try:
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   261
                    heads = sorted([node.bin(n) for n in f.read().split() if n])
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   262
                finally:
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   263
                    f.close()
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   264
            except IOError:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   265
                pass
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   266
            return heads
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   267
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   268
        def _readstatesheads(self, undo=False):
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   269
            statesheads = {}
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   270
            for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   271
                if state.trackheads:
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   272
                    filemask = 'states/%s-heads'
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   273
                    filename = filemask % state.name
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   274
                    statesheads[state] = self._readheadsfile(filename)
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   275
            return statesheads
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   276
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   277
        def _writeheadsfile(self, filename, heads):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   278
            f = self.opener(filename, 'w', atomictemp=True)
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   279
            try:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   280
                for h in heads:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   281
                    f.write(hex(h) + '\n')
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   282
                f.rename()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   283
            finally:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   284
                f.close()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   285
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   286
        def _writestateshead(self):
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   287
            # transaction!
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   288
            for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   289
                if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   290
                    filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   291
                    self._writeheadsfile(filename, self._statesheads[state])
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   292
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   293
        def setstate(self, state, nodes):
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   294
            """change state of targets changeset and it's ancestors.
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   295
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   296
            Simplify the list of head."""
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   297
            assert not isinstance(nodes, basestring)
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   298
            heads = self._statesheads[state]
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   299
            olds = heads[:]
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   300
            heads.extend(nodes)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   301
            heads[:] = set(heads)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   302
            heads.sort()
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   303
            if olds != heads:
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
   304
                heads[:] = noderange(repo, ["heads(::%s())" % state.headssymbol])
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   305
                heads.sort()
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   306
            if olds != heads:
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   307
                self._writestateshead()
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
   308
            if state.next is not None and state.next.trackheads:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
   309
                self.setstate(state.next, nodes) # cascading
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   310
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   311
        def _reducehead(self, candidates):
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   312
            selected = set()
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   313
            st = laststatewithout(_NOSHARE)
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   314
            for candidate in candidates:
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   315
                rev = self.changelog.rev(candidate)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   316
                ok = True
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   317
                for h in self.stateheads(st):
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   318
                    revh = self.changelog.rev(h)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   319
                    if self.changelog.descendant(revh, rev):
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   320
                        ok = False
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   321
                        selected.add(h)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   322
                if ok:
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   323
                    selected.add(candidate)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   324
            return sorted(selected)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   325
24
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   326
        ### enable // disable logic
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   327
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   328
        @util.propertycache
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   329
        def _enabledstates(self):
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   330
            return self._readenabledstates()
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   331
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   332
        def _readenabledstates(self):
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   333
            states = set()
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   334
            mapping = dict([(st.name, st) for st in STATES])
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   335
            try:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   336
                f = self.opener('states/Enabled')
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   337
                for line in f:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   338
                    st =  mapping.get(line.strip())
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   339
                    if st is not None:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   340
                        states.add(st)
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   341
            finally:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   342
                return states
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   343
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   344
        def _writeenabledstates(self):
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   345
            f = self.opener('states/Enabled', 'w', atomictemp=True)
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   346
            try:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   347
                for st in self._enabledstates:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   348
                    f.write(st.name + '\n')
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   349
                f.rename()
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   350
            finally:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   351
                f.close()
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   352
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   353
        ### local clone support
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   354
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
   355
        def cancopy(self):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   356
            st = laststatewithout(_NOSHARE)
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   357
            return ocancopy() and (self.stateheads(st) == self.heads())
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   358
24
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   359
        ### pull // push support
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
   360
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   361
        def pull(self, remote, *args, **kwargs):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   362
            result = opull(remote, *args, **kwargs)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   363
            remoteheads = self._pullimmutableheads(remote)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   364
            #print [node.short(h) for h in remoteheads]
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   365
            self.setstate(ST0, remoteheads)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   366
            return result
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   367
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   368
        def push(self, remote, *args, **opts):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   369
            result = opush(remote, *args, **opts)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   370
            remoteheads = self._pullimmutableheads(remote)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   371
            self.setstate(ST0, remoteheads)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   372
            if remoteheads != self.stateheads(ST0):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   373
                #print 'stuff to push'
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   374
                #print 'remote', [node.short(h) for h in remoteheads]
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   375
                #print 'local',  [node.short(h) for h in self._statesheads[ST0]]
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   376
                self._pushimmutableheads(remote, remoteheads)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   377
            return result
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   378
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   379
        def _pushimmutableheads(self, remote, remoteheads):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   380
            missing = set(self.stateheads(ST0)) - set(remoteheads)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   381
            for h in missing:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   382
                #print 'missing', node.short(h)
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   383
                remote.pushkey('immutableheads', node.hex(h), '', '1')
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   384
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   385
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   386
        def _pullimmutableheads(self, remote):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   387
            self.ui.debug('checking for immutableheadshg on server')
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   388
            if 'immutableheads' not in remote.listkeys('namespaces'):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   389
                self.ui.debug('immutableheads not enabled on the remote server, '
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   390
                              'marking everything as frozen')
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   391
                remote = remote.heads()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   392
            else:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   393
                self.ui.debug('server has immutableheads enabled, merging lists')
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   394
                remote = map(node.bin, remote.listkeys('immutableheads'))
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   395
            return remote
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
   396
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   397
        ### Tag support
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   398
22
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   399
        def _tag(self, names, node, *args, **kwargs):
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   400
            tagnode = o_tag(names, node, *args, **kwargs)
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   401
            self.setstate(ST0, [node, tagnode])
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   402
            return tagnode
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
   403
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   404
        ### rollback support
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   405
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   406
        def _writejournal(self, desc):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   407
            entries = list(o_writejournal(desc))
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   408
            for state in STATES:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   409
                if state.trackheads:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   410
                    filename = 'states/%s-heads' % state.name
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   411
                    filepath = self.join(filename)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   412
                    if  os.path.exists(filepath):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   413
                        journalname = 'states/journal.%s-heads' % state.name
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   414
                        journalpath = self.join(journalname)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   415
                        util.copyfile(filepath, journalpath)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   416
                        entries.append(journalpath)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   417
            return tuple(entries)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   418
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   419
        def rollback(self, dryrun=False):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   420
            wlock = lock = None
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   421
            try:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   422
                wlock = self.wlock()
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   423
                lock = self.lock()
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   424
                ret = orollback(dryrun)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   425
                if not (ret or dryrun): #rollback did not failed
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   426
                    for state in STATES:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   427
                        if state.trackheads:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   428
                            src  = self.join('states/undo.%s-heads') % state.name
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   429
                            dest = self.join('states/%s-heads') % state.name
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   430
                            if os.path.exists(src):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   431
                                util.rename(src, dest)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   432
                            elif os.path.exists(dest): #unlink in any case
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   433
                                os.unlink(dest)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   434
                    self.__dict__.pop('_statesheads', None)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   435
                return ret
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   436
            finally:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   437
                release(lock, wlock)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
   438
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   439
    repo.__class__ = statefulrepo
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
   440