author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Mon, 01 Aug 2011 14:28:38 +0200 | |
changeset 34 | f28116682827 |
parent 33 | dca86448d736 |
permissions | -rw-r--r-- |
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): |
33
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
126 |
"""view and modify activated states. |
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
127 |
|
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
128 |
With no argument, list activated state. |
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
129 |
|
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
130 |
With argument, activate the state in argument. |
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
131 |
|
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
132 |
With argument plus the --off switch, deactivate the state in argument. |
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
133 |
|
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
134 |
note: published state are alway activated.""" |
dca86448d736
Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
31
diff
changeset
|
135 |
|
26
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
136 |
if not states: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
137 |
for st in sorted(repo._enabledstates): |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
138 |
ui.write('%s\n' % st) |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
139 |
else: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
140 |
off = opt.get('off', False) |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
141 |
for state_name in states: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
142 |
for st in STATES: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
143 |
if st.name == state_name: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
144 |
break |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
145 |
else: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
146 |
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
|
147 |
return 1 |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
148 |
if off and st in repo._enabledstates: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
149 |
repo._enabledstates.remove(st) |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
150 |
else: |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
151 |
repo._enabledstates.add(st) |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
152 |
repo._writeenabledstates() |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
153 |
return 0 |
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
154 |
|
c9da15600775
add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
25
diff
changeset
|
155 |
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
|
156 |
#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
|
157 |
|
18
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
158 |
def makecmd(state): |
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
159 |
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
|
160 |
"""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
|
161 |
revs = scmutil.revrange(repo, changesets) |
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
162 |
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
|
163 |
return 0 |
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
164 |
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
|
165 |
|
18
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
166 |
for state in STATES: |
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
167 |
if state.trackheads: |
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
168 |
cmdmoveheads = makecmd(state) |
9ffe946febc0
Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17
diff
changeset
|
169 |
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
|
170 |
|
21
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
171 |
# 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
|
172 |
######################################### |
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
|
173 |
|
21
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
174 |
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
|
175 |
st = ST0 |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
176 |
w = repo.wlock() |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
177 |
try: |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
178 |
#print 'pushing', key |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
179 |
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
|
180 |
finally: |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
181 |
w.release() |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
182 |
|
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
183 |
def listimmutableheads(repo): |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
184 |
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
|
185 |
|
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
186 |
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
|
187 |
|
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
|
188 |
|
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
|
189 |
|
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
|
190 |
|
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
|
191 |
|
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
|
192 |
def uisetup(ui): |
2
166694e62daf
hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
heads = remote._reducehead(heads) |
166694e62daf
hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1
diff
changeset
|
199 |
return common, anyinc, heads |
166694e62daf
hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1
diff
changeset
|
200 |
|
166694e62daf
hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1
diff
changeset
|
201 |
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
|
202 |
extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein) |
0
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
203 |
|
7
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
204 |
# Write protocols |
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 |
def heads(repo, proto): |
19
8784a989a572
introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18
diff
changeset
|
207 |
st = laststatewithout(_NOSHARE) |
8784a989a572
introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18
diff
changeset
|
208 |
h = repo.stateheads(st) |
7
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
209 |
return wireproto.encodelist(h) + "\n" |
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
210 |
|
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
211 |
def _reducehead(wirerepo, heads): |
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
212 |
"""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
|
213 |
return heads |
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
214 |
|
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
215 |
wireproto.wirerepository._reducehead = _reducehead |
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
216 |
wireproto.commands['heads'] = (heads, '') |
cc592295900f
Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5
diff
changeset
|
217 |
|
17
6aa349f47e7c
add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
16
diff
changeset
|
218 |
templatekw.keywords['state'] = showstate |
6aa349f47e7c
add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
16
diff
changeset
|
219 |
|
14
f5e1055a3f68
reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
13
diff
changeset
|
220 |
def extsetup(ui): |
f5e1055a3f68
reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
13
diff
changeset
|
221 |
for state in STATES: |
f5e1055a3f68
reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
13
diff
changeset
|
222 |
if state.trackheads: |
f5e1055a3f68
reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
13
diff
changeset
|
223 |
revset.symbols[state.headssymbol] = state._revsetheads |
f5e1055a3f68
reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
13
diff
changeset
|
224 |
|
0
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
225 |
def reposetup(ui, repo): |
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
226 |
|
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
227 |
if not repo.local(): |
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
228 |
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
|
229 |
|
21
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
230 |
ocancopy =repo.cancopy |
22
93dd72d028a1
Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
21
diff
changeset
|
231 |
opull = repo.pull |
93dd72d028a1
Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
21
diff
changeset
|
232 |
opush = repo.push |
93dd72d028a1
Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
21
diff
changeset
|
233 |
o_tag = repo._tag |
23
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
234 |
orollback = repo.rollback |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
235 |
o_writejournal = repo._writejournal |
0
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
236 |
class statefulrepo(repo.__class__): |
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
237 |
|
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
238 |
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
|
239 |
rev = self.changelog.rev(node) |
30
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
240 |
|
29
52c227772dad
fix nodestate computation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
28
diff
changeset
|
241 |
for state in STATES: |
13
e95e8cf7988f
Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
12
diff
changeset
|
242 |
# 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
|
243 |
if state.next is not None: |
30
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
244 |
ancestors = map(self.changelog.rev, self.stateheads(state)) |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
245 |
ancestors.extend(self.changelog.ancestors(*ancestors)) |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
246 |
if rev in ancestors: |
29
52c227772dad
fix nodestate computation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
28
diff
changeset
|
247 |
break |
13
e95e8cf7988f
Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
12
diff
changeset
|
248 |
return state |
0
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
249 |
|
12
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
250 |
|
9
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
251 |
|
13
e95e8cf7988f
Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
12
diff
changeset
|
252 |
def stateheads(self, state): |
20
9983f240ac63
Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19
diff
changeset
|
253 |
# 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
|
254 |
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
|
255 |
state = state.next |
9983f240ac63
Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19
diff
changeset
|
256 |
# 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
|
257 |
if state.trackheads: |
20
9983f240ac63
Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
19
diff
changeset
|
258 |
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
|
259 |
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
|
260 |
|
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 |
@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
|
262 |
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
|
263 |
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
|
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 |
|
9
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
266 |
def _readheadsfile(self, filename): |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
267 |
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
|
268 |
try: |
9
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
except IOError: |
9
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
275 |
pass |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
276 |
return heads |
23
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
277 |
|
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
278 |
def _readstatesheads(self, undo=False): |
9
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
279 |
statesheads = {} |
12
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
280 |
for state in STATES: |
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
281 |
if state.trackheads: |
23
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
282 |
filemask = 'states/%s-heads' |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
283 |
filename = filemask % state.name |
12
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
|
9
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
287 |
def _writeheadsfile(self, filename, heads): |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
288 |
f = self.opener(filename, 'w', atomictemp=True) |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
289 |
try: |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
290 |
for h in heads: |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
291 |
f.write(hex(h) + '\n') |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
292 |
f.rename() |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
293 |
finally: |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
294 |
f.close() |
1f84a74df837
introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7
diff
changeset
|
295 |
|
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
|
296 |
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
|
297 |
# transaction! |
12
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
298 |
for state in STATES: |
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
299 |
if state.trackheads: |
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
300 |
filename = 'states/%s-heads' % state.name |
6312fc525a54
rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
11
diff
changeset
|
301 |
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
|
302 |
|
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 |
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
|
304 |
"""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
|
305 |
|
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 |
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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
if olds != heads: |
10
91169d2d7f1b
state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
9
diff
changeset
|
314 |
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
|
315 |
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
|
316 |
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
|
317 |
self._writestateshead() |
10
91169d2d7f1b
state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
9
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
|
2
166694e62daf
hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1
diff
changeset
|
321 |
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
|
322 |
selected = set() |
19
8784a989a572
introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18
diff
changeset
|
323 |
st = laststatewithout(_NOSHARE) |
30
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
324 |
candidates = set(map(self.changelog.rev, candidates)) |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
325 |
heads = set(map(self.changelog.rev, self.stateheads(st))) |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
326 |
shareable = set(self.changelog.ancestors(*heads)) |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
327 |
shareable.update(heads) |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
328 |
selected = candidates & shareable |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
329 |
unselected = candidates - shareable |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
330 |
for rev in unselected: |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
331 |
for revh in heads: |
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
|
332 |
if self.changelog.descendant(revh, rev): |
30
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
333 |
selected.add(revh) |
a2189159e92f
fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
29
diff
changeset
|
334 |
return sorted(map(self.changelog.node, selected)) |
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
|
335 |
|
24
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
336 |
### 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
|
337 |
|
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
338 |
@util.propertycache |
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
339 |
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
|
340 |
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
|
341 |
|
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
342 |
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
|
343 |
states = set() |
28
0918e3b54f0b
published is always enabled.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
27
diff
changeset
|
344 |
states.add(ST0) |
24
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
345 |
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
|
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 |
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
|
348 |
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
|
349 |
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
|
350 |
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
|
351 |
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
|
352 |
finally: |
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
353 |
return states |
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
354 |
|
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
try: |
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
f.rename() |
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
361 |
finally: |
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
362 |
f.close() |
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
363 |
|
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
364 |
### 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
|
365 |
|
5 | 366 |
def cancopy(self): |
19
8784a989a572
introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18
diff
changeset
|
367 |
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
|
368 |
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
|
369 |
|
24
20ac7fa3fd29
Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
23
diff
changeset
|
370 |
### 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
|
371 |
|
21
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
#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
|
376 |
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
|
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 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
|
380 |
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
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
#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
|
385 |
#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
|
386 |
#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
|
387 |
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
|
388 |
return result |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
389 |
|
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
390 |
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
|
391 |
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
|
392 |
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
|
393 |
#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
|
394 |
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
|
395 |
|
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
396 |
|
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
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
|
401 |
'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
|
402 |
remote = remote.heads() |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
403 |
else: |
aa0870d093b8
Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20
diff
changeset
|
404 |
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
|
405 |
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
|
406 |
return remote |
5 | 407 |
|
23
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
408 |
### Tag support |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
409 |
|
22
93dd72d028a1
Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
21
diff
changeset
|
410 |
def _tag(self, names, node, *args, **kwargs): |
93dd72d028a1
Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
21
diff
changeset
|
411 |
tagnode = o_tag(names, node, *args, **kwargs) |
31
1fef89f56588
tag: do not publish for local tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
30
diff
changeset
|
412 |
if tagnode is not None: # do nothing for local one |
1fef89f56588
tag: do not publish for local tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
30
diff
changeset
|
413 |
self.setstate(ST0, [node, tagnode]) |
22
93dd72d028a1
Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
21
diff
changeset
|
414 |
return tagnode |
93dd72d028a1
Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
21
diff
changeset
|
415 |
|
23
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
416 |
### rollback support |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
417 |
|
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
418 |
def _writejournal(self, desc): |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
419 |
entries = list(o_writejournal(desc)) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
420 |
for state in STATES: |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
421 |
if state.trackheads: |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
422 |
filename = 'states/%s-heads' % state.name |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
423 |
filepath = self.join(filename) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
424 |
if os.path.exists(filepath): |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
425 |
journalname = 'states/journal.%s-heads' % state.name |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
426 |
journalpath = self.join(journalname) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
427 |
util.copyfile(filepath, journalpath) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
428 |
entries.append(journalpath) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
429 |
return tuple(entries) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
430 |
|
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
431 |
def rollback(self, dryrun=False): |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
432 |
wlock = lock = None |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
433 |
try: |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
434 |
wlock = self.wlock() |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
435 |
lock = self.lock() |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
436 |
ret = orollback(dryrun) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
437 |
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
|
438 |
for state in STATES: |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
439 |
if state.trackheads: |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
440 |
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
|
441 |
dest = self.join('states/%s-heads') % state.name |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
442 |
if os.path.exists(src): |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
443 |
util.rename(src, dest) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
444 |
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
|
445 |
os.unlink(dest) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
446 |
self.__dict__.pop('_statesheads', None) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
447 |
return ret |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
448 |
finally: |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
449 |
release(lock, wlock) |
423c62a146c7
add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
22
diff
changeset
|
450 |
|
0
bbeef801409c
minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
451 |
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
|
452 |