mercurial/phases.py
author Augie Fackler <augie@google.com>
Sat, 11 Mar 2017 20:53:20 -0500
changeset 31351 1470b0f771c8
parent 31162 b7cef987356d
child 32000 511a62669f1b
permissions -rw-r--r--
phases: explicitly evaluate list returned by map On Python 3 map() returns a generator, which bool()s to true even if it had an empty input set. Work around this by using list() on the map() result.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
from __future__ import absolute_import
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   104
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
   105
import errno
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   106
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   107
from .i18n import _
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   108
from .node import (
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   109
    bin,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   110
    hex,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   111
    nullid,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   112
    nullrev,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   113
    short,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   114
)
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   115
from . import (
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   116
    error,
31036
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   117
    smartset,
31073
6afd8a87a657 phases: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31036
diff changeset
   118
    txnutil,
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   119
)
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   120
15818
57241845a4bb phases: store phase values in constant instead of using raw integer
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15705
diff changeset
   121
allphases = public, draft, secret = range(3)
15417
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   122
trackedphases = allphases[1:]
15821
e3ee8bf5d0cc phases: add list of string to access phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15818
diff changeset
   123
phasenames = ['public', 'draft', 'secret']
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   124
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   125
def _readroots(repo, phasedefaults=None):
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   126
    """Read phase roots from disk
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   127
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   128
    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
   129
    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
   130
    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
   131
    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
   132
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   133
    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
   134
    what is being stored.
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   135
    """
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
   136
    repo = repo.unfiltered()
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   137
    dirty = False
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   138
    roots = [set() for i in allphases]
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   139
    try:
31073
6afd8a87a657 phases: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31036
diff changeset
   140
        f, pending = txnutil.trypending(repo.root, repo.svfs, 'phaseroots')
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   141
        try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   142
            for line in f:
16588
72319bfd7966 phases: line.strip().split() == line.split()
Martin Geisler <mg@aragost.com>
parents: 16535
diff changeset
   143
                phase, nh = line.split()
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   144
                roots[int(phase)].add(bin(nh))
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   145
        finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   146
            f.close()
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25624
diff changeset
   147
    except IOError as inst:
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
   148
        if inst.errno != errno.ENOENT:
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
   149
            raise
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   150
        if phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   151
            for f in phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   152
                roots = f(repo, roots)
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   153
        dirty = True
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   154
    return roots, dirty
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   155
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   156
class phasecache(object):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   157
    def __init__(self, repo, phasedefaults, _load=True):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   158
        if _load:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   159
            # Cheap trick to allow shallow-copy without copy module
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   160
            self.phaseroots, self.dirty = _readroots(repo, phasedefaults)
18220
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   161
            self._phaserevs = None
25190
22438cfd11b5 phases: add set per phase in C phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24599
diff changeset
   162
            self._phasesets = None
18220
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   163
            self.filterunknown(repo)
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23631
diff changeset
   164
            self.opener = repo.svfs
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   165
31036
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   166
    def getrevset(self, repo, phases):
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   167
        """return a smartset for the given phases"""
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   168
        self.loadphaserevs(repo) # ensure phase's sets are loaded
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   169
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   170
        if self._phasesets and all(self._phasesets[p] is not None
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   171
                                   for p in phases):
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   172
            # fast path - use _phasesets
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   173
            revs = self._phasesets[phases[0]]
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   174
            if len(phases) > 1:
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   175
                revs = revs.copy() # only copy when needed
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   176
                for p in phases[1:]:
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   177
                    revs.update(self._phasesets[p])
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   178
            if repo.changelog.filteredrevs:
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   179
                revs = revs - repo.changelog.filteredrevs
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   180
            return smartset.baseset(revs)
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   181
        else:
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   182
            # slow path - enumerate all revisions
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   183
            phase = self.phase
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   184
            revs = (r for r in repo if phase(repo, r) in phases)
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   185
            return smartset.generatorset(revs, iterasc=True)
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30639
diff changeset
   186
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   187
    def copy(self):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   188
        # Shallow copy meant to ensure isolation in
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   189
        # advance/retractboundary(), nothing more.
23631
b8260abfeb7d bundlerepo: implement safe phasecache
Eric Sumner <ericsumner@fb.com>
parents: 23361
diff changeset
   190
        ph = self.__class__(None, None, _load=False)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   191
        ph.phaseroots = self.phaseroots[:]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   192
        ph.dirty = self.dirty
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   193
        ph.opener = self.opener
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   194
        ph._phaserevs = self._phaserevs
