annotate hgext/states.py @ 55:cf4626a13345

Update pushkey code to be able to push ready heads too.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 08 Sep 2011 19:03:42 +0200
parents ad1a4fb0fc49
children 62f2fe22bd42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
54
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
36 from mercurial import error
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
37 from mercurial.lock import release
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
38
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
39
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
40 _NOSHARE=2
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
41 _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
42
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
43 class state(object):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
44
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
45 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
46 self.name = name
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
47 self.properties = properties
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
48 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
49 self.next = next
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
50
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
51 def __repr__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
52 return 'state(%s)' % self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
53
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
54 def __str__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
55 return self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
56
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
57 @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
58 def trackheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
59 """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
60
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
61 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
62 return self.next is not None
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
63
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
64 def __cmp__(self, other):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
65 return cmp(self.properties, other.properties)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
66
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
67 @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
68 def _revsetheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
69 """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
70 assert self.trackheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
71 def revsetheads(repo, subset, x):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
72 args = revset.getargs(x, 0, 0, 'publicheads takes no arguments')
54
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
73 heads = []
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
74 for h in repo._statesheads[self]:
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
75 try:
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
76 heads.append(repo.changelog.rev(h))
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
77 except error.LookupError:
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
78 pass
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
79 heads.sort()
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 return revsetheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
82
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
83 @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
84 def headssymbol(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
85 """name of the revset symbols"""
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
86 if self.trackheads:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
87 return "%sheads" % self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
88 else:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
89 return 'heads'
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
90
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
91 ST2 = state('draft', _NOSHARE | _MUTABLE)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
92 ST1 = state('ready', _MUTABLE, next=ST2)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
93 ST0 = state('published', next=ST1)
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
94
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
95 STATES = (ST0, ST1, ST2)
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
96 STATESMAP =dict([(st.name, st) for st in STATES])
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
97
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
98 @util.cachefunc
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
99 def laststatewithout(prop):
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
100 for state in STATES:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
101 if not state.properties & prop:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
102 candidate = state
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
103 else:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
104 return candidate
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
105
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
106 # 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
107 #############################
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
108 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
109 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
110 scmutil.revrange(repo, revsets))
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
111
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
112 # Patch changectx
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
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
115 def state(ctx):
27
31906bc290ff Working directory is draft.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 26
diff changeset
116 if ctx.node()is None:
31906bc290ff Working directory is draft.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 26
diff changeset
117 return STATES[-1]
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
118 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
119 context.changectx.state = state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
120
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
121 # improve template
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
122 #############################
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
123
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
124 def showstate(ctx, **args):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
125 return ctx.state()
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
126
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
127
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
128 # 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
129 #############################
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
130
26
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
131
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
132 def cmdstates(ui, repo, *states, **opt):
33
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
133 """view and modify activated states.
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
134
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
135 With no argument, list activated state.
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
136
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
137 With argument, activate the state in argument.
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
138
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
139 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
140
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
141 note: published state are alway activated."""
dca86448d736 Add some doc.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 31
diff changeset
142
26
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
143 if not states:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
144 for st in sorted(repo._enabledstates):
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
145 ui.write('%s\n' % st)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
146 else:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
147 off = opt.get('off', False)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
148 for state_name in states:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
149 for st in STATES:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
150 if st.name == state_name:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
151 break
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
152 else:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
153 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
154 return 1
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
155 if off and st in repo._enabledstates:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
156 repo._enabledstates.remove(st)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
157 else:
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
158 repo._enabledstates.add(st)
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
159 repo._writeenabledstates()
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
160 return 0
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
161
c9da15600775 add a states command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 25
diff changeset
162 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
163 #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
164
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
165 def makecmd(state):
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
166 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
167 """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
168 revs = scmutil.revrange(repo, changesets)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
169 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
170 return 0
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
171 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
172
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
173 for state in STATES:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
174 if state.trackheads:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
175 cmdmoveheads = makecmd(state)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
176 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
177
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
178 # 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
179 #########################################
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
180
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
181 def pushstatesheads(repo, key, old, new):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
182 st = STATESMAP[new]
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
183 w = repo.wlock()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
184 try:
54
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
185 newhead = node.bin(key)
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
186 repo[newhead]
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
187 repo.setstate(st, [newhead])
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
188 finally:
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
189 w.release()
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
190
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
191 def liststatesheads(repo):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
192 keys = {}
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
193 for state in [st for st in STATES if st.trackheads]:
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
194 for head in repo.stateheads(state):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
195 head = node.hex(head)
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
196 if head in keys:
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
197 keys[head] += ',' + state.name
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
198 else:
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
199 keys[head] = state.name
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
200 return keys
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
201
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
202 pushkey.register('states-heads', pushstatesheads, liststatesheads)
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
203
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
204
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
205
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
206
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
207
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
208 def uisetup(ui):
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
209 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
210 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
211 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
212 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
213 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
214 heads = remote._reducehead(heads)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
215 return common, anyinc, heads
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
216
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
217 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
218 extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
219
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
220 # Write protocols
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
221 ####################
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
222 def heads(repo, proto):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
223 st = laststatewithout(_NOSHARE)
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
224 h = repo.stateheads(st)
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
225 return wireproto.encodelist(h) + "\n"
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
226
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
227 def _reducehead(wirerepo, heads):
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
228 """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
229 return heads
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
230
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
231 wireproto.wirerepository._reducehead = _reducehead
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
232 wireproto.commands['heads'] = (heads, '')
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
233
17
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
234 templatekw.keywords['state'] = showstate
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
235
14
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
236 def extsetup(ui):
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
237 for state in STATES:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
238 if state.trackheads:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
239 revset.symbols[state.headssymbol] = state._revsetheads
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
240
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
241 def reposetup(ui, repo):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
242
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
243 if not repo.local():
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
244 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
245
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
246 ocancopy =repo.cancopy
22
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
247 opull = repo.pull
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
248 opush = repo.push
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
249 o_tag = repo._tag
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
250 orollback = repo.rollback
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
251 o_writejournal = repo._writejournal
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
252 class statefulrepo(repo.__class__):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
253
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
254 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
255 rev = self.changelog.rev(node)
30
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
256
29
52c227772dad fix nodestate computation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 28
diff changeset
257 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
258 # 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
259 if state.next is not None:
30
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
260 ancestors = map(self.changelog.rev, self.stateheads(state))
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
261 ancestors.extend(self.changelog.ancestors(*ancestors))
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
262 if rev in ancestors:
29
52c227772dad fix nodestate computation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 28
diff changeset
263 break
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
264 return state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
265
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
266
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
267
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
268 def stateheads(self, state):
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
269 # 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
270 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
271 state = state.next
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
272 # 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
273 if state.trackheads:
20
9983f240ac63 Smarter states heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 19
diff changeset
274 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
275 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
276
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
277 @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
278 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
279 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
280
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
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
282 def _readheadsfile(self, filename):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
283 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
284 try:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
285 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
286 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
287 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
288 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
289 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
290 except IOError:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
291 pass
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
292 return heads
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
293
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
294 def _readstatesheads(self, undo=False):
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
295 statesheads = {}
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
296 for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
297 if state.trackheads:
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
298 filemask = 'states/%s-heads'
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
299 filename = filemask % state.name
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
300 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
301 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
302
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
303 def _writeheadsfile(self, filename, heads):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
304 f = self.opener(filename, 'w', atomictemp=True)
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
305 try:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
306 for h in heads:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
307 f.write(hex(h) + '\n')
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
308 f.rename()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
309 finally:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
310 f.close()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
311
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
312 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
313 # transaction!
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
314 for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
315 if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
316 filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
317 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
318
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
319 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
320 """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
321
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 Simplify the list of head."""
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
323 assert not isinstance(nodes, basestring), repr(nodes)
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
324 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
325 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
326 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
327 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
328 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
329 if olds != heads:
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
330 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
331 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
332 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
333 self._writestateshead()
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
334 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
335 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
336
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
337 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
338 selected = set()
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
339 st = laststatewithout(_NOSHARE)
30
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
340 candidates = set(map(self.changelog.rev, candidates))
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
341 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
342 shareable = set(self.changelog.ancestors(*heads))
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
343 shareable.update(heads)
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
344 selected = candidates & shareable
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
345 unselected = candidates - shareable
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
346 for rev in unselected:
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
347 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
348 if self.changelog.descendant(revh, rev):
30
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
349 selected.add(revh)
a2189159e92f fix outgoing filtering.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 29
diff changeset
350 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
351
24
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
352 ### 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
353
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
354 @util.propertycache
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
355 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
356 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
357
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
358 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
359 states = set()
28
0918e3b54f0b published is always enabled.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 27
diff changeset
360 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
361 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
362 try:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
363 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
364 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
365 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
366 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
367 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
368 finally:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
369 return states
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
370
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
371 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
372 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
373 try:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
374 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
375 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
376 f.rename()
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
377 finally:
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
378 f.close()
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
379
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
380 ### 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
381
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
382 def cancopy(self):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
383 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
384 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
385
24
20ac7fa3fd29 Move state activitation in a dedicated file repo-side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 23
diff changeset
386 ### 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
387
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
388 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
389 result = opull(remote, *args, **kwargs)
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
390 remoteheads = self._pullstatesheads(remote)
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
391 #print [node.short(h) for h in remoteheads]
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
392 for st, heads in remoteheads.iteritems():
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
393 self.setstate(st, heads)
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
394 return result
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 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
397 result = opush(remote, *args, **opts)
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
398 remoteheads = self._pullstatesheads(remote)
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
399 for st, heads in remoteheads.iteritems():
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
400 self.setstate(st, heads)
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
401 if heads != self.stateheads(st):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
402 self._pushstatesheads(remote, st, heads)
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
403 return result
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
404
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
405 def _pushstatesheads(self, remote, state, remoteheads):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
406 local = set(self.stateheads(state))
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
407 missing = local - set(remoteheads)
54
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
408 while missing:
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
409 h = missing.pop()
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
410 try:
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
411 remote.pushkey('states-heads', node.hex(h), '', state.name)
54
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
412 except error.RepoLookupError:
ad1a4fb0fc49 Make states more resilient to missing head
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 51
diff changeset
413 missing.update(p.node() for p in repo[h].parents())
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
414
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
415
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
416 def _pullstatesheads(self, remote):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
417 remoteheads = {}
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
418 self.ui.debug('checking for states-heads on remote server')
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
419 if 'states-heads' not in remote.listkeys('namespaces'):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
420 self.ui.debug('states-heads not enabled on the remote server, '
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
421 'marking everything as published')
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
422 remoteheads[ST0] = remote.heads()
21
aa0870d093b8 Add pull and push support for relevant heads.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20
diff changeset
423 else:
55
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
424 self.ui.debug('server has states-heads enabled, merging lists')
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
425 for hex, statenames in remote.listkeys('states-heads').iteritems():
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
426 for stn in statenames.split(','):
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
427 remoteheads.setdefault(STATESMAP[stn], []).append(node.bin(hex))
cf4626a13345 Update pushkey code to be able to push ready heads too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 54
diff changeset
428 return remoteheads
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
429
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
430 ### Tag support
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
431
22
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
432 def _tag(self, names, node, *args, **kwargs):
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
433 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
434 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
435 self.setstate(ST0, [node, tagnode])
22
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
436 return tagnode
93dd72d028a1 Automatically publish on tag.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 21
diff changeset
437
23
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
438 ### rollback support
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
439
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
440 def _writejournal(self, desc):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
441 entries = list(o_writejournal(desc))
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
442 for state in STATES:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
443 if state.trackheads:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
444 filename = 'states/%s-heads' % state.name
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
445 filepath = self.join(filename)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
446 if os.path.exists(filepath):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
447 journalname = 'states/journal.%s-heads' % state.name
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
448 journalpath = self.join(journalname)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
449 util.copyfile(filepath, journalpath)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
450 entries.append(journalpath)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
451 return tuple(entries)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
452
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
453 def rollback(self, dryrun=False):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
454 wlock = lock = None
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
455 try:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
456 wlock = self.wlock()
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
457 lock = self.lock()
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
458 ret = orollback(dryrun)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
459 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
460 for state in STATES:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
461 if state.trackheads:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
462 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
463 dest = self.join('states/%s-heads') % state.name
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
464 if os.path.exists(src):
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
465 util.rename(src, dest)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
466 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
467 os.unlink(dest)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
468 self.__dict__.pop('_statesheads', None)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
469 return ret
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
470 finally:
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
471 release(lock, wlock)
423c62a146c7 add rollback support.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 22
diff changeset
472
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
473 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
474