mercurial/phases.py
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 15 Dec 2011 02:18:24 +0100
changeset 15649 ca7c4254a21a
parent 15648 79cc89de5be1
child 15659 7fba5a245acc
permissions -rw-r--r--
phases: add a function to compute heads from root
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15417
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     1
# Mercurial phases support code
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     2
#
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     3
# Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     4
#                Logilab SA        <contact@logilab.fr>
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     5
#                Augie Fackler     <durin42@gmail.com>
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     6
#
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     7
# This software may be used and distributed according to the terms of the
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     8
# GNU General Public License version 2 or any later version.
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     9
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
    10
import errno
15456
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    11
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
    12
from i18n import _
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    13
15417
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    14
allphases = range(2)
5261140d9322 phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    15
trackedphases = allphases[1:]
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    16
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    17
def readroots(repo):
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    18
    """Read phase roots from disk"""
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    19
    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
    20
    roots[0].add(nullid)
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    21
    try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    22
        f = repo.sopener('phaseroots')
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    23
        try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    24
            for line in f:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    25
                phase, nh = line.strip().split()
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    26
                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
    27
        finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    28
            f.close()
15419
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
    29
    except IOError, inst:
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
    30
        if inst.errno != errno.ENOENT:
ccb7de21625a phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents: 15418
diff changeset
    31
            raise
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    32
    return roots
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    33
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    34
def writeroots(repo):
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    35
    """Write phase roots from disk"""
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    36
    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
    37
    try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    38
        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
    39
            for h in roots:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    40
                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
    41
        repo._dirtyphases = False
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    42
    finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
    43
        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
    44
15456
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    45
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
    46
    """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
    47
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    48
    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
    49
    """
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    50
    if phaseroots is None:
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    51
        phaseroots = repo._phaseroots
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    52
    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
    53
        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
    54
        if missing:
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    55
            for mnode in missing:
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    56
                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
    57
                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
    58
            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
    59
            repo._dirtyphases = True
abcaaf51d568 phases: handle unknown nodes in boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15454
diff changeset
    60
15481
0b7ce2f739fb phases: rename moveboundary into advance boundary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15480
diff changeset
    61
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
    62
    """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
    63
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
    64
    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
    65
    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
    66
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
    67
    Simplify boundary to contains phase roots only."""
15480
7d4f364c980b phases: remove underbar into target_phase argument
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15456
diff changeset
    68
    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
    69
        # 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
    70
        # 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
    71
        # 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
    72
        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
    73
        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
    74
            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
    75
        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
    76
        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
    77
        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
    78
        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
    79
        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
    80
        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
    81
            # 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
    82
            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
    83
                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
    84
            repo._dirtyphases = True
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
    85
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
    86
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
    87
    """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
    88
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
    89
    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
    90
    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
    91
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
    92
    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
    93
    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
    94
    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
    95
    if newroots:
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
    96
        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
    97
        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
    98
        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
    99
        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
   100
            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
   101
        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
   102
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   103
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   104
def listphases(repo):
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   105
    """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
   106
    keys = {}
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   107
    for phase in trackedphases:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   108
        for root in repo._phaseroots[phase]:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   109
            keys[hex(root)] = '%i' % phase
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   110
    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
   111
        # 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
   112
        # 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
   113
        # 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
   114
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   115
        # 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
   116
        # 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
   117
        # 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
   118
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   119
        # 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
   120
        # 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
   121
        # 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
   122
        #    public should
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   123
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   124
        # 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
   125
        # phase data.
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   126
        keys['publishing'] = 'True'
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   127
    return keys
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   128
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   129
def pushphase(repo, nhex, oldphasestr, newphasestr):
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   130
    """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
   131
    lock = repo.lock()
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   132
    try:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   133
        currentphase = repo[nhex].phase()
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   134
        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
   135
        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
   136
        if currentphase == oldphase and newphase < oldphase:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   137
            advanceboundary(repo, newphase, [bin(nhex)])
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   138
            return 1
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   139
        else:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   140
            return 0
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   141
    finally:
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
   142
        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
   143
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   144
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
   145
    """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
   146
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   147
    * 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
   148
    * 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
   149
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   150
    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
   151
    """
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   152
    # 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
   153
    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
   154
    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
   155
        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
   156
            continue
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
   157
        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
   158
        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
   159
        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
   160
            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
   161
    # 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
   162
    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
   163
    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
   164
        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
   165
        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
   166
                          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
   167
        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
   168
    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
   169