25592
dd2349ccfa66 phase: also copy phase's sets when copying phase cache
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25527
diff changeset
   195
        ph._phasesets = self._phasesets
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   196
        return ph
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   197
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   198
    def replace(self, phcache):
25613
a13c18c14ade phase: document the replace method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25611
diff changeset
   199
        """replace all values in 'self' with content of phcache"""
25614
6c48f012d37e phase: remove a 'for x in "foo bar".split()' idiom in phasecache.replace
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25613
diff changeset
   200
        for a in ('phaseroots', 'dirty', 'opener', '_phaserevs', '_phasesets'):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   201
            setattr(self, a, getattr(phcache, a))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   202
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
   203
    def _getphaserevsnative(self, repo):
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   204
        repo = repo.unfiltered()
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   205
        nativeroots = []
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   206
        for phase in trackedphases:
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   207
            nativeroots.append(map(repo.changelog.rev, self.phaseroots[phase]))
25527
262e6ad93885 phases: really fix native phase computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25190
diff changeset
   208
        return repo.changelog.computephases(nativeroots)
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   209
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
   210
    def _computephaserevspure(self, repo):
24519
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   211
        repo = repo.unfiltered()
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   212
        revs = [public] * len(repo.changelog)
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   213
        self._phaserevs = revs
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   214
        self._populatephaseroots(repo)
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   215
        for phase in trackedphases:
31351
1470b0f771c8 phases: explicitly evaluate list returned by map
Augie Fackler <augie@google.com>
parents: 31162
diff changeset
   216
            roots = list(map(repo.changelog.rev, self.phaseroots[phase]))
24519
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   217
            if roots:
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   218
                for rev in roots:
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   219
                    revs[rev] = phase
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   220
                for rev in repo.changelog.descendants(roots):
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   221
                    revs[rev] = phase
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   222
25611
d89045a66e01 phase: rename getphaserevs to loadphaserevs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25594
diff changeset
   223
    def loadphaserevs(self, repo):
d89045a66e01 phase: rename getphaserevs to loadphaserevs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25594
diff changeset
   224
        """ensure phase information is loaded in the object"""
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
   225
        if self._phaserevs is None:
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   226
            try:
31162
b7cef987356d phases: remove experimental.nativephaseskillswitch
Jun Wu <quark@fb.com>
parents: 31073
diff changeset
   227
                res = self._getphaserevsnative(repo)
b7cef987356d phases: remove experimental.nativephaseskillswitch
Jun Wu <quark@fb.com>
parents: 31073
diff changeset
   228
                self._phaserevs, self._phasesets = res
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   229
            except AttributeError:
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
   230
                self._computephaserevspure(repo)
22894
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   231
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
   232
    def invalidate(self):
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
   233
        self._phaserevs = None
25593
9e551f155810 phase: invalidate the phase's set cache alongside the revs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25592
diff changeset
   234
        self._phasesets = None
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   235
22894
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   236
    def _populatephaseroots(self, repo):
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   237
        """Fills the _phaserevs cache with phases for the roots.
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   238
        """
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   239
        cl = repo.changelog
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   240
        phaserevs = self._phaserevs
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   241
        for phase in trackedphases:
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   242
            roots = map(cl.rev, self.phaseroots[phase])
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   243
            for root in roots:
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   244
                phaserevs[root] = phase
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   245
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   246
    def phase(self, repo, rev):
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17205
diff changeset
   247
        # We need a repo argument here to be able to build _phaserevs
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   248
        # if necessary. The repository instance is not stored in
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   249
        # phasecache to avoid reference cycles. The changelog instance
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   250
        # is not stored because it is a filecache() property and can
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   251
        # be replaced without us being notified.
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   252
        if rev == nullrev:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   253
            return public
19984
7d5e7799a29f rebase: fix rebase aborts when 'tip-1' is public (issue4082)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   254
        if rev < nullrev:
7d5e7799a29f rebase: fix rebase aborts when 'tip-1' is public (issue4082)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   255
            raise ValueError(_('cannot lookup negative revision'))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   256
        if self._phaserevs is None or rev >= len(self._phaserevs):
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
   257
            self.invalidate()
25611
d89045a66e01 phase: rename getphaserevs to loadphaserevs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25594
diff changeset
   258
            self.loadphaserevs(repo)
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   259
        return self._phaserevs[rev]
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   260
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   261
    def write(self):
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   262
        if not self.dirty:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   263
            return
