annotate states.py @ 15:a38b3d0a1562

add dedicated command to mark changeset as published or ready This command coul be generated.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 25 May 2011 02:19:20 +0200
parents f5e1055a3f68
children fd9f50406cb8
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
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
40 def __init__(self, name, order=0, next=None):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
41 self.name = name
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
42 self.order = order
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):
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
60 return cmp(self.order, other.order)
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
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
87 # 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
88 #############################
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
89 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
90 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
91 scmutil.revrange(repo, revsets))
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
92
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
93 # Patch changectx
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
94 #############################
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
95
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
96 def state(ctx):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
97 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
98 context.changectx.state = state
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 # improve template
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 showstate(ctx, **args):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
104 return ctx.state()
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
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 # New revset predicate
beabde937e36 Add "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 #############################
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
108
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
109
beabde937e36 Add "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
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
111 # 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
112 #############################
beabde937e36 Add "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
15
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
114 def cmdpublished(ui, repo, *changesets):
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
115 revs = scmutil.revrange(repo, changesets)
15
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
116 repo.setstate(ST0, [repo.changelog.node(rev) for rev in revs])
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
117 return 0
beabde937e36 Add "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
15
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
119 def cmdready(ui, repo, *changesets):
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
120 revs = scmutil.revrange(repo, changesets)
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
121 repo.setstate(ST1, [repo.changelog.node(rev) for rev in revs])
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
122 return 0
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
123
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
124 #autogen this
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
125 cmdtable = {
15
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
126 'published': (cmdpublished, [], _('<revset>')),
a38b3d0a1562 add dedicated command to mark changeset as published or ready
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14
diff changeset
127 'ready': (cmdready, [], _('<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
128 }
beabde937e36 Add "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 templatekw.keywords['state'] = showstate
beabde937e36 Add "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
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
137
beabde937e36 Add "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 def uisetup(ui):
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
139 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
140 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
141 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
142 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
143 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
144 heads = remote._reducehead(heads)
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
145 return common, anyinc, heads
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
146
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
147 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
148 extensions.wrapfunction(discovery, 'findcommonincoming', filterprivatein)
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
149
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
150 # Write protocols
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
151 ####################
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
152 def heads(repo, proto):
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
153 h = repo.stateheads(ST1)
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
154 return wireproto.encodelist(h) + "\n"
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
155
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
156 def _reducehead(wirerepo, heads):
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
157 """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
158 return heads
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
159
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
160 wireproto.wirerepository._reducehead = _reducehead
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
161 wireproto.commands['heads'] = (heads, '')
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5
diff changeset
162
14
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
163 def extsetup(ui):
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
164 for state in STATES:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
165 if state.trackheads:
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
166 revset.symbols[state.headssymbol] = state._revsetheads
f5e1055a3f68 reorder extsetup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 13
diff changeset
167
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
168 def reposetup(ui, repo):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
169
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
170 if not repo.local():
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
171 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
172
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
173 o_cancopy =repo.cancopy
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
174 class statefulrepo(repo.__class__):
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
175
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
176 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
177 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
178 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
179 # 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
180 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
181 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
182 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
183 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
184 return state.next
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
185 return state
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
186
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
187
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
188
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
189 def stateheads(self, state):
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
190 if state.trackheads:
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
191 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
192 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
193 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
194
beabde937e36 Add "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 @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
196 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
197 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
198
beabde937e36 Add "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
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
200 def _readheadsfile(self, filename):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
201 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
202 try:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
203 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
204 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
205 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
206 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
207 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
208 except IOError:
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
209 pass
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
210 return heads
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
211 def _readstatesheads(self):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
212 statesheads = {}
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
213 for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
214 if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
215 filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
216 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
217 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
218
9
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
219 def _writeheadsfile(self, filename, heads):
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
220 f = self.opener(filename, 'w', atomictemp=True)
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
221 try:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
222 for h in heads:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
223 f.write(hex(h) + '\n')
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
224 f.rename()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
225 finally:
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
226 f.close()
1f84a74df837 introduce a third state
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7
diff changeset
227
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
228 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
229 # transaction!
12
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
230 for state in STATES:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
231 if state.trackheads:
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
232 filename = 'states/%s-heads' % state.name
6312fc525a54 rename state related attributes
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 11
diff changeset
233 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
234
beabde937e36 Add "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 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
236 """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
237
beabde937e36 Add "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 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
239 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
240 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
241 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
242 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
243 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
244 if olds != heads:
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
245 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
246 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
247 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
248 self._writestateshead()
10
91169d2d7f1b state are now object.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 9
diff changeset
249 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
250 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
251
2
166694e62daf hide private changeset to inc and pull.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 1
diff changeset
252 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
253 selected = set()
beabde937e36 Add "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 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
255 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
256 ok = True
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
257 for h in self.stateheads(ST1):
1
beabde937e36 Add "private" concept (2). private changeset are hiden suppose to be hidden for
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 0
diff changeset
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
266 def cancopy(self):
13
e95e8cf7988f Get ride of dedicated heads property.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 12
diff changeset
267 return o_cancopy() and (self.stateheads(ST1) == self.heads())
5
9445ce78a935 fix clone
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2
diff changeset
268
0
bbeef801409c minimalistic state concept.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
269 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
270