states.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 06 Jun 2011 16:42:56 +0200
changeset 21 aa0870d093b8
parent 20 9983f240ac63
child 22 93dd72d028a1
permissions -rw-r--r--
Add pull and push support for relevant heads. This use pushkey.
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
'''
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
    20
from functools import partial
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 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
    22
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
    23
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
    24
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
    25
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
    26
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
    27
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
    28
from mercurial import node
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
    29
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
    30
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
    31
from mercurial import extensions
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
    32
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
    33
from mercurial import pushkey
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    34
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    35
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    36
_NOSHARE=2
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
    37
_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
    38
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    39
class state(object):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    40
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    41
    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
    42
        self.name = name
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    43
        self.properties = properties
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    44
        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
    45
        self.next = next
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    46
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    47
    def __repr__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    48
        return 'state(%s)' % self.name
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 __str__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    51
        return 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
    @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    54
    def trackheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    55
        """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
    56
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    57
        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
    58
        return self.next is not None
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    59
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    60
    def __cmp__(self, other):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    61
        return cmp(self.properties, other.properties)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    62
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    63
    @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    64
    def _revsetheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    65
        """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
    66
        assert self.trackheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    67
        def revsetheads(repo, subset, x):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    68
            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
    69
            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
    70
            heads.sort()
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    71
            return heads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    72
        return revsetheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    73
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    74
    @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    75
    def headssymbol(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
    76
        """name of the revset symbols"""
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    77
        if self.trackheads:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    78
            return "%sheads" % self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    79
        else:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    80
            return 'heads'
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    81
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
    82
    def enabled(self, ui):
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
    83
        return ui.configbool('states', self.name, False)
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
    84
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
    85
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    86
ST2 = state('draft', _NOSHARE | _MUTABLE)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    87
ST1 = state('ready', _MUTABLE, next=ST2)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    88
ST0 = state('published', next=ST1)
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
    89
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
    90
STATES = (ST0, ST1, ST2)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    91
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
    92
@util.cachefunc
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    93
def laststatewithout(prop):
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    94
    for state in STATES:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    95
        if not state.properties & prop:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    96
            candidate = state
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    97
        else:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    98
            return candidate
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
    99
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
   100
# 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
   101
#############################
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
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
   103
    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
   104
               scmutil.revrange(repo, revsets))
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   105
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   106
# Patch changectx
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
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   109
def state(ctx):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   110
    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
   111
context.changectx.state = state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   112
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   113
# improve template
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   114
#############################
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
def showstate(ctx, **args):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   117
    return ctx.state()
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   118
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
   119
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
# 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
   121
#############################
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
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   123
cmdtable = {}
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
   124
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   125
def makecmd(state):
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   126
    def cmdmoveheads(ui, repo, *changesets):
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   127
        revs = scmutil.revrange(repo, changesets)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   128
        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
   129
        return 0
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   130
    return cmdmoveheads
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   131
for state in STATES:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   132
    if state.trackheads:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   133
        cmdmoveheads = makecmd(state)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
   134
        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
   135
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   136
# 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
   137
#########################################
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
   138
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   139
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
   140
    st = ST0
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   141
    w = repo.wlock()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   142
    try:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   143
        #print 'pushing', key
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   144
        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
   145
    finally:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   146
        w.release()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   147
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   148
def listimmutableheads(repo):
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   149
    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
   150
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   151
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
   152
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
   153
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
   154
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
   155
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
   156
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
   157
def uisetup(ui):
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   158
    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
   159
        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
   160
        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
   161
    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
   162
        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
   163
        heads = remote._reducehead(heads)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   164
        return common, anyinc, heads
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   165
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   166
    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
   167
    extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   168
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   169
    # Write protocols
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   170
    ####################
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   171
    def heads(repo, proto):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   172
        st = laststatewithout(_NOSHARE)
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   173
        h = repo.stateheads(st)
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   174
        return wireproto.encodelist(h) + "\n"
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   175
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   176
    def _reducehead(wirerepo, heads):
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   177
        """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
   178
        return heads
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   179
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   180
    wireproto.wirerepository._reducehead = _reducehead
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   181
    wireproto.commands['heads'] = (heads, '')
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
   182
17
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
   183
    templatekw.keywords['state'] = showstate
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
   184
14
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   185
def extsetup(ui):
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   186
    for state in STATES:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   187
        if state.trackheads:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   188
            revset.symbols[state.headssymbol] = state._revsetheads
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
   189
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   190
def reposetup(ui, repo):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   191
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   192
    if not repo.local():
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   193
        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
   194
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   195
    ocancopy =repo.cancopy
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   196
    opull =repo.pull
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   197
    opush =repo.push
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   198
    class statefulrepo(repo.__class__):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   199
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   200
        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
   201
            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
   202
            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
   203
                # 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
   204
                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
   205
                    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
   206
                        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
   207
                        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
   208
                            return state.next
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   209
            return state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   210
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   211
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   212
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
   213
        def stateheads(self, state):
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   214
            # look for a relevant state
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   215
            while state.trackheads and not state.next.enabled(self.ui):
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   216
                state = state.next
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   217
            # 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
   218
            if state.trackheads:
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
   219
                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
   220
            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
   221
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
   222
        @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
   223
        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
   224
            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
   225
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
   226
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   227
        def _readheadsfile(self, filename):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   228
            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
   229
            try:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   230
                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
   231
                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
   232
                    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
   233
                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
   234
                    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
   235
            except IOError:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   236
                pass
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   237
            return heads
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   238
        def _readstatesheads(self):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   239
            statesheads = {}
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   240
            for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   241
                if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   242
                    filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   243
                    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
   244
            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
   245
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   246
        def _writeheadsfile(self, filename, heads):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   247
            f = self.opener(filename, 'w', atomictemp=True)
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   248
            try:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   249
                for h in heads:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   250
                    f.write(hex(h) + '\n')
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   251
                f.rename()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   252
            finally:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   253
                f.close()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
   254
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
   255
        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
   256
            # transaction!
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   257
            for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   258
                if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   259
                    filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
   260
                    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
   261
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
        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
   263
            """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
   264
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
   265
            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
   266
            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
   267
            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
   268
            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
   269
            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
   270
            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
   271
            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
   272
            if olds != heads:
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
   273
                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
   274
                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
   275
            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
   276
                self._writestateshead()
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
   277
            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
   278
                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
   279
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
   280
        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
   281
            selected = set()
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   282
            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
   283
            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
   284
                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
   285
                ok = True
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   286
                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
   287
                    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
   288
                    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
   289
                        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
   290
                        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
   291
                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
   292
                    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
   293
            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
   294
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
   295
        def cancopy(self):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
   296
            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
   297
            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
   298
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   299
        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
   300
            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
   301
            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
   302
            #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
   303
            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
   304
            return result
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   305
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   306
        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
   307
            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
   308
            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
   309
            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
   310
            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
   311
                #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
   312
                #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
   313
                #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
   314
                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
   315
            return result
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   316
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   317
        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
   318
            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
   319
            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
   320
                #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
   321
                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
   322
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   323
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   324
        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
   325
            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
   326
            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
   327
                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
   328
                              '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
   329
                remote = remote.heads()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   330
            else:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
   331
                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
   332
                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
   333
            return remote
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
   334
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   335
    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
   336