29303
3a2357c31d2a phases: make writing phaseroots file out avoid ambiguity of file stat
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28174
diff changeset
   264
        f = self.opener('phaseroots', 'w', atomictemp=True, checkambig=True)
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   265
        try:
22079
5dcc58649b1a phase: extract the phaseroots serialization in a dedicated method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22070
diff changeset
   266
            self._write(f)
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   267
        finally:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   268
            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
   269
5dcc58649b1a phase: extract the phaseroots serialization in a dedicated method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22070
diff changeset
   270
    def _write(self, fp):
5dcc58649b1a phase: extract the phaseroots serialization in a dedicated method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22070
diff changeset
   271
        for phase, roots in enumerate(self.phaseroots):
5dcc58649b1a phase: extract the phaseroots serialization in a dedicated method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22070
diff changeset
   272
            for h in roots:
5dcc58649b1a phase: extract the phaseroots serialization in a dedicated method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22070
diff changeset
   273
                fp.write('%i %s\n' % (phase, hex(h)))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   274
        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
   275
22080
37f46575d9c2 phase: attach phase to the transaction instead of the lock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22079
diff changeset
   276
    def _updateroots(self, phase, newroots, tr):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   277
        self.phaseroots[phase] = newroots
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
   278
        self.invalidate()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   279
        self.dirty = True
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   280
22080
37f46575d9c2 phase: attach phase to the transaction instead of the lock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22079
diff changeset
   281
        tr.addfilegenerator('phase', ('phaseroots',), self._write)
22940
e803186296ab phases: inform transaction-related hooks that a phase was moved
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22894
diff changeset
   282
        tr.hookargs['phases_moved'] = '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
   283
