annotate mercurial/phases.py @ 17434:038f4f0439d7

test: remove invalid hidden rev in graphlog test The hidden set of revision can not have descendant outside this set. The extension is patched to raise and exception when this happen.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 30 Aug 2012 22:13:24 +0200
parents e95ec38f86b0
children fb72eec7efd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
1 """ Mercurial phases support code
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
2
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
3 ---
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
4
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
5 Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
6 Logilab SA <contact@logilab.fr>
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
7 Augie Fackler <durin42@gmail.com>
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
8
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
9 This software may be used and distributed according to the terms
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
10 of the GNU General Public License version 2 or any later version.
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
11
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
12 ---
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
13
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
14 This module implements most phase logic in mercurial.
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
15
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
16
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
17 Basic Concept
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
18 =============
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
19
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
20 A 'changeset phase' is an indicator that tells us how a changeset is
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
21 manipulated and communicated. The details of each phase is described
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
22 below, here we describe the properties they have in common.
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
23
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
24 Like bookmarks, phases are not stored in history and thus are not
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
25 permanent and leave no audit trail.
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
26
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
27 First, no changeset can be in two phases at once. Phases are ordered,
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
28 so they can be considered from lowest to highest. The default, lowest
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
29 phase is 'public' - this is the normal phase of existing changesets. A
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
30 child changeset can not be in a lower phase than its parents.
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
31
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
32 These phases share a hierarchy of traits:
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
33
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
34 immutable shared
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
35 public: X X
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
36 draft: X
15705
e34f4d1f0dbb phases: update doc to mention secret phase
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15697
diff changeset
37 secret:
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
38
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
39 Local commits are draft by default.
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
40
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
41 Phase Movement and Exchange
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
42 ===========================
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
43
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
44 Phase data is exchanged by pushkey on pull and push. Some servers have
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
45 a publish option set, we call such a server a "publishing server".
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
46 Pushing a draft changeset to a publishing server changes the phase to
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
47 public.
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
48
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
49 A small list of fact/rules define the exchange of phase:
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
50
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
51 * old client never changes server states
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
52 * pull never changes server states
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
53 * publish and old server changesets are seen as public by client
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
54 * any secret changeset seen in another repository is lowered to at
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
55 least draft
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
56
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
57 Here is the final table summing up the 49 possible use cases of phase
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
58 exchange:
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
59
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
60 server
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
61 old publish non-publish
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
62 N X N D P N D P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
63 old client
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
64 pull
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
65 N - X/X - X/D X/P - X/D X/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
66 X - X/X - X/D X/P - X/D X/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
67 push
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
68 X X/X X/X X/P X/P X/P X/D X/D X/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
69 new client
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
70 pull
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
71 N - P/X - P/D P/P - D/D P/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
72 D - P/X - P/D P/P - D/D P/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
73 P - P/X - P/D P/P - P/D P/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
74 push
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
75 D P/X P/X P/P P/P P/P D/D D/D P/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
76 P P/X P/X P/P P/P P/P P/P P/P P/P
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
77
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
78 Legend:
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
79
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
80 A/B = final state on client / state on server
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
81
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
82 * N = new/not present,
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
83 * P = public,
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
84 * D = draft,
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
85 * X = not tracked (i.e., the old client or server has no internal
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
86 way of recording the phase.)
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
87
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
88 passive = only pushes
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
89
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
90
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
91 A cell here can be read like this:
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
92
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
93 "When a new client pushes a draft changeset (D) to a publishing
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
94 server where it's not present (N), it's marked public on both
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
95 sides (P/P)."
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
96
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
97 Note: old client behave as a publishing server with draft only content
15659
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
98 - other people see it as public
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
99 - content is pushed as draft
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
100
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
101 """
15417
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
102
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
103 import errno
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
104 from node import nullid, nullrev, bin, hex, short
15456
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
105 from i18n import _
16659
58edd786e96f phase: make if abort on nullid for the good reason
Patrick Mezard <patrick@mezard.eu>
parents: 16658
diff changeset
106 import util
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
107
15818
57241845a4bb phases: store phase values in constant instead of using raw integer
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15705
diff changeset
108 allphases = public, draft, secret = range(3)
15417
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
109 trackedphases = allphases[1:]
15821
e3ee8bf5d0cc phases: add list of string to access phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15818
diff changeset
110 phasenames = ['public', 'draft', 'secret']
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
111
16624
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
112 def _filterunknown(ui, changelog, phaseroots):
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
113 """remove unknown nodes from the phase boundary
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
114
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
115 Nothing is lost as unknown nodes only hold data for their descendants.
16624
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
116 """
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
117 updated = False
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
118 nodemap = changelog.nodemap # to filter unknown nodes
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
119 for phase, nodes in enumerate(phaseroots):
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
120 missing = [node for node in nodes if node not in nodemap]
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
121 if missing:
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
122 for mnode in missing:
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
123 ui.debug(
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
124 'removing unknown node %s from %i-phase boundary\n'
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
125 % (short(mnode), phase))
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
126 nodes.symmetric_difference_update(missing)
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
127 updated = True
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
128 return updated
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
129
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
130 def _readroots(repo, phasedefaults=None):
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
131 """Read phase roots from disk
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
132
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
133 phasedefaults is a list of fn(repo, roots) callable, which are
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
134 executed if the phase roots file does not exist. When phases are
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
135 being initialized on an existing repository, this could be used to
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
136 set selected changesets phase to something else than public.
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
137
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
138 Return (roots, dirty) where dirty is true if roots differ from
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
139 what is being stored.
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
140 """
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
141 dirty = False
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
142 roots = [set() for i in allphases]
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
143 try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
144 f = repo.sopener('phaseroots')
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
145 try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
146 for line in f:
16588
72319bfd7966 phases: line.strip().split() == line.split()
Martin Geisler <mg@aragost.com>
parents: 16535
diff changeset
147 phase, nh = line.split()
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
148 roots[int(phase)].add(bin(nh))
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
149 finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
150 f.close()
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
151 except IOError, inst:
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
152 if inst.errno != errno.ENOENT:
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
153 raise
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
154 if phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
155 for f in phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
156 roots = f(repo, roots)
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
157 dirty = True
16624
3f85cef66dcc phases: call filterunknown() in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16588
diff changeset
158 if _filterunknown(repo.ui, repo.changelog, roots):
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
159 dirty = True
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
160 return roots, dirty
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
161
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
162 class phasecache(object):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
163 def __init__(self, repo, phasedefaults, _load=True):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
164 if _load:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
165 # Cheap trick to allow shallow-copy without copy module
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
166 self.phaseroots, self.dirty = _readroots(repo, phasedefaults)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
167 self.opener = repo.sopener
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
168 self._phaserevs = None
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
169
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
170 def copy(self):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
171 # Shallow copy meant to ensure isolation in
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
172 # advance/retractboundary(), nothing more.
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
173 ph = phasecache(None, None, _load=False)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
174 ph.phaseroots = self.phaseroots[:]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
175 ph.dirty = self.dirty
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
176 ph.opener = self.opener
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
177 ph._phaserevs = self._phaserevs
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
178 return ph
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
179
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
180 def replace(self, phcache):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
181 for a in 'phaseroots dirty opener _phaserevs'.split():
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
182 setattr(self, a, getattr(phcache, a))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
183
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
184 def getphaserevs(self, repo, rebuild=False):
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
185 if rebuild or self._phaserevs is None:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
186 revs = [public] * len(repo.changelog)
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
187 for phase in trackedphases:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
188 roots = map(repo.changelog.rev, self.phaseroots[phase])
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
189 if roots:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
190 for rev in roots:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
191 revs[rev] = phase
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16725
diff changeset
192 for rev in repo.changelog.descendants(roots):
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
193 revs[rev] = phase
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
194 self._phaserevs = revs
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
195 return self._phaserevs
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
196
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
197 def phase(self, repo, rev):
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17205
diff changeset
198 # We need a repo argument here to be able to build _phaserevs
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
199 # if necessary. The repository instance is not stored in
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
200 # phasecache to avoid reference cycles. The changelog instance
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
201 # is not stored because it is a filecache() property and can
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
202 # be replaced without us being notified.
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
203 if rev == nullrev:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
204 return public
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
205 if self._phaserevs is None or rev >= len(self._phaserevs):
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
206 self._phaserevs = self.getphaserevs(repo, rebuild=True)
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
207 return self._phaserevs[rev]
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
208
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
209 def write(self):
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
210 if not self.dirty:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
211 return
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
212 f = self.opener('phaseroots', 'w', atomictemp=True)
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
213 try:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
214 for phase, roots in enumerate(self.phaseroots):
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
215 for h in roots:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
216 f.write('%i %s\n' % (phase, hex(h)))
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
217 finally:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
218 f.close()
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
219 self.dirty = False
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
220
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
221 def _updateroots(self, phase, newroots):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
222 self.phaseroots[phase] = newroots
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
223 self._phaserevs = None
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
224 self.dirty = True
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
225
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
226 def advanceboundary(self, repo, targetphase, nodes):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
227 # Be careful to preserve shallow-copied values: do not update
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
228 # phaseroots values, replace them.
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
229
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
230 delroots = [] # set of root deleted by this path
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
231 for phase in xrange(targetphase + 1, len(allphases)):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
232 # filter nodes that are not in a compatible phase already
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
233 nodes = [n for n in nodes
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
234 if self.phase(repo, repo[n].rev()) >= phase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
235 if not nodes:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
236 break # no roots to move anymore
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
237 olds = self.phaseroots[phase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
238 roots = set(ctx.node() for ctx in repo.set(
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
239 'roots((%ln::) - (%ln::%ln))', olds, olds, nodes))
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
240 if olds != roots:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
241 self._updateroots(phase, roots)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
242 # some roots may need to be declared for lower phases
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
243 delroots.extend(olds - roots)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
244 # declare deleted root in the target phase
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
245 if targetphase != 0:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
246 self.retractboundary(repo, targetphase, delroots)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
247
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
248 def retractboundary(self, repo, targetphase, nodes):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
249 # Be careful to preserve shallow-copied values: do not update
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
250 # phaseroots values, replace them.
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
251
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
252 currentroots = self.phaseroots[targetphase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
253 newroots = [n for n in nodes
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
254 if self.phase(repo, repo[n].rev()) < targetphase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
255 if newroots:
16659
58edd786e96f phase: make if abort on nullid for the good reason
Patrick Mezard <patrick@mezard.eu>
parents: 16658
diff changeset
256 if nullid in newroots:
58edd786e96f phase: make if abort on nullid for the good reason
Patrick Mezard <patrick@mezard.eu>
parents: 16658
diff changeset
257 raise util.Abort(_('cannot change null revision phase'))
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
258 currentroots = currentroots.copy()
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
259 currentroots.update(newroots)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
260 ctxs = repo.set('roots(%ln::)', currentroots)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
261 currentroots.intersection_update(ctx.node() for ctx in ctxs)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
262 self._updateroots(targetphase, currentroots)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
263
15481
0b7ce2f739fb phases: rename moveboundary into advance boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15480
diff changeset
264 def advanceboundary(repo, targetphase, nodes):
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
265 """Add nodes to a phase changing other nodes phases if necessary.
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
266
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
267 This function move boundary *forward* this means that all nodes
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
268 are set in the target phase or kept in a *lower* phase.
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
269
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
270 Simplify boundary to contains phase roots only."""
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
271 phcache = repo._phasecache.copy()
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
272 phcache.advanceboundary(repo, targetphase, nodes)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
273 repo._phasecache.replace(phcache)
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
274
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
275 def retractboundary(repo, targetphase, nodes):
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
276 """Set nodes back to a phase changing other nodes phases if
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
277 necessary.
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
278
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
279 This function move boundary *backward* this means that all nodes
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
280 are set in the target phase or kept in a *higher* phase.
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
281
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
282 Simplify boundary to contains phase roots only."""
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
283 phcache = repo._phasecache.copy()
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
284 phcache.retractboundary(repo, targetphase, nodes)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
285 repo._phasecache.replace(phcache)
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
286
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
287 def listphases(repo):
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
288 """List phases root for serialization over pushkey"""
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
289 keys = {}
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
290 value = '%i' % draft
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
291 for root in repo._phasecache.phaseroots[draft]:
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
292 keys[hex(root)] = value
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
293
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
294 if repo.ui.configbool('phases', 'publish', True):
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
295 # Add an extra data to let remote know we are a publishing
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
296 # repo. Publishing repo can't just pretend they are old repo.
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
297 # When pushing to a publishing repo, the client still need to
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
298 # push phase boundary
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
299 #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
300 # Push do not only push changeset. It also push phase data.
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
301 # New phase data may apply to common changeset which won't be
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
302 # push (as they are common). Here is a very simple example:
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
303 #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
304 # 1) repo A push changeset X as draft to repo B
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
305 # 2) repo B make changeset X public
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
306 # 3) repo B push to repo A. X is not pushed but the data that
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
307 # X as now public should
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
308 #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
309 # The server can't handle it on it's own as it has no idea of
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
310 # client phase data.
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
311 keys['publishing'] = 'True'
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
312 return keys
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
313
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
314 def pushphase(repo, nhex, oldphasestr, newphasestr):
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
315 """List phases root for serialisation over pushkey"""
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
316 lock = repo.lock()
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
317 try:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
318 currentphase = repo[nhex].phase()
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
319 newphase = abs(int(newphasestr)) # let's avoid negative index surprise
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
320 oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
321 if currentphase == oldphase and newphase < oldphase:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
322 advanceboundary(repo, newphase, [bin(nhex)])
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
323 return 1
16051
2aa5b51f310f phases: don't complain if cset is already public on pushkey (issue3230)
Matt Mackall <mpm@selenic.com>
parents: 16030
diff changeset
324 elif currentphase == newphase:
2aa5b51f310f phases: don't complain if cset is already public on pushkey (issue3230)
Matt Mackall <mpm@selenic.com>
parents: 16030
diff changeset
325 # raced, but got correct result
2aa5b51f310f phases: don't complain if cset is already public on pushkey (issue3230)
Matt Mackall <mpm@selenic.com>
parents: 16030
diff changeset
326 return 1
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
327 else:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
328 return 0
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
329 finally:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
330 lock.release()
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
331
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
332 def analyzeremotephases(repo, subset, roots):
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
333 """Compute phases heads and root in a subset of node from root dict
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
334
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
335 * subset is heads of the subset
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
336 * roots is {<nodeid> => phase} mapping. key and value are string.
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
337
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
338 Accept unknown element input
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
339 """
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
340 # build list from dictionary
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
341 draftroots = []
15902
4252d9f08d7e phases: use nodemap to check for missing nodes
Sune Foldager <cryo@cyanite.org>
parents: 15892
diff changeset
342 nodemap = repo.changelog.nodemap # to filter unknown nodes
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
343 for nhex, phase in roots.iteritems():
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
344 if nhex == 'publishing': # ignore data related to publish option
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
345 continue
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
346 node = bin(nhex)
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
347 phase = int(phase)
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
348 if phase == 0:
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
349 if node != nullid:
15953
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
350 repo.ui.warn(_('ignoring inconsistent public root'
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
351 ' from remote: %s\n') % nhex)
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
352 elif phase == 1:
15902
4252d9f08d7e phases: use nodemap to check for missing nodes
Sune Foldager <cryo@cyanite.org>
parents: 15892
diff changeset
353 if node in nodemap:
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
354 draftroots.append(node)
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
355 else:
15953
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
356 repo.ui.warn(_('ignoring unexpected root from remote: %i %s\n')
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
357 % (phase, nhex))
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
358 # compute heads
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
359 publicheads = newheads(repo, subset, draftroots)
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
360 return publicheads, draftroots
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
361
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
362 def newheads(repo, heads, roots):
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
363 """compute new head of a subset minus another
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
364
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
365 * `heads`: define the first subset
17425
e95ec38f86b0 fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 17424
diff changeset
366 * `roots`: define the second we subtract from the first"""
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
367 revset = repo.set('heads((%ln + parents(%ln)) - (%ln::%ln))',
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
368 heads, roots, roots, heads)
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
369 return [c.node() for c in revset]
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
370
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
371
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
372 def newcommitphase(ui):
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
373 """helper to get the target phase of new commit
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
374
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
375 Handle all possible values for the phases.new-commit options.
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
376
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
377 """
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
378 v = ui.config('phases', 'new-commit', draft)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
379 try:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
380 return phasenames.index(v)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
381 except ValueError:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
382 try:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
383 return int(v)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
384 except ValueError:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
385 msg = _("phases.new-commit: not a valid phase name ('%s')")
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
386 raise error.ConfigError(msg % v)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
387