annotate states.py @ 19:8784a989a572

introduce a ``laststatewithout`` method We use it to remove explicite reference to state in to module code. This allow more flexible dev for now.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Mon, 06 Jun 2011 15:30:43 +0200
parents 9ffe946febc0
children 9983f240ac63
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 '''
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
20 from functools import partial
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
21 from mercurial.i18n import _
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
22 from mercurial import cmdutil
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
23 from mercurial import scmutil
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
24 from mercurial import context
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
25 from mercurial import revset
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
26 from mercurial import templatekw
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
27 from mercurial import util
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
28 from mercurial import node
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
29 from mercurial.node import nullid, hex, short
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
30 from mercurial import discovery
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
31 from mercurial import extensions
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
32 from mercurial import wireproto
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
33
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
34
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
35 _NOSHARE=2
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
36 _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
37
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
38 class state(object):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
39
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
40 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
41 self.name = name
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
42 self.properties = properties
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
43 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
44 self.next = next
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
45
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
46 def __repr__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
47 return 'state(%s)' % self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
48
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
49 def __str__(self):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
50 return self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
51
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
52 @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
53 def trackheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
54 """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
55
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
56 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
57 return self.next is not None
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
58
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
59 def __cmp__(self, other):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
60 return cmp(self.properties, other.properties)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
61
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
62 @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
63 def _revsetheads(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
64 """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
65 assert self.trackheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
66 def revsetheads(repo, subset, x):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
67 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
68 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
69 heads.sort()
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
70 return heads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
71 return revsetheads
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
72
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
73 @util.propertycache
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
74 def headssymbol(self):
11
47ba990eff0e update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 10
diff changeset
75 """name of the revset symbols"""
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
76 if self.trackheads:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
77 return "%sheads" % self.name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
78 else:
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
79 return 'heads'
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
80
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
81 ST2 = state('draft', _NOSHARE | _MUTABLE)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
82 ST1 = state('ready', _MUTABLE, next=ST2)
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
83 ST0 = state('published', next=ST1)
10
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 STATES = (ST0, ST1, ST2)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
86
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
87 def laststatewithout(prop):
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
88 for state in STATES:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
89 if not state.properties & prop:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
90 candidate = state
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
91 else:
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
92 return candidate
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
93
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
94 # 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
95 #############################
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
96 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
97 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
98 scmutil.revrange(repo, revsets))
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
99
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
100 # Patch changectx
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
101 #############################
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
102
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
103 def state(ctx):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
104 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
105 context.changectx.state = state
0
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 # improve template
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
108 #############################
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
109
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
110 def showstate(ctx, **args):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
111 return ctx.state()
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
112
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
113
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
114 # 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
115 #############################
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
116
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
117 cmdtable = {}
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
118
18
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
119 def makecmd(state):
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
120 def cmdmoveheads(ui, repo, *changesets):
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
121 revs = scmutil.revrange(repo, changesets)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
122 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
123 return 0
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
124 return cmdmoveheads
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
125 for state in STATES:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
126 if state.trackheads:
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
127 cmdmoveheads = makecmd(state)
9ffe946febc0 Autogenerate command table.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17
diff changeset
128 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
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
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
131
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
132
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
133
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
134
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
135
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
136 def uisetup(ui):
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
137 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
138 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
139 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
140 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
141 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
142 heads = remote._reducehead(heads)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
143 return common, anyinc, heads
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
144
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
145 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
146 extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
147
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
148 # Write protocols
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
149 ####################
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
150 def heads(repo, proto):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
151 st = laststatewithout(_NOSHARE)
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
152 h = repo.stateheads(st)
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
153 return wireproto.encodelist(h) + "\n"
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
154
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
155 def _reducehead(wirerepo, heads):
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
156 """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
157 return heads
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
158
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
159 wireproto.wirerepository._reducehead = _reducehead
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
160 wireproto.commands['heads'] = (heads, '')
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
161
17
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
162 templatekw.keywords['state'] = showstate
6aa349f47e7c add templatekeyword in a proper location
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 16
diff changeset
163
14
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
164 def extsetup(ui):
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
165 for state in STATES:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
166 if state.trackheads:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
167 revset.symbols[state.headssymbol] = state._revsetheads
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
168
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
169 def reposetup(ui, repo):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
170
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
171 if not repo.local():
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
172 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
173
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
174 o_cancopy =repo.cancopy
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
175 class statefulrepo(repo.__class__):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
176
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
177 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
178 rev = self.changelog.rev(node)
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
179 for state in STATES[::-1]:
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
180 # 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
181 if state.next is not None:
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
182 for head in self.stateheads(state):
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
183 revhead = self.changelog.rev(head)
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
184 if self.changelog.descendant(revhead, rev):
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
185 return state.next
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
186 return state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
187
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
188
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
189
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
190 def stateheads(self, state):
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
191 if state.trackheads:
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
192 if self.ui.configbool('states', state.next.name, False):
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
193 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
194 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
195
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
196 @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
197 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
198 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
199
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
200
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
201 def _readheadsfile(self, filename):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
202 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
203 try:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
204 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
205 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
206 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
207 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
208 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
209 except IOError:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
210 pass
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
211 return heads
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
212 def _readstatesheads(self):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
213 statesheads = {}
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
214 for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
215 if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
216 filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
217 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
218 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
219
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
220 def _writeheadsfile(self, filename, heads):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
221 f = self.opener(filename, 'w', atomictemp=True)
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
222 try:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
223 for h in heads:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
224 f.write(hex(h) + '\n')
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
225 f.rename()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
226 finally:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
227 f.close()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
228
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 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
230 # transaction!
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
231 for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
232 if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
233 filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
234 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
235
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
236 def setstate(self, state, 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
237 """freeze targets changeset and it's ancestors.
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
238
beabde937e36 Add "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 Simplify the list of head."""
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
240 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
241 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
242 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
243 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
244 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
245 if olds != heads:
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
246 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
247 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
248 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
249 self._writestateshead()
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
250 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
251 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
252
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
253 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
254 selected = set()
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
255 st = laststatewithout(_NOSHARE)
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
256 for candidate in candidates:
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
257 rev = self.changelog.rev(candidate)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
258 ok = True
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
259 for h in self.stateheads(st):
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
260 revh = self.changelog.rev(h)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
261 if self.changelog.descendant(revh, rev):
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
262 ok = False
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
263 selected.add(h)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
264 if ok:
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
265 selected.add(candidate)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
266 return sorted(selected)
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
267
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
268 def cancopy(self):
19
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
269 st = laststatewithout(_NOSHARE)
8784a989a572 introduce a ``laststatewithout`` method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18
diff changeset
270 return o_cancopy() and (self.stateheads(st) == self.heads())
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
271
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
272 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
273