22069
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22052
diff changeset
   284
    def advanceboundary(self, repo, tr, targetphase, nodes):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   285
        # 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
   286
        # phaseroots values, replace them.
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   287
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
   288
        repo = repo.unfiltered()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   289
        delroots = [] # set of root deleted by this path
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   290
        for phase in xrange(targetphase + 1, len(allphases)):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   291
            # filter nodes that are not in a compatible phase already
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   292
            nodes = [n for n in nodes
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   293
                     if self.phase(repo, repo[n].rev()) >= phase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   294
            if not nodes:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   295
                break # no roots to move anymore
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   296
            olds = self.phaseroots[phase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   297
            roots = set(ctx.node() for ctx in repo.set(
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   298
                    'roots((%ln::) - (%ln::%ln))', olds, olds, nodes))
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   299
            if olds != roots:
22080
37f46575d9c2 phase: attach phase to the transaction instead of the lock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22079
diff changeset
   300
                self._updateroots(phase, roots, tr)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   301
                # 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
   302
                delroots.extend(olds - roots)
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   303
            # declare deleted root in the target phase
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   304
            if targetphase != 0:
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
   305
                self.retractboundary(repo, tr, targetphase, delroots)
18105
312262ebc223 cache: group obscache and revsfiltercache invalidation in a single function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18101
diff changeset
   306
        repo.invalidatevolatilesets()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   307
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
   308
    def retractboundary(self, repo, tr, targetphase, nodes):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   309
        # 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
   310
        # phaseroots values, replace them.
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   311
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
   312
        repo = repo.unfiltered()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   313
        currentroots = self.phaseroots[targetphase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   314
        newroots = [n for n in nodes
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   315
                    if self.phase(repo, repo[n].rev()) < targetphase]
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   316
        if newroots:
16659
58edd786e96f phase: make if abort on nullid for the good reason
Patrick Mezard <patrick@mezard.eu>
parents: 16658
diff changeset
   317
            if nullid in newroots:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25966
diff changeset
   318
                raise error.Abort(_('cannot change null revision phase'))
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   319
            currentroots = currentroots.copy()
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   320
            currentroots.update(newroots)
26909
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   321
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   322
            # 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
   323
            # retracted.
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   324
            minnewroot = min(repo[n].rev() for n in newroots)
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   325
            aboveroots = [n for n in currentroots
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   326
                          if repo[n].rev() >= minnewroot]
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   327
            updatedroots = repo.set('roots(%ln::)', aboveroots)
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   328
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   329
            finalroots = set(n for n in currentroots if repo[n].rev() <
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   330
                             minnewroot)
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   331
            finalroots.update(ctx.node() for ctx in updatedroots)
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   332
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   333
            self._updateroots(targetphase, finalroots, tr)
18105
312262ebc223 cache: group obscache and revsfiltercache invalidation in a single function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18101
diff changeset
   334
        repo.invalidatevolatilesets()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   335
18220
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   336
    def filterunknown(self, repo):
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   337
        """remove unknown nodes from the phase boundary
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   338
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   339
        Nothing is lost as unknown nodes only hold data for their descendants.
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   340
        """
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   341
        filtered = False
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   342
        nodemap = repo.changelog.nodemap # to filter unknown nodes
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   343
        for phase, nodes in enumerate(self.phaseroots):
20550
1716a2671ec7 phases: make order of debug output 'removing unknown node' deterministic
Mads Kiilerich <madski@unity3d.com>
parents: 19984
diff changeset
   344
            missing = sorted(node for node in nodes if node not in nodemap)
18220
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   345
            if missing:
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   346
                for mnode in missing:
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   347
                    repo.ui.debug(
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   348
                        'removing unknown node %s from %i-phase boundary\n'
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   349
                        % (short(mnode), phase))
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   350
                nodes.symmetric_difference_update(missing)
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   351
                filtered = True
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   352
        if filtered:
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   353
            self.dirty = True
18983
31bcc5112191 destroyed: invalidate phraserevs cache in all case (issue3858)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18220
diff changeset
   354
        # filterunknown is called by repo.destroyed, we may have no changes in
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 18983
diff changeset
   355
        # root but phaserevs contents is certainly invalid (or at least we
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 18983
diff changeset
   356
        # have not proper way to check that). related to issue 3858.
18983
31bcc5112191 destroyed: invalidate phraserevs cache in all case (issue3858)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18220
diff changeset
   357
        #
31bcc5112191 destroyed: invalidate phraserevs cache in all case (issue3858)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18220
diff changeset
   358
        # The other caller is __init__ that have no _phaserevs initialized
31bcc5112191 destroyed: invalidate phraserevs cache in all case (issue3858)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18220
diff changeset
   359
        # anyway. If this change we should consider adding a dedicated
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 18983
diff changeset
   360
        # "destroyed" function to phasecache or a proper cache key mechanism
18983
31bcc5112191 destroyed: invalidate phraserevs cache in all case (issue3858)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18220
diff changeset
   361
        # (see branchmap one)
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
   362
        self.invalidate()
18220
767d1c602c8b phases: make _filterunknown a member function of phasecache
Idan Kamara <idankk86@gmail.com>
parents: 18105
diff changeset
   363
22069
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22052
diff changeset
   364
def advanceboundary(repo, tr, targetphase, nodes):
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   365
    """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
   366
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
   367
    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
   368
    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
   369
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   370
    Simplify boundary to contains phase roots only."""
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   371
    phcache = repo._phasecache.copy()
22069
616a455b02ca phase: add a transaction argument to advanceboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22052
diff changeset
   372
    phcache.advanceboundary(repo, tr, targetphase, nodes)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   373
    repo._phasecache.replace(phcache)
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   374
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
   375
def retractboundary(repo, tr, targetphase, nodes):
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
   376
    """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
   377
    necessary.
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   378
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
   379
    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
   380
    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
   381
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   382
    Simplify boundary to contains phase roots only."""
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   383
    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
   384
    phcache.retractboundary(repo, tr, targetphase, nodes)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   385
    repo._phasecache.replace(phcache)
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   386
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   387
def listphases(repo):
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
   388
    """List phases root for serialization over pushkey"""
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   389
    keys = {}
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
   390
    value = '%i' % draft
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   391
    for root in repo._phasecache.phaseroots[draft]:
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
   392
        keys[hex(root)] = value
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
   393
25624
f0745da75056 publishing: use new helper method
Matt Mackall <mpm@selenic.com>
parents: 25614
diff changeset
   394
    if repo.publishing():
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
   395
        # 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
   396
        # 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
   397
        # 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
   398
        # push phase boundary
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   399
        #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
   400
        # 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
   401
        # 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
   402
        # 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
   403
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   404
        # 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
   405
        # 2) repo B make changeset X public
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
   406
        # 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
   407
        #    X as now public should
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   408
        #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
   409
        # 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
   410
        # client phase data.
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   411
        keys['publishing'] = 'True'
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   412
    return keys
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   413
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   414
def pushphase(repo, nhex, oldphasestr, newphasestr):
17535
63e302be813f en-us: serialization
timeless@mozdev.org
parents: 17205
diff changeset
   415
    """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
   416
    repo = repo.unfiltered()
27861
3315a9c2019c with: use context manager for lock in pushphase
Bryan O'Sullivan <bryano@fb.com>
parents: 26909
diff changeset
   417
    with repo.lock():
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   418
        currentphase = repo[nhex].phase()
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   419
        newphase = abs(int(newphasestr)) # let's avoid negative index surprise
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   420
        oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   421
        if currentphase == oldphase and newphase < oldphase:
27874
4ff0e2347ae6 with: use context manager for transaction in pushphase
Bryan O'Sullivan <bryano@fb.com>
parents: 27861
diff changeset
   422
            with repo.transaction('pushkey-phase') as tr:
27861
3315a9c2019c with: use context manager for lock in pushphase
Bryan O'Sullivan <bryano@fb.com>
parents: 26909
diff changeset
   423
                advanceboundary(repo, tr, newphase, [bin(nhex)])
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   424
            return 1
16051
2aa5b51f310f phases: don't complain if cset is already public on pushkey (issue3230)
Matt Mackall <mpm@selenic.com>
parents: 16030
diff changeset
   425
        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
   426
            # raced, but got correct result
2aa5b51f310f phases: don't complain if cset is already public on pushkey (issue3230)
Matt Mackall <mpm@selenic.com>
parents: 16030
diff changeset
   427
            return 1
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   428
        else:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   429
            return 0
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   430
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   431
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
   432
    """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
   433
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   434
    * 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
   435
    * 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
   436
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   437
    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
   438
    """
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
   439
    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
   440
    # 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
   441
    draftroots = []
15902
4252d9f08d7e phases: use nodemap to check for missing nodes
Sune Foldager <cryo@cyanite.org>
parents: 15892
diff changeset
   442
    nodemap = repo.changelog.nodemap # to filter unknown nodes
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   443
    for nhex, phase in roots.iteritems():
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   444
        if nhex == 'publishing': # ignore data related to publish option
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   445
            continue
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   446
        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
   447
        phase = int(phase)
28174
f16b84b1e40e phases: use constants for phase values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27874
diff changeset
   448
        if phase == public:
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
   449
            if node != nullid:
15953
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
   450
                repo.ui.warn(_('ignoring inconsistent public root'
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
   451
                               ' from remote: %s\n') % nhex)
28174
f16b84b1e40e phases: use constants for phase values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27874
diff changeset
   452
        elif phase == draft:
15902
4252d9f08d7e phases: use nodemap to check for missing nodes
Sune Foldager <cryo@cyanite.org>
parents: 15892
diff changeset
   453
            if node in nodemap:
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
   454
                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
   455
        else:
15953
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
   456
            repo.ui.warn(_('ignoring unexpected root from remote: %i %s\n')
52dc2b33d0be phase: fix warning text from invalid remote phase
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15948
diff changeset
   457
                         % (phase, nhex))
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   458
    # compute heads
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
   459
    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
   460
    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
   461
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
   462
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
   463
    """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
   464
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
   465
    * `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
   466
    * `roots`: define the second we subtract from the first"""
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
   467
    repo = repo.unfiltered()
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
   468
    revset = repo.set('heads((%ln + parents(%ln)) - (%ln::%ln))',
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
   469
                      heads, roots, roots, heads)
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
   470
    return [c.node() for c in revset]
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
   471
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   472
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   473
def newcommitphase(ui):
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   474
    """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
   475
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   476
    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
   477
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   478
    """
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   479
    v = ui.config('phases', 'new-commit', draft)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   480
    try:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   481
        return phasenames.index(v)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   482
    except ValueError:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   483
        try:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   484
            return int(v)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   485
        except ValueError:
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   486
            msg = _("phases.new-commit: not a valid phase name ('%s')")
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   487
            raise error.ConfigError(msg % v)
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
   488
17671
fdd0fc046cf1 clfilter: introduce a `hassecret` function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17537
diff changeset
   489
def hassecret(repo):
fdd0fc046cf1 clfilter: introduce a `hassecret` function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17537
diff changeset
   490
    """utility function that check if a repo have any secret changeset."""
fdd0fc046cf1 clfilter: introduce a `hassecret` function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17537
diff changeset
   491
    return bool(repo._phasecache.phaseroots[2])