annotate mercurial/phases.py @ 51403:12881244e48a

phases: do filtering at read time This remove the need for the `filterunknown` method at all.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 20 Feb 2024 21:40:08 +0100
parents 04111ef08fb0
children f8bf1a8e9181
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
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
103
34326
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
104 import struct
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
105 import typing
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
106 import weakref
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
107
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
108 from typing import (
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
109 Any,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
110 Callable,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
111 Dict,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
112 Iterable,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
113 List,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
114 Optional,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
115 Set,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
116 Tuple,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
117 )
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
118
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
119 from .i18n import _
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
120 from .node import (
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
121 bin,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
122 hex,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
123 nullrev,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
124 short,
44007
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43763
diff changeset
125 wdirrev,
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
126 )
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
127 from . import (
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
128 error,
35318
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
129 pycompat,
45392
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45376
diff changeset
130 requirements,
31036
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
131 smartset,
31073
6afd8a87a657 phases: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31036
diff changeset
132 txnutil,
32000
511a62669f1b phases: emit phases to pushkey protocol in deterministic order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31351
diff changeset
133 util,
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
134 )
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
135
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
136 Phaseroots = Dict[int, Set[bytes]]
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
137
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
138 if typing.TYPE_CHECKING:
46683
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
139 from . import (
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
140 localrepo,
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
141 ui as uimod,
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
142 )
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
143
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
144 # keeps pyflakes happy
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
145 assert [uimod]
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51122
diff changeset
146
46683
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
147 Phasedefaults = List[
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
148 Callable[[localrepo.localrepository, Phaseroots], Phaseroots]
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
149 ]
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
150
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
151
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
152 _fphasesentry = struct.Struct(b'>i20s')
34326
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
153
39324
06c976acc581 phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents: 39320
diff changeset
154 # record phase index
51305
8b2ea2246a5f pytype: convert type comment for inline variable too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51304
diff changeset
155 public: int = 0
8b2ea2246a5f pytype: convert type comment for inline variable too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51304
diff changeset
156 draft: int = 1
8b2ea2246a5f pytype: convert type comment for inline variable too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51304
diff changeset
157 secret: int = 2
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
158 archived = 32 # non-continuous for compatibility
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
159 internal = 96 # non-continuous for compatibility
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
160 allphases = (public, draft, secret, archived, internal)
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
161 trackedphases = (draft, secret, archived, internal)
50421
92f71d40fc1d revset: include all non-public phases in _notpublic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49475
diff changeset
162 not_public_phases = trackedphases
39324
06c976acc581 phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents: 39320
diff changeset
163 # record phase names
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
164 cmdphasenames = [b'public', b'draft', b'secret'] # known to `hg phase` command
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
165 phasenames = dict(enumerate(cmdphasenames))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
166 phasenames[archived] = b'archived'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
167 phasenames[internal] = b'internal'
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
168 # map phase name to phase number
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
169 phasenumber = {name: phase for phase, name in phasenames.items()}
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
170 # like phasenumber, but also include maps for the numeric and binary
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
171 # phase number to the phase number
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
172 phasenumber2 = phasenumber.copy()
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
173 phasenumber2.update({phase: phase for phase in phasenames})
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
174 phasenumber2.update({b'%i' % phase: phase for phase in phasenames})
39324
06c976acc581 phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents: 39320
diff changeset
175 # record phase property
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
176 mutablephases = (draft, secret, archived, internal)
51122
80bda4254b84 unstable: do not consider internal phases when computing unstable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
177 relevant_mutable_phases = (draft, secret) # could be obsolete or unstable
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
178 remotehiddenphases = (secret, archived, internal)
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
179 localhiddenphases = (internal, archived)
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
180
50430
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50426
diff changeset
181 all_internal_phases = tuple(p for p in allphases if p & internal)
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50426
diff changeset
182 # We do not want any internal content to exit the repository, ever.
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50426
diff changeset
183 no_bundle_phases = all_internal_phases
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50426
diff changeset
184
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
185
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
186 def supportinternal(repo: "localrepo.localrepository") -> bool:
39326
7775c1fb8fa0 phases: enforce internal phase support
Boris Feld <boris.feld@octobus.net>
parents: 39324
diff changeset
187 """True if the internal phase can be used on a repository"""
45392
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45376
diff changeset
188 return requirements.INTERNAL_PHASE_REQUIREMENT in repo.requirements
39326
7775c1fb8fa0 phases: enforce internal phase support
Boris Feld <boris.feld@octobus.net>
parents: 39324
diff changeset
189
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
190
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
191 def supportarchived(repo: "localrepo.localrepository") -> bool:
49474
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
192 """True if the archived phase can be used on a repository"""
49475
0c70d888a484 phase: introduce a dedicated requirement for the `archived` phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49474
diff changeset
193 return requirements.ARCHIVED_PHASE_REQUIREMENT in repo.requirements
49474
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
194
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
195
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
196 def _readroots(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
197 repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
198 phasedefaults: Optional["Phasedefaults"] = None,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
199 ) -> Tuple[Phaseroots, bool]:
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
200 """Read phase roots from disk
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
201
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
202 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
203 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
204 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
205 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
206
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
207 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
208 what is being stored.
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
209 """
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
210 repo = repo.unfiltered()
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
211 dirty = False
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
212 roots = {i: set() for i in allphases}
51403
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
213 has_node = repo.changelog.index.has_node
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
214 unknown_msg = b'removing unknown node %s from %i-phase boundary\n'
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
215 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
216 f, pending = txnutil.trypending(repo.root, repo.svfs, b'phaseroots')
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
217 try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
218 for line in f:
51403
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
219 str_phase, hex_node = line.split()
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
220 phase = int(str_phase)
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
221 node = bin(hex_node)
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
222 if not has_node(node):
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
223 repo.ui.debug(unknown_msg % (short(hex_node), phase))
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
224 dirty = True
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
225 else:
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
226 roots[phase].add(node)
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
227 finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
228 f.close()
49314
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49292
diff changeset
229 except FileNotFoundError:
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
230 if phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
231 for f in phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
232 roots = f(repo, roots)
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
233 dirty = True
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
234 return roots, dirty
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
235
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
236
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
237 def binaryencode(phasemapping: Dict[int, List[bytes]]) -> bytes:
34326
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
238 """encode a 'phase -> nodes' mapping into a binary stream
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
239
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
240 The revision lists are encoded as (phase, root) pairs.
34326
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
241 """
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
242 binarydata = []
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
243 for phase, nodes in phasemapping.items():
34326
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
244 for head in nodes:
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
245 binarydata.append(_fphasesentry.pack(phase, head))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
246 return b''.join(binarydata)
34326
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
247
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
248
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
249 def binarydecode(stream) -> Dict[int, List[bytes]]:
34327
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
250 """decode a binary stream into a 'phase -> nodes' mapping
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
251
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
252 The (phase, root) pairs are turned back into a dictionary with
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
253 the phase as index and the aggregated roots of that phase as value."""
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
254 headsbyphase = {i: [] for i in allphases}
34327
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
255 entrysize = _fphasesentry.size
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
256 while True:
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
257 entry = stream.read(entrysize)
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
258 if len(entry) < entrysize:
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
259 if entry:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
260 raise error.Abort(_(b'bad phase-heads stream'))
34327
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
261 break
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
262 phase, node = _fphasesentry.unpack(entry)
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
263 headsbyphase[phase].append(node)
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
264 return headsbyphase
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34326
diff changeset
265
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
266
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
267 def _sortedrange_insert(data, idx, rev, t):
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
268 merge_before = False
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
269 if idx:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
270 r1, t1 = data[idx - 1]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
271 merge_before = r1[-1] + 1 == rev and t1 == t
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
272 merge_after = False
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
273 if idx < len(data):
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
274 r2, t2 = data[idx]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
275 merge_after = r2[0] == rev + 1 and t2 == t
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
276
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
277 if merge_before and merge_after:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
278 data[idx - 1] = (range(r1[0], r2[-1] + 1), t)
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
279 data.pop(idx)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
280 elif merge_before:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
281 data[idx - 1] = (range(r1[0], rev + 1), t)
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
282 elif merge_after:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
283 data[idx] = (range(rev, r2[-1] + 1), t)
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
284 else:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
285 data.insert(idx, (range(rev, rev + 1), t))
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
286
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
287
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
288 def _sortedrange_split(data, idx, rev, t):
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
289 r1, t1 = data[idx]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
290 if t == t1:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
291 return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
292 t = (t1[0], t[1])
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
293 if len(r1) == 1:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
294 data.pop(idx)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
295 _sortedrange_insert(data, idx, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
296 elif r1[0] == rev:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
297 data[idx] = (range(rev + 1, r1[-1] + 1), t1)
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
298 _sortedrange_insert(data, idx, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
299 elif r1[-1] == rev:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
300 data[idx] = (range(r1[0], rev), t1)
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
301 _sortedrange_insert(data, idx + 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
302 else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
303 data[idx : idx + 1] = [
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
304 (range(r1[0], rev), t1),
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
305 (range(rev, rev + 1), t),
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
306 (range(rev + 1, r1[-1] + 1), t1),
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
307 ]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
308
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
309
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
310 def _trackphasechange(data, rev, old, new):
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
311 """add a phase move to the <data> list of ranges
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
312
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
313 If data is None, nothing happens.
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
314 """
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
315 if data is None:
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
316 return
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
317
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
318 # If data is empty, create a one-revision range and done
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
319 if not data:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
320 data.insert(0, (range(rev, rev + 1), (old, new)))
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
321 return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
322
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
323 low = 0
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
324 high = len(data)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
325 t = (old, new)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
326 while low < high:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
327 mid = (low + high) // 2
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
328 revs = data[mid][0]
45556
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45392
diff changeset
329 revs_low = revs[0]
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45392
diff changeset
330 revs_high = revs[-1]
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
331
45556
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45392
diff changeset
332 if rev >= revs_low and rev <= revs_high:
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
333 _sortedrange_split(data, mid, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
334 return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
335
45556
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45392
diff changeset
336 if revs_low == rev + 1:
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
337 if mid and data[mid - 1][0][-1] == rev:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
338 _sortedrange_split(data, mid - 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
339 else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
340 _sortedrange_insert(data, mid, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
341 return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
342
45556
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45392
diff changeset
343 if revs_high == rev - 1:
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
344 if mid + 1 < len(data) and data[mid + 1][0][0] == rev:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
345 _sortedrange_split(data, mid + 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
346 else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
347 _sortedrange_insert(data, mid + 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
348 return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
349
45556
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45392
diff changeset
350 if revs_low > rev:
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
351 high = mid
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
352 else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
353 low = mid + 1
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
354
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
355 if low == len(data):
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
356 data.append((range(rev, rev + 1), t))
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
357 return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
358
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
359 r1, t1 = data[low]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
360 if r1[0] > rev:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
361 data.insert(low, (range(rev, rev + 1), t))
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
362 else:
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
363 data.insert(low + 1, (range(rev, rev + 1), t))
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
364
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
365
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
366 class phasecache:
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
367 def __init__(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
368 self,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
369 repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
370 phasedefaults: Optional["Phasedefaults"],
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
371 _load: bool = True,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
372 ):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
373 if _load:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
374 # Cheap trick to allow shallow-copy without copy module
51403
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
375 loaded = _readroots(repo, phasedefaults)
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
376 self._phaseroots: Phaseroots = loaded[0]
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51402
diff changeset
377 self.dirty: bool = loaded[1]
35446
56745e58df07 phases: initialize number of loaded revisions to 0
Yuya Nishihara <yuya@tcha.org>
parents: 35445
diff changeset
378 self._loadedrevslen = 0
25190
22438cfd11b5 phases: add set per phase in C phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24599
diff changeset
379 self._phasesets = None
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
380
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
381 def hasnonpublicphases(self, repo: "localrepo.localrepository") -> bool:
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
382 """detect if there are revisions with non-public phase"""
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
383 repo = repo.unfiltered()
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
384 cl = repo.changelog
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
385 if len(cl) >= self._loadedrevslen:
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
386 self.invalidate()
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
387 self.loadphaserevs(repo)
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
388 return any(
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
389 revs for phase, revs in self._phaseroots.items() if phase != public
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
390 )
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
391
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
392 def nonpublicphaseroots(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
393 self, repo: "localrepo.localrepository"
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
394 ) -> Set[bytes]:
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
395 """returns the roots of all non-public phases
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
396
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
397 The roots are not minimized, so if the secret revisions are
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
398 descendants of draft revisions, their roots will still be present.
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
399 """
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
400 repo = repo.unfiltered()
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
401 cl = repo.changelog
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
402 if len(cl) >= self._loadedrevslen:
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
403 self.invalidate()
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
404 self.loadphaserevs(repo)
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
405 return set().union(
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
406 *[
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
407 revs
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
408 for phase, revs in self._phaseroots.items()
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
409 if phase != public
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
410 ]
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
411 )
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45064
diff changeset
412
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
413 def getrevset(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
414 self,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
415 repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
416 phases: Iterable[int],
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
417 subset: Optional[Any] = None,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
418 ) -> Any:
46683
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45813
diff changeset
419 # TODO: finish typing this
31036
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
420 """return a smartset for the given phases"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
421 self.loadphaserevs(repo) # ensure phase's sets are loaded
35318
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
422 phases = set(phases)
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
423 publicphase = public in phases
44007
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43763
diff changeset
424
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
425 if publicphase:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
426 # In this case, phases keeps all the *other* phases.
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
427 phases = set(allphases).difference(phases)
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
428 if not phases:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
429 return smartset.fullreposet(repo)
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
430
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
431 # fast path: _phasesets contains the interesting sets,
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
432 # might only need a union and post-filtering.
44065
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
433 revsneedscopy = False
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
434 if len(phases) == 1:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
435 [p] = phases
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
436 revs = self._phasesets[p]
44065
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
437 revsneedscopy = True # Don't modify _phasesets
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
438 else:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
439 # revs has the revisions in all *other* phases.
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
440 revs = set.union(*[self._phasesets[p] for p in phases])
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
441
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
442 def _addwdir(wdirsubset, wdirrevs):
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
443 if wdirrev in wdirsubset and repo[None].phase() in phases:
44065
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
444 if revsneedscopy:
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
445 wdirrevs = wdirrevs.copy()
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
446 # The working dir would never be in the # cache, but it was in
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
447 # the subset being filtered for its phase (or filtered out,
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
448 # depending on publicphase), so add it to the output to be
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
449 # included (or filtered out).
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
450 wdirrevs.add(wdirrev)
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
451 return wdirrevs
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
452
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
453 if not publicphase:
31036
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
454 if repo.changelog.filteredrevs:
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
455 revs = revs - repo.changelog.filteredrevs
44007
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43763
diff changeset
456
35339
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
457 if subset is None:
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
458 return smartset.baseset(revs)
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
459 else:
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
460 revs = _addwdir(subset, revs)
35339
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
461 return subset & smartset.baseset(revs)
31036
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
462 else:
35339
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
463 if subset is None:
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
464 subset = smartset.fullreposet(repo)
44007
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43763
diff changeset
465
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44007
diff changeset
466 revs = _addwdir(subset, revs)
44007
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43763
diff changeset
467
35318
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
468 if not revs:
35339
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
469 return subset
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35318
diff changeset
470 return subset.filter(lambda r: r not in revs)
31036
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
471
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
472 def copy(self):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
473 # Shallow copy meant to ensure isolation in
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
474 # advance/retractboundary(), nothing more.
23631
b8260abfeb7d bundlerepo: implement safe phasecache
Eric Sumner <ericsumner@fb.com>
parents: 23361
diff changeset
475 ph = self.__class__(None, None, _load=False)
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
476 ph._phaseroots = self._phaseroots.copy()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
477 ph.dirty = self.dirty
35445
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35339
diff changeset
478 ph._loadedrevslen = self._loadedrevslen
25592
dd2349ccfa66 phase: also copy phase's sets when copying phase cache
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25527
diff changeset
479 ph._phasesets = self._phasesets
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
480 return ph
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
481
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
482 def replace(self, phcache):
25613
a13c18c14ade phase: document the replace method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25611
diff changeset
483 """replace all values in 'self' with content of phcache"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
484 for a in (
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
485 '_phaseroots',
50623
0f83dc22efbc safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50430
diff changeset
486 'dirty',
0f83dc22efbc safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50430
diff changeset
487 '_loadedrevslen',
0f83dc22efbc safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50430
diff changeset
488 '_phasesets',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
489 ):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
490 setattr(self, a, getattr(phcache, a))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
491
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
492 def _getphaserevsnative(self, repo):
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
493 repo = repo.unfiltered()
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
494 return repo.changelog.computephases(self._phaseroots)
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
495
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
496 def _computephaserevspure(self, repo):
24519
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
497 repo = repo.unfiltered()
35318
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
498 cl = repo.changelog
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
499 self._phasesets = {phase: set() for phase in allphases}
39298
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
500 lowerroots = set()
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
501 for phase in reversed(trackedphases):
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
502 roots = pycompat.maplist(cl.rev, self._phaseroots[phase])
39298
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
503 if roots:
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
504 ps = set(cl.descendants(roots))
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
505 for root in roots:
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
506 ps.add(root)
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
507 ps.difference_update(lowerroots)
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
508 lowerroots.update(ps)
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39290
diff changeset
509 self._phasesets[phase] = ps
35445
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35339
diff changeset
510 self._loadedrevslen = len(cl)
24519
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
511
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
512 def loadphaserevs(self, repo: "localrepo.localrepository") -> None:
25611
d89045a66e01 phase: rename getphaserevs to loadphaserevs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25594
diff changeset
513 """ensure phase information is loaded in the object"""
35318
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
514 if self._phasesets is None:
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
515 try:
31162
b7cef987356d phases: remove experimental.nativephaseskillswitch
Jun Wu <quark@fb.com>
parents: 31073
diff changeset
516 res = self._getphaserevsnative(repo)
35445
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35339
diff changeset
517 self._loadedrevslen, self._phasesets = res
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
518 except AttributeError:
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
519 self._computephaserevspure(repo)
22894
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
520
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
521 def invalidate(self):
35446
56745e58df07 phases: initialize number of loaded revisions to 0
Yuya Nishihara <yuya@tcha.org>
parents: 35445
diff changeset
522 self._loadedrevslen = 0
25593
9e551f155810 phase: invalidate the phase's set cache alongside the revs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25592
diff changeset
523 self._phasesets = None
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
524
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
525 def phase(self, repo: "localrepo.localrepository", rev: int) -> int:
35318
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
526 # We need a repo argument here to be able to build _phasesets
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
527 # if necessary. The repository instance is not stored in
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
528 # phasecache to avoid reference cycles. The changelog instance
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
529 # is not stored because it is a filecache() property and can
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
530 # be replaced without us being notified.
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
531 if rev == nullrev:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
532 return public
19984
7d5e7799a29f rebase: fix rebase aborts when 'tip-1' is public (issue4082)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
533 if rev < nullrev:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
534 raise ValueError(_(b'cannot lookup negative revision'))
35445
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35339
diff changeset
535 if rev >= self._loadedrevslen:
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
536 self.invalidate()
25611
d89045a66e01 phase: rename getphaserevs to loadphaserevs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25594
diff changeset
537 self.loadphaserevs(repo)
35318
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
538 for phase in trackedphases:
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
539 if rev in self._phasesets[phase]:
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
540 return phase
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
541 return public
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
542
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
543 def write(self, repo):
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
544 if not self.dirty:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
545 return
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
546 f = repo.svfs(b'phaseroots', b'w', atomictemp=True, checkambig=True)
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
547 try:
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
548 self._write(repo.unfiltered(), f)
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
549 finally:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
550 f.close()
22079
5dcc58649b1a phase: extract the phaseroots serialization in a dedicated method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22070
diff changeset
551
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
552 def _write(self, repo, fp):
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
553 assert repo.filtername is None
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
554 for phase, roots in self._phaseroots.items():
36482
ab81e5a8fba5 phases: write phaseroots deterministically
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35446
diff changeset
555 for h in sorted(roots):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
556 fp.write(b'%i %s\n' % (phase, hex(h)))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
557 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
558
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
559 def _updateroots(self, repo, phase, newroots, tr):
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
560 self._phaseroots[phase] = newroots
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
561 self.invalidate()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
562 self.dirty = True
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
563
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
564 assert repo.filtername is None
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
565 wrepo = weakref.ref(repo)
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
566
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
567 def tr_write(fp):
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
568 repo = wrepo()
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
569 assert repo is not None
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
570 self._write(repo, fp)
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
571
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
572 tr.addfilegenerator(b'phase', (b'phaseroots',), tr_write)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
573 tr.hookargs[b'phases_moved'] = b'1'
22080
37f46575d9c2 phase: attach phase to the transaction instead of the lock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22079
diff changeset
574
45813
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45812
diff changeset
575 def registernew(self, repo, tr, targetphase, revs):
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
576 repo = repo.unfiltered()
45813
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45812
diff changeset
577 self._retractboundary(repo, tr, targetphase, [], revs=revs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
578 if tr is not None and b'phases' in tr.changes:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
579 phasetracking = tr.changes[b'phases']
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
580 phase = self.phase
45813
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45812
diff changeset
581 for rev in sorted(revs):
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
582 revphase = phase(repo, rev)
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
583 _trackphasechange(phasetracking, rev, None, revphase)
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
584 repo.invalidatevolatilesets()
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
585
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
586 def advanceboundary(
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
587 self, repo, tr, targetphase, nodes, revs=None, dryrun=None
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
588 ):
33450
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
589 """Set all 'nodes' to phase 'targetphase'
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
590
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
591 Nodes with a phase lower than 'targetphase' are not affected.
38230
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
592
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
593 If dryrun is True, no actions will be performed
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
594
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
595 Returns a set of revs whose phase is changed or should be changed
33450
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
596 """
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
597 # 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
598 # phaseroots values, replace them.
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
599 if revs is None:
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
600 revs = []
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
601 if tr is None:
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
602 phasetracking = None
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
603 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
604 phasetracking = tr.changes.get(b'phases')
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
605
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
606 repo = repo.unfiltered()
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
607 revs = [repo[n].rev() for n in nodes] + [r for r in revs]
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
608
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
609 changes = set() # set of revisions to be changed
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
610 delroots = [] # set of root deleted by this path
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
611 for phase in (phase for phase in allphases if phase > targetphase):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
612 # filter nodes that are not in a compatible phase already
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
613 revs = [rev for rev in revs if self.phase(repo, rev) >= phase]
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
614 if not revs:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
615 break # no roots to move anymore
33450
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
616
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
617 olds = self._phaseroots[phase]
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
618
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
619 affected = repo.revs(b'%ln::%ld', olds, revs)
38230
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
620 changes.update(affected)
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
621 if dryrun:
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
622 continue
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
623 for r in affected:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
624 _trackphasechange(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
625 phasetracking, r, self.phase(repo, r), targetphase
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
626 )
33450
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
627
44470
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44065
diff changeset
628 roots = {
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
629 ctx.node()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
630 for ctx in repo.set(b'roots((%ln::) - %ld)', olds, affected)
44470
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44065
diff changeset
631 }
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
632 if olds != roots:
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
633 self._updateroots(repo, phase, roots, tr)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
634 # 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
635 delroots.extend(olds - roots)
38230
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
636 if not dryrun:
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
637 # declare deleted root in the target phase
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
638 if targetphase != 0:
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
639 self._retractboundary(repo, tr, targetphase, delroots)
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
640 repo.invalidatevolatilesets()
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
641 return changes
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
642
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
643 def retractboundary(self, repo, tr, targetphase, nodes):
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
644 oldroots = {
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
645 phase: revs
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
646 for phase, revs in self._phaseroots.items()
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
647 if phase <= targetphase
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
648 }
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
649 if tr is None:
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
650 phasetracking = None
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
651 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
652 phasetracking = tr.changes.get(b'phases')
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
653 repo = repo.unfiltered()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
654 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
655 self._retractboundary(repo, tr, targetphase, nodes)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
656 and phasetracking is not None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
657 ):
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
658
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
659 # find the affected revisions
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
660 new = self._phaseroots[targetphase]
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
661 old = oldroots[targetphase]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
662 affected = set(repo.revs(b'(%ln::) - (%ln::)', new, old))
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
663
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
664 # find the phase of the affected revision
49292
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
665 for phase in range(targetphase, -1, -1):
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
666 if phase:
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
667 roots = oldroots.get(phase, [])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
668 revs = set(repo.revs(b'%ln::%ld', roots, affected))
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
669 affected -= revs
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
670 else: # public phase
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
671 revs = affected
44558
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44470
diff changeset
672 for r in sorted(revs):
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
673 _trackphasechange(phasetracking, r, phase, targetphase)
33452
7b25a56366cf phases: extract the core of boundary retraction in '_retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33451
diff changeset
674 repo.invalidatevolatilesets()
7b25a56366cf phases: extract the core of boundary retraction in '_retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33451
diff changeset
675
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
676 def _retractboundary(self, repo, tr, targetphase, nodes, revs=None):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
677 # 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
678 # phaseroots values, replace them.
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
679 if revs is None:
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
680 revs = []
49474
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
681 if (
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
682 targetphase == internal
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
683 and not supportinternal(repo)
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
684 or targetphase == archived
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
685 and not supportarchived(repo)
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49314
diff changeset
686 ):
40408
49c7b701fdc2 phase: add an archived phase
Boris Feld <boris.feld@octobus.net>
parents: 39326
diff changeset
687 name = phasenames[targetphase]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
688 msg = b'this repository does not support the %s phase' % name
39326
7775c1fb8fa0 phases: enforce internal phase support
Boris Feld <boris.feld@octobus.net>
parents: 39324
diff changeset
689 raise error.ProgrammingError(msg)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
690
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
691 repo = repo.unfiltered()
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
692 torev = repo.changelog.rev
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
693 tonode = repo.changelog.node
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
694 currentroots = {torev(node) for node in self._phaseroots[targetphase]}
33457
61714c282106 phases: detect when boundaries has been actually retracted
Boris Feld <boris.feld@octobus.net>
parents: 33453
diff changeset
695 finalroots = oldroots = set(currentroots)
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
696 newroots = [torev(node) for node in nodes] + [r for r in revs]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
697 newroots = [
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
698 rev for rev in newroots if self.phase(repo, rev) < targetphase
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
699 ]
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
700
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
701 if newroots:
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
702 if nullrev in newroots:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
703 raise error.Abort(_(b'cannot change null revision phase'))
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
704 currentroots.update(newroots)
26909
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
705
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
706 # Only compute new roots for revs above the roots that are being
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
707 # retracted.
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
708 minnewroot = min(newroots)
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
709 aboveroots = [rev for rev in currentroots if rev >= minnewroot]
45013
98f97026fa05 phases: remove useless lookup of repo[rev].rev() in _retractboundary
Yuya Nishihara <yuya@tcha.org>
parents: 45008
diff changeset
710 updatedroots = repo.revs(b'roots(%ld::)', aboveroots)
26909
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
711
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
712 finalroots = {rev for rev in currentroots if rev < minnewroot}
45013
98f97026fa05 phases: remove useless lookup of repo[rev].rev() in _retractboundary
Yuya Nishihara <yuya@tcha.org>
parents: 45008
diff changeset
713 finalroots.update(updatedroots)
33457
61714c282106 phases: detect when boundaries has been actually retracted
Boris Feld <boris.feld@octobus.net>
parents: 33453
diff changeset
714 if finalroots != oldroots:
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
715 self._updateroots(
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
716 repo,
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
717 targetphase,
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
718 {tonode(rev) for rev in finalroots},
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
719 tr,
45008
fa151f7af275 phases: improve performance of _retractboundary
Joerg Sonnenberger <joerg@bec.de>
parents: 44558
diff changeset
720 )
33457
61714c282106 phases: detect when boundaries has been actually retracted
Boris Feld <boris.feld@octobus.net>
parents: 33453
diff changeset
721 return True
61714c282106 phases: detect when boundaries has been actually retracted
Boris Feld <boris.feld@octobus.net>
parents: 33453
diff changeset
722 return False
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
723
51399
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
724 def register_strip(
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
725 self,
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
726 repo: "localrepo.localrepository",
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
727 tr,
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
728 strip_rev: int,
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
729 ):
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
730 """announce a strip to the phase cache
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
731
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
732 Any roots higher than the stripped revision should be dropped.
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
733 """
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
734 assert repo.filtername is None
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
735 to_rev = repo.changelog.index.rev
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
736 for targetphase, nodes in list(self._phaseroots.items()):
51399
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
737 filtered = {n for n in nodes if to_rev(n) >= strip_rev}
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
738 if filtered:
51402
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
739 self._updateroots(repo, targetphase, nodes - filtered, tr)
51399
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
740 self.invalidate()
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
741
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
742
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
743 def advanceboundary(repo, tr, targetphase, nodes, revs=None, dryrun=None):
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
744 """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
745
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
746 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
747 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
748
38230
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
749 Simplify boundary to contains phase roots only.
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
750
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
751 If dryrun is True, no actions will be performed
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
752
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
753 Returns a set of revs whose phase is changed or should be changed
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
754 """
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
755 if revs is None:
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
756 revs = []
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
757 phcache = repo._phasecache.copy()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
758 changes = phcache.advanceboundary(
45812
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45556
diff changeset
759 repo, tr, targetphase, nodes, revs=revs, dryrun=dryrun
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
760 )
38230
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
761 if not dryrun:
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
762 repo._phasecache.replace(phcache)
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38191
diff changeset
763 return changes
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
764
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
765
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
766 def retractboundary(repo, tr, targetphase, nodes):
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
767 """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
768 necessary.
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
769
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
770 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
771 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
772
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
773 Simplify boundary to contains phase roots only."""
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
774 phcache = repo._phasecache.copy()
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
775 phcache.retractboundary(repo, tr, targetphase, nodes)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
776 repo._phasecache.replace(phcache)
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
777
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
778
45813
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45812
diff changeset
779 def registernew(repo, tr, targetphase, revs):
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
780 """register a new revision and its phase
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
781
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
782 Code adding revisions to the repository should use this function to
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
783 set new changeset in their target phase (or higher).
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
784 """
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
785 phcache = repo._phasecache.copy()
45813
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45812
diff changeset
786 phcache.registernew(repo, tr, targetphase, revs)
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
787 repo._phasecache.replace(phcache)
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
788
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
789
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
790 def listphases(repo: "localrepo.localrepository") -> Dict[bytes, bytes]:
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
791 """List phases root for serialization over pushkey"""
32000
511a62669f1b phases: emit phases to pushkey protocol in deterministic order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31351
diff changeset
792 # Use ordered dictionary so behavior is deterministic.
511a62669f1b phases: emit phases to pushkey protocol in deterministic order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31351
diff changeset
793 keys = util.sortdict()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
794 value = b'%i' % draft
34816
e2c42f751b06 phase: filter out non-draft item in "draft root"
Boris Feld <boris.feld@octobus.net>
parents: 34710
diff changeset
795 cl = repo.unfiltered().changelog
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
796 for root in repo._phasecache._phaseroots[draft]:
34816
e2c42f751b06 phase: filter out non-draft item in "draft root"
Boris Feld <boris.feld@octobus.net>
parents: 34710
diff changeset
797 if repo._phasecache.phase(repo, cl.rev(root)) <= draft:
e2c42f751b06 phase: filter out non-draft item in "draft root"
Boris Feld <boris.feld@octobus.net>
parents: 34710
diff changeset
798 keys[hex(root)] = value
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
799
25624
f0745da75056 publishing: use new helper method
Matt Mackall <mpm@selenic.com>
parents: 25614
diff changeset
800 if repo.publishing():
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
801 # 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
802 # 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
803 # 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
804 # push phase boundary
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
805 #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
806 # 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
807 # 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
808 # 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
809 #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
810 # 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
811 # 2) repo B make changeset X public
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
812 # 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
813 # X as now public should
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
814 #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
815 # 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
816 # client phase data.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
817 keys[b'publishing'] = b'True'
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
818 return keys
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
819
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
820
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
821 def pushphase(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
822 repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
823 nhex: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
824 oldphasestr: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
825 newphasestr: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
826 ) -> bool:
17535
63e302be813f en-us: serialization
timeless@mozdev.org
parents: 17205
diff changeset
827 """List phases root for serialization over pushkey"""
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
828 repo = repo.unfiltered()
27861
3315a9c2019c with: use context manager for lock in pushphase
Bryan O'Sullivan <bryano@fb.com>
parents: 26909
diff changeset
829 with repo.lock():
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
830 currentphase = repo[nhex].phase()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
831 newphase = abs(int(newphasestr)) # let's avoid negative index surprise
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
832 oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
833 if currentphase == oldphase and newphase < oldphase:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
834 with repo.transaction(b'pushkey-phase') as tr:
27861
3315a9c2019c with: use context manager for lock in pushphase
Bryan O'Sullivan <bryano@fb.com>
parents: 26909
diff changeset
835 advanceboundary(repo, tr, newphase, [bin(nhex)])
32841
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32000
diff changeset
836 return True
16051
2aa5b51f310f phases: don't complain if cset is already public on pushkey (issue3230)
Matt Mackall <mpm@selenic.com>
parents: 16030
diff changeset
837 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
838 # raced, but got correct result
32841
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32000
diff changeset
839 return True
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
840 else:
32841
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32000
diff changeset
841 return False
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
842
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
843
33043
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
844 def subsetphaseheads(repo, subset):
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
845 """Finds the phase heads for a subset of a history
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
846
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
847 Returns a list indexed by phase number where each item is a list of phase
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
848 head nodes.
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
849 """
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
850 cl = repo.changelog
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
851
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
852 headsbyphase = {i: [] for i in allphases}
50426
385a4f8056e5 bundle: include required phases when saving a bundle (issue6794)
Jason R. Coombs <jaraco@jaraco.com>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50421
diff changeset
853 for phase in allphases:
385a4f8056e5 bundle: include required phases when saving a bundle (issue6794)
Jason R. Coombs <jaraco@jaraco.com>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50421
diff changeset
854 revset = b"heads(%%ln & _phase(%d))" % phase
33043
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
855 headsbyphase[phase] = [cl.node(r) for r in repo.revs(revset, subset)]
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
856 return headsbyphase
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
857
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
858
34328
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34327
diff changeset
859 def updatephases(repo, trgetter, headsbyphase):
33043
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
860 """Updates the repo with the given phase heads"""
45116
361a7444bc41 phases: updatephases should not skip internal phase
Joerg Sonnenberger <joerg@bec.de>
parents: 45114
diff changeset
861 # Now advance phase boundaries of all phases
34328
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34327
diff changeset
862 #
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34327
diff changeset
863 # run the update (and fetch transaction) only if there are actually things
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34327
diff changeset
864 # to update. This avoid creating empty transaction during no-op operation.
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34327
diff changeset
865
45116
361a7444bc41 phases: updatephases should not skip internal phase
Joerg Sonnenberger <joerg@bec.de>
parents: 45114
diff changeset
866 for phase in allphases:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
867 revset = b'%ln - _phase(%s)'
39320
278eb4541758 phases: simplify revset in updatephases
Boris Feld <boris.feld@octobus.net>
parents: 39302
diff changeset
868 heads = [c.node() for c in repo.set(revset, headsbyphase[phase], phase)]
34328
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34327
diff changeset
869 if heads:
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34327
diff changeset
870 advanceboundary(repo, trgetter(), phase, heads)
33043
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32841
diff changeset
871
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
872
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
873 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
874 """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
875
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
876 * 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
877 * 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
878
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
879 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
880 """
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
881 repo = repo.unfiltered()
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
882 # 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
883 draftroots = []
43586
9970412d2ce3 index: use `index.has_node` in `analyzeremotephases`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
884 has_node = repo.changelog.index.has_node # to filter unknown nodes
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
885 for nhex, phase in roots.items():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
886 if nhex == b'publishing': # ignore data related to publish option
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
887 continue
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
888 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
889 phase = int(phase)
28174
f16b84b1e40e phases: use constants for phase values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27874
diff changeset
890 if phase == public:
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46683
diff changeset
891 if node != repo.nullid:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
892 repo.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
893 _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
894 b'ignoring inconsistent public root'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
895 b' from remote: %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
896 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
897 % nhex
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
898 )
28174
f16b84b1e40e phases: use constants for phase values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27874
diff changeset
899 elif phase == draft:
43586
9970412d2ce3 index: use `index.has_node` in `analyzeremotephases`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
900 if has_node(node):
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
901 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
902 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
903 repo.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
904 _(b'ignoring unexpected root from remote: %i %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
905 % (phase, nhex)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
906 )
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
907 # compute heads
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
908 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
909 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
910
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
911
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
912 class remotephasessummary:
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
913 """summarize phase information on the remote side
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
914
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
915 :publishing: True is the remote is publishing
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
916 :publicheads: list of remote public phase heads (nodes)
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
917 :draftheads: list of remote draft phase heads (nodes)
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
918 :draftroots: list of remote draft phase root (nodes)
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
919 """
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
920
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
921 def __init__(self, repo, remotesubset, remoteroots):
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
922 unfi = repo.unfiltered()
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
923 self._allremoteroots = remoteroots
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
924
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
925 self.publishing = remoteroots.get(b'publishing', False)
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
926
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
927 ana = analyzeremotephases(repo, remotesubset, remoteroots)
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
928 self.publicheads, self.draftroots = ana
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
929 # Get the list of all "heads" revs draft on remote
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
930 dheads = unfi.set(b'heads(%ln::%ln)', self.draftroots, remotesubset)
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
931 self.draftheads = [c.node() for c in dheads]
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
932
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
933
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
934 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
935 """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
936
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
937 * `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
938 * `roots`: define the second we subtract from the first"""
38773
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
939 # prevent an import cycle
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
940 # phases > dagop > patch > copies > scmutil > obsolete > obsutil > phases
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
941 from . import dagop
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
942
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
943 repo = repo.unfiltered()
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
944 cl = repo.changelog
43604
505a2bc53759 index: use `index.get_rev` in `phases.newheads`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43587
diff changeset
945 rev = cl.index.get_rev
38773
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
946 if not roots:
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
947 return heads
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46683
diff changeset
948 if not heads or heads == [repo.nullid]:
38773
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
949 return []
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
950 # The logic operated on revisions, convert arguments early for convenience
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46683
diff changeset
951 new_heads = {rev(n) for n in heads if n != repo.nullid}
38773
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
952 roots = [rev(n) for n in roots]
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
953 # compute the area we need to remove
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
954 affected_zone = repo.revs(b"(%ld::%ld)", roots, new_heads)
38773
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
955 # heads in the area are no longer heads
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
956 new_heads.difference_update(affected_zone)
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
957 # revisions in the area have children outside of it,
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
958 # They might be new heads
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
959 candidates = repo.revs(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
960 b"parents(%ld + (%ld and merge())) and not null", roots, affected_zone
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
961 )
38773
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
962 candidates -= affected_zone
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
963 if new_heads or candidates:
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
964 # remove candidate that are ancestors of other heads
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
965 new_heads.update(candidates)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
966 prunestart = repo.revs(b"parents(%ld) and not null", new_heads)
38773
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
967 pruned = dagop.reachableroots(repo, candidates, prunestart)
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
968 new_heads.difference_update(pruned)
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
969
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 38772
diff changeset
970 return pycompat.maplist(cl.node, sorted(new_heads))
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
971
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
972
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
973 def newcommitphase(ui: "uimod.ui") -> int:
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
974 """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
975
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
976 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
977
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
978 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
979 v = ui.config(b'phases', b'new-commit')
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
980 try:
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
981 return phasenumber2[v]
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
982 except KeyError:
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
983 raise error.ConfigError(
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
984 _(b"phases.new-commit: not a valid phase name ('%s')") % v
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
985 )
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
986
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
987
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
988 def hassecret(repo: "localrepo.localrepository") -> bool:
17671
fdd0fc046cf1 clfilter: introduce a `hassecret` function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17537
diff changeset
989 """utility function that check if a repo have any secret changeset."""
51401
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51399
diff changeset
990 return bool(repo._phasecache._phaseroots[secret])
34710
cdf833d7de98 phase: add a dedicated txnclose-phase hook
Boris Feld <boris.feld@octobus.net>
parents: 34563
diff changeset
991
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40627
diff changeset
992
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
993 def preparehookargs(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
994 node: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
995 old: Optional[int],
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
996 new: Optional[int],
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
997 ) -> Dict[bytes, bytes]:
34710
cdf833d7de98 phase: add a dedicated txnclose-phase hook
Boris Feld <boris.feld@octobus.net>
parents: 34563
diff changeset
998 if old is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
999 old = b''
34710
cdf833d7de98 phase: add a dedicated txnclose-phase hook
Boris Feld <boris.feld@octobus.net>
parents: 34563
diff changeset
1000 else:
34876
eb1b964b354b phases: pass phase names to hooks instead of internal values
Kevin Bullock <kbullock+mercurial@ringworld.org>
parents: 34819
diff changeset
1001 old = phasenames[old]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1002 return {b'node': node, b'oldphase': old, b'phase': phasenames[new]}