mercurial/phases.py
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 06 Jan 2012 09:51:35 +0100
changeset 15818 57241845a4bb
parent 15705 e34f4d1f0dbb
child 15821 e3ee8bf5d0cc
permissions -rw-r--r--
phases: store phase values in constant instead of using raw integer Phases constant are named after the phase name. Usage of integer have been replaced by proper constant.
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
     9
    This software may be used and distributed according to the terms of the
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    10
    GNU General Public License version 2 or any later version.
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    20
A 'changeset phases' is an indicator that tells us how a changeset is
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    21
manipulated and communicated. The details of each phase is described below,
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    22
here we describe the properties they have in common.
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    24
Like bookmarks, phases are not stored in history and thus are not permanent and
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    25
leave no audit trail.
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    27
First, no changeset can be in two phases at once. Phases are ordered, so they
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    28
can be considered from lowest to highest. The default, lowest phase is '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
    29
- this is the normal phase of existing changesets. A child changeset can not be
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    30
in a lower phase than its parents.
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    39
local commits are draft by default
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    41
Phase movement and exchange
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    42
============================
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    44
Phase data are exchanged by pushkey on pull and push. Some server have a
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    45
publish option set, we call them publishing server. Pushing to such server make
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    46
draft changeset 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
    47
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
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
    49
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
* 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
    51
* pull 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
* publish and old server csets are seen as public by 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
    53
15705
e34f4d1f0dbb phases: update doc to mention secret phase
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15697
diff changeset
    54
* Any secret changeset seens in another repository is lowered to at least draft
e34f4d1f0dbb phases: update doc to mention secret phase
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15697
diff changeset
    55
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
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    57
Here is the final table summing up the 49 possible usecase of phase exchange:
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    58
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
                           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
    60
                  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
    61
                 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
    62
    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
    63
    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
    64
     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
    65
     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
    66
    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
    67
     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
    68
    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
    69
    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
    70
     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
    71
     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
    72
     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
    73
    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
    74
     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
    75
     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
    76
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
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
    78
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
    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
    80
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
    * 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
    82
    * 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
    83
    * D = 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
    84
    * X = not tracked (ie: the old client or server has no internal way of
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    85
          recording the 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
    86
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
    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
    88
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
    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
    91
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
    "When a new client pushes a draft changeset (D) to a publishing 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
    93
    where it's not present (N), it's marked public on both sides (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
    94
7fba5a245acc phases: change publish behavior to only alter behavior when server.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15649
diff changeset
    95
Note: old client behave as publish server with Draft only content
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
- 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
    97
- 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
    98
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
"""
15417
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   100
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
   101
import errno
15456
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   102
from node import nullid, bin, hex, short
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   103
from i18n import _
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   104
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
   105
allphases = public, draft, secret = range(3)
15417
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   106
trackedphases = allphases[1:]
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   107
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   108
def readroots(repo):
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   109
    """Read phase roots from disk"""
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   110
    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
   111
    roots[0].add(nullid)
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   112
    try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   113
        f = repo.sopener('phaseroots')
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   114
        try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   115
            for line in f:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   116
                phase, nh = line.strip().split()
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   117
                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
   118
        finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   119
            f.close()
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
   120
    except IOError, inst:
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
   121
        if inst.errno != errno.ENOENT:
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
   122
            raise
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   123
    return roots
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   124
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   125
def writeroots(repo):
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   126
    """Write phase roots from disk"""
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   127
    f = repo.sopener('phaseroots', 'w', atomictemp=True)
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   128
    try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   129
        for phase, roots in enumerate(repo._phaseroots):
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   130
            for h in roots:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   131
                f.write('%i %s\n' % (phase, hex(h)))
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   132
        repo._dirtyphases = False
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   133
    finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   134
        f.close()
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   135
15456
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   136
def filterunknown(repo, phaseroots=None):
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   137
    """remove unknown nodes from the phase boundary
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   138
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   139
    no data is lost as unknown node only old data for their descentants
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   140
    """
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   141
    if phaseroots is None:
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   142
        phaseroots = repo._phaseroots
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   143
    for phase, nodes in enumerate(phaseroots):
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   144
        missing = [node for node in nodes if node not in repo]
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   145
        if missing:
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   146
            for mnode in missing:
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   147
                msg = _('Removing unknown node %(n)s from %(p)i-phase boundary')
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   148
                repo.ui.debug(msg, {'n': short(mnode), 'p': phase})
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   149
            nodes.symmetric_difference_update(missing)
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   150
            repo._dirtyphases = True
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
   151
15481
0b7ce2f739fb phases: rename moveboundary into advance boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15480
diff changeset
   152
def advanceboundary(repo, targetphase, nodes):
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   153
    """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
   154
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   155
    This function move boundary *forward* this means that all nodes are set
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   156
    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
   157
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   158
    Simplify boundary to contains phase roots only."""
15695
1b9dcf2eb011 phases: fix advanceboundary behavior when targetphase !=0
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15659
diff changeset
   159
    delroots = [] # set of root deleted by this path
15480
7d4f364c980b phases: remove underbar into target_phase argument
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15456
diff changeset
   160
    for phase in xrange(targetphase + 1, len(allphases)):
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   161
        # filter nodes that are not in a compatible phase already
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   162
        # XXX rev phase cache might have been invalidated by a previous loop
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   163
        # XXX we need to be smarter here
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   164
        nodes = [n for n in nodes if repo[n].phase() >= phase]
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   165
        if not nodes:
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   166
            break # no roots to move anymore
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   167
        roots = repo._phaseroots[phase]
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   168
        olds = roots.copy()
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   169
        ctxs = list(repo.set('roots((%ln::) - (%ln::%ln))', olds, olds, nodes))
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   170
        roots.clear()
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   171
        roots.update(ctx.node() for ctx in ctxs)
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   172
        if olds != roots:
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   173
            # invalidate cache (we probably could be smarter here
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   174
            if '_phaserev' in vars(repo):
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   175
                del repo._phaserev
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
   176
            repo._dirtyphases = True
15695
1b9dcf2eb011 phases: fix advanceboundary behavior when targetphase !=0
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15659
diff changeset
   177
            # some roots may need to be declared for lower phases
1b9dcf2eb011 phases: fix advanceboundary behavior when targetphase !=0
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15659
diff changeset
   178
            delroots.extend(olds - roots)
1b9dcf2eb011 phases: fix advanceboundary behavior when targetphase !=0
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15659
diff changeset
   179
        # declare deleted root in the target phase
1b9dcf2eb011 phases: fix advanceboundary behavior when targetphase !=0
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15659
diff changeset
   180
        if targetphase != 0:
1b9dcf2eb011 phases: fix advanceboundary behavior when targetphase !=0
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15659
diff changeset
   181
            retractboundary(repo, targetphase, delroots)
1b9dcf2eb011 phases: fix advanceboundary behavior when targetphase !=0
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15659
diff changeset
   182
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   183
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   184
def retractboundary(repo, targetphase, nodes):
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   185
    """Set nodes back to a phase changing other nodes phases if necessary.
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   186
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   187
    This function move boundary *backward* this means that all nodes are set
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   188
    in the target phase or kept in a *higher* phase.
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   189
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   190
    Simplify boundary to contains phase roots only."""
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   191
    currentroots = repo._phaseroots[targetphase]
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   192
    newroots = [n for n in nodes if repo[n].phase() < targetphase]
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   193
    if newroots:
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   194
        currentroots.update(newroots)
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   195
        ctxs = repo.set('roots(%ln::)', currentroots)
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   196
        currentroots.intersection_update(ctx.node() for ctx in ctxs)
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   197
        if '_phaserev' in vars(repo):
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   198
            del repo._phaserev
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   199
        repo._dirtyphases = True
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
   200
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   201
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   202
def listphases(repo):
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   203
    """List phases root for serialisation over pushkey"""
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   204
    keys = {}
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   205
    for phase in trackedphases:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   206
        for root in repo._phaseroots[phase]:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   207
            keys[hex(root)] = '%i' % phase
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   208
    if repo.ui.configbool('phases', 'publish', True):
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   209
        # Add an extra data to let remote know we are a publishing repo.
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   210
        # Publishing repo can't just pretend they are old repo. When pushing to
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   211
        # a publishing repo, the client still need to push phase boundary
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   212
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   213
        # Push do not only push changeset. It also push phase data. New
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   214
        # phase data may apply to common changeset which won't be push (as they
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   215
        # are common).  Here is a very simple example:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   216
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   217
        # 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
   218
        # 2) repo B make changeset X public
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   219
        # 3) repo B push to repo A. X is not pushed but the data that X as now
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   220
        #    public should
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   221
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   222
        # The server can't handle it on it's own as it has no idea of client
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   223
        # phase data.
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   224
        keys['publishing'] = 'True'
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   225
    return keys
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   226
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   227
def pushphase(repo, nhex, oldphasestr, newphasestr):
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   228
    """List phases root for serialisation over pushkey"""
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   229
    lock = repo.lock()
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   230
    try:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   231
        currentphase = repo[nhex].phase()
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   232
        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
   233
        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
   234
        if currentphase == oldphase and newphase < oldphase:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   235
            advanceboundary(repo, newphase, [bin(nhex)])
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   236
            return 1
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   237
        else:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   238
            return 0
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   239
    finally:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   240
        lock.release()
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   241
15697
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   242
def visibleheads(repo):
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   243
    """return the set of visible head of this repo"""
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   244
    # XXX we want a cache on this
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
   245
    sroots = repo._phaseroots[secret]
15697
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   246
    if sroots:
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   247
        # XXX very slow revset. storing heads or secret "boundary" would help.
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   248
        revset = repo.set('heads(not (%ln::))', sroots)
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   249
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   250
        vheads = [ctx.node() for ctx in revset]
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   251
        if not vheads:
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   252
            vheads.append(nullid)
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   253
    else:
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   254
        vheads = repo.heads()
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   255
    return vheads
21eb048edc19 phases: add a function to compute visible heads
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15696
diff changeset
   256
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   257
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
   258
    """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
   259
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   260
    * 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
   261
    * 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
   262
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   263
    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
   264
    """
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   265
    # build list from dictionary
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   266
    phaseroots = [[] for p in allphases]
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   267
    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
   268
        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
   269
            continue
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   270
        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
   271
        phase = int(phase)
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   272
        if node in repo:
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   273
            phaseroots[phase].append(node)
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   274
    # compute heads
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   275
    phaseheads = [[] for p in allphases]
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   276
    for phase in allphases[:-1]:
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   277
        toproof = phaseroots[phase + 1]
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   278
        revset = repo.set('heads((%ln + parents(%ln)) - (%ln::%ln))',
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   279
                          subset, toproof, toproof, subset)
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   280
        phaseheads[phase].extend(c.node() for c in revset)
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   281
    return phaseheads, phaseroots
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   282