mercurial/phases.py
author Matt Harbison <matt_harbison@yahoo.com>
Thu, 26 Sep 2024 18:04:31 -0400
changeset 51921 382d9629cede
parent 51863 f4733654f144
permissions -rw-r--r--
interfaces: convert the dirstate zope interface to a Protocol class This is a small trial run for converting the repository interfaces enmasse, in the same series of steps. I'm not sure that this current code is valid (it has zope attribute fields, and it's missing all of the `self` args on its functions, but that was the previous state of things, and made PyCharm really unhappy). But it will be easier to review the repository interface changes if this change is separate from adding `self` and dropping the zope attributes all over. Having an empty constructor in a protocol is weird. I'm not sure if these args should be converted to fields that all subclasses would have, and comments around existing attributes say some should be going away. Comment it out for now so that it's not in the way, but also not forgotten.
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
51863
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51811
diff changeset
   103
from __future__ import annotations
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   104
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   105
import heapq
34319
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   106
import struct
51285
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   107
import typing
51404
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   108
import weakref
51285
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   109
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   110
from typing import (
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   111
    Any,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   112
    Callable,
51580
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
   113
    Collection,
51285
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   114
    Dict,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   115
    Iterable,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   116
    List,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   117
    Optional,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   118
    Set,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   119
    Tuple,
51811
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   120
    overload,
51285
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   121
)
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   122
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   123
from .i18n import _
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   124
from .node import (
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   125
    bin,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   126
    hex,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   127
    nullrev,
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   128
    short,
44004
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43730
diff changeset
   129
    wdirrev,
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   130
)
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   131
from . import (
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   132
    error,
45372
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45356
diff changeset
   133
    requirements,
31016
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30634
diff changeset
   134
    smartset,
31053
6afd8a87a657 phases: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31016
diff changeset
   135
    txnutil,
32000
511a62669f1b phases: emit phases to pushkey protocol in deterministic order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31342
diff changeset
   136
    util,
25966
f14cea32e1d4 phases: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   137
)
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   138
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   139
Phaseroots = Dict[int, Set[int]]
51411
774e4eff6e47 phases: type annotation for `_phasesets`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51410
diff changeset
   140
PhaseSets = Dict[int, Set[int]]
51285
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   141
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   142
if typing.TYPE_CHECKING:
51811
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   143
    from typing_extensions import (
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   144
        Literal,  # py3.8+
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   145
    )
46644
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   146
    from . import (
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   147
        localrepo,
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   148
        ui as uimod,
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   149
    )
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   150
51285
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   151
    # keeps pyflakes happy
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   152
    assert [uimod]
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51124
diff changeset
   153
46644
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   154
    Phasedefaults = List[
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   155
        Callable[[localrepo.localrepository, Phaseroots], Phaseroots]
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   156
    ]
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   157
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   158
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   159
_fphasesentry = struct.Struct(b'>i20s')
34319
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   160
39297
06c976acc581 phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents: 39293
diff changeset
   161
# record phase index
51288
8b2ea2246a5f pytype: convert type comment for inline variable too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51287
diff changeset
   162
public: int = 0
8b2ea2246a5f pytype: convert type comment for inline variable too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51287
diff changeset
   163
draft: int = 1
8b2ea2246a5f pytype: convert type comment for inline variable too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51287
diff changeset
   164
secret: int = 2
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   165
archived = 32  # non-continuous for compatibility
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   166
internal = 96  # non-continuous for compatibility
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   167
allphases = (public, draft, secret, archived, internal)
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   168
trackedphases = (draft, secret, archived, internal)
50387
92f71d40fc1d revset: include all non-public phases in _notpublic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49451
diff changeset
   169
not_public_phases = trackedphases
39297
06c976acc581 phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents: 39293
diff changeset
   170
# record phase names
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   171
cmdphasenames = [b'public', b'draft', b'secret']  # known to `hg phase` command
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   172
phasenames = dict(enumerate(cmdphasenames))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   173
phasenames[archived] = b'archived'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   174
phasenames[internal] = b'internal'
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   175
# map phase name to phase number
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   176
phasenumber = {name: phase for phase, name in phasenames.items()}
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   177
# like phasenumber, but also include maps for the numeric and binary
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   178
# phase number to the phase number
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   179
phasenumber2 = phasenumber.copy()
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   180
phasenumber2.update({phase: phase for phase in phasenames})
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   181
phasenumber2.update({b'%i' % phase: phase for phase in phasenames})
39297
06c976acc581 phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents: 39293
diff changeset
   182
# record phase property
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   183
mutablephases = (draft, secret, archived, internal)
51124
80bda4254b84 unstable: do not consider internal phases when computing unstable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50929
diff changeset
   184
relevant_mutable_phases = (draft, secret)  # could be obsolete or unstable
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   185
remotehiddenphases = (secret, archived, internal)
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   186
localhiddenphases = (internal, archived)
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   187
50396
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50392
diff changeset
   188
all_internal_phases = tuple(p for p in allphases if p & internal)
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50392
diff changeset
   189
# We do not want any internal content to exit the repository, ever.
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50392
diff changeset
   190
no_bundle_phases = all_internal_phases
386737600689 revset: add `_internal()` predicate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50392
diff changeset
   191
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   192
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   193
def supportinternal(repo: "localrepo.localrepository") -> bool:
39299
7775c1fb8fa0 phases: enforce internal phase support
Boris Feld <boris.feld@octobus.net>
parents: 39297
diff changeset
   194
    """True if the internal phase can be used on a repository"""
45372
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45356
diff changeset
   195
    return requirements.INTERNAL_PHASE_REQUIREMENT in repo.requirements
39299
7775c1fb8fa0 phases: enforce internal phase support
Boris Feld <boris.feld@octobus.net>
parents: 39297
diff changeset
   196
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   197
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   198
def supportarchived(repo: "localrepo.localrepository") -> bool:
49450
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   199
    """True if the archived phase can be used on a repository"""
49451
0c70d888a484 phase: introduce a dedicated requirement for the `archived` phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49450
diff changeset
   200
    return requirements.ARCHIVED_PHASE_REQUIREMENT in repo.requirements
49450
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   201
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   202
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   203
def _readroots(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   204
    repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   205
    phasedefaults: Optional["Phasedefaults"] = None,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   206
) -> Tuple[Phaseroots, bool]:
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   207
    """Read phase roots from disk
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   208
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   209
    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
   210
    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
   211
    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
   212
    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
   213
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   214
    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
   215
    what is being stored.
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   216
    """
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
   217
    repo = repo.unfiltered()
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   218
    dirty = False
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   219
    roots = {i: set() for i in allphases}
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   220
    to_rev = repo.changelog.index.get_rev
51405
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   221
    unknown_msg = b'removing unknown node %s from %i-phase boundary\n'
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   222
    try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   223
        f, pending = txnutil.trypending(repo.root, repo.svfs, b'phaseroots')
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   224
        try:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   225
            for line in f:
51405
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   226
                str_phase, hex_node = line.split()
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   227
                phase = int(str_phase)
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   228
                node = bin(hex_node)
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   229
                rev = to_rev(node)
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   230
                if rev is None:
51405
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   231
                    repo.ui.debug(unknown_msg % (short(hex_node), phase))
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   232
                    dirty = True
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   233
                else:
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   234
                    roots[phase].add(rev)
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   235
        finally:
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   236
            f.close()
49306
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49284
diff changeset
   237
    except FileNotFoundError:
16625
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   238
        if phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   239
            for f in phasedefaults:
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   240
                roots = f(repo, roots)
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   241
        dirty = True
df9df747070d phases: stop modifying localrepo in readroots()
Patrick Mezard <patrick@mezard.eu>
parents: 16624
diff changeset
   242
    return roots, dirty
15418
cf729af26963 phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15417
diff changeset
   243
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   244
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   245
def binaryencode(phasemapping: Dict[int, List[bytes]]) -> bytes:
34319
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   246
    """encode a 'phase -> nodes' mapping into a binary stream
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   247
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   248
    The revision lists are encoded as (phase, root) pairs.
34319
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   249
    """
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   250
    binarydata = []
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   251
    for phase, nodes in phasemapping.items():
34319
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   252
        for head in nodes:
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   253
            binarydata.append(_fphasesentry.pack(phase, head))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   254
    return b''.join(binarydata)
34319
5779d096a696 phases: move binary encoding into a reusable function
Boris Feld <boris.feld@octobus.net>
parents: 33460
diff changeset
   255
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   256
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   257
def binarydecode(stream) -> Dict[int, List[bytes]]:
34320
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   258
    """decode a binary stream into a 'phase -> nodes' mapping
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   259
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   260
    The (phase, root) pairs are turned back into a dictionary with
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   261
    the phase as index and the aggregated roots of that phase as value."""
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
   262
    headsbyphase = {i: [] for i in allphases}
34320
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   263
    entrysize = _fphasesentry.size
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   264
    while True:
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   265
        entry = stream.read(entrysize)
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   266
        if len(entry) < entrysize:
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   267
            if entry:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   268
                raise error.Abort(_(b'bad phase-heads stream'))
34320
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   269
            break
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   270
        phase, node = _fphasesentry.unpack(entry)
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   271
        headsbyphase[phase].append(node)
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   272
    return headsbyphase
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34319
diff changeset
   273
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   274
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   275
def _sortedrange_insert(data, idx, rev, t):
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   276
    merge_before = False
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   277
    if idx:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   278
        r1, t1 = data[idx - 1]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   279
        merge_before = r1[-1] + 1 == rev and t1 == t
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   280
    merge_after = False
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   281
    if idx < len(data):
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   282
        r2, t2 = data[idx]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   283
        merge_after = r2[0] == rev + 1 and t2 == t
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   284
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   285
    if merge_before and merge_after:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   286
        data[idx - 1] = (range(r1[0], r2[-1] + 1), t)
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   287
        data.pop(idx)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   288
    elif merge_before:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   289
        data[idx - 1] = (range(r1[0], rev + 1), t)
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   290
    elif merge_after:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   291
        data[idx] = (range(rev, r2[-1] + 1), t)
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   292
    else:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   293
        data.insert(idx, (range(rev, rev + 1), t))
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   294
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   295
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   296
def _sortedrange_split(data, idx, rev, t):
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   297
    r1, t1 = data[idx]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   298
    if t == t1:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   299
        return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   300
    t = (t1[0], t[1])
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   301
    if len(r1) == 1:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   302
        data.pop(idx)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   303
        _sortedrange_insert(data, idx, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   304
    elif r1[0] == rev:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   305
        data[idx] = (range(rev + 1, r1[-1] + 1), t1)
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   306
        _sortedrange_insert(data, idx, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   307
    elif r1[-1] == rev:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   308
        data[idx] = (range(r1[0], rev), t1)
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   309
        _sortedrange_insert(data, idx + 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   310
    else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   311
        data[idx : idx + 1] = [
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   312
            (range(r1[0], rev), t1),
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   313
            (range(rev, rev + 1), t),
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   314
            (range(rev + 1, r1[-1] + 1), t1),
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   315
        ]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   316
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   317
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   318
def _trackphasechange(data, rev, old, new):
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   319
    """add a phase move to the <data> list of ranges
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   320
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   321
    If data is None, nothing happens.
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   322
    """
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   323
    if data is None:
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   324
        return
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   325
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   326
    # If data is empty, create a one-revision range and done
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   327
    if not data:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   328
        data.insert(0, (range(rev, rev + 1), (old, new)))
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   329
        return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   330
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   331
    low = 0
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   332
    high = len(data)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   333
    t = (old, new)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   334
    while low < high:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   335
        mid = (low + high) // 2
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   336
        revs = data[mid][0]
45550
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45372
diff changeset
   337
        revs_low = revs[0]
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45372
diff changeset
   338
        revs_high = revs[-1]
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   339
45550
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45372
diff changeset
   340
        if rev >= revs_low and rev <= revs_high:
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   341
            _sortedrange_split(data, mid, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   342
            return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   343
45550
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45372
diff changeset
   344
        if revs_low == rev + 1:
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   345
            if mid and data[mid - 1][0][-1] == rev:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   346
                _sortedrange_split(data, mid - 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   347
            else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   348
                _sortedrange_insert(data, mid, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   349
            return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   350
45550
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45372
diff changeset
   351
        if revs_high == rev - 1:
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   352
            if mid + 1 < len(data) and data[mid + 1][0][0] == rev:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   353
                _sortedrange_split(data, mid + 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   354
            else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   355
                _sortedrange_insert(data, mid + 1, rev, t)
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   356
            return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   357
45550
29a259be6424 phases: fix performance regression with Python 2
Joerg Sonnenberger <joerg@bec.de>
parents: 45372
diff changeset
   358
        if revs_low > rev:
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   359
            high = mid
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   360
        else:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   361
            low = mid + 1
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   362
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   363
    if low == len(data):
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   364
        data.append((range(rev, rev + 1), t))
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   365
        return
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   366
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   367
    r1, t1 = data[low]
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   368
    if r1[0] > rev:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   369
        data.insert(low, (range(rev, rev + 1), t))
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 44452
diff changeset
   370
    else:
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   371
        data.insert(low + 1, (range(rev, rev + 1), t))
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   372
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   373
51419
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   374
# consider incrementaly updating the phase set the update set is not bigger
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   375
# than this size
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   376
#
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   377
# Be warned, this number is picked arbitrarily, without any benchmark. It
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   378
# should blindly pickup "small update"
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   379
INCREMENTAL_PHASE_SETS_UPDATE_MAX_UPDATE = 100
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   380
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   381
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
   382
class phasecache:
51811
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   383
    if typing.TYPE_CHECKING:
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   384
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   385
        @overload
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   386
        def __init__(
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   387
            self,
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   388
            repo: Any,
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   389
            phasedefaults: Any,
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   390
            _load: Literal[False],
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   391
        ) -> None:
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   392
            pass
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   393
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   394
        @overload
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   395
        def __init__(
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   396
            self,
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   397
            repo: "localrepo.localrepository",
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   398
            phasedefaults: Optional["Phasedefaults"],
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   399
            _load: bool = True,
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   400
        ) -> None:
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   401
            pass
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   402
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   403
    def __init__(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   404
        self,
51811
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   405
        repo,
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   406
        phasedefaults,
673b07a1db08 typing: create an @overload of `phasecache` ctor to handle the copy case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51810
diff changeset
   407
        _load=True,
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   408
    ):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   409
        if _load:
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   410
            # Cheap trick to allow shallow-copy without copy module
51405
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   411
            loaded = _readroots(repo, phasedefaults)
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   412
            self._phaseroots: Phaseroots = loaded[0]
12881244e48a phases: do filtering at read time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51404
diff changeset
   413
            self.dirty: bool = loaded[1]
35442
56745e58df07 phases: initialize number of loaded revisions to 0
Yuya Nishihara <yuya@tcha.org>
parents: 35441
diff changeset
   414
            self._loadedrevslen = 0
51810
07086b3ad502 typing: declare the `_phasesets` member of `phasecache` to be `Optional`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51703
diff changeset
   415
            self._phasesets: Optional[PhaseSets] = None
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   416
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   417
    def hasnonpublicphases(self, repo: "localrepo.localrepository") -> bool:
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   418
        """detect if there are revisions with non-public phase"""
51416
0c04074f5414 phases: drop set building in `hasnonpublicphases`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51415
diff changeset
   419
        # XXX deprecate the unused repo argument
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   420
        return any(
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
   421
            revs for phase, revs in self._phaseroots.items() if phase != public
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   422
        )
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   423
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   424
    def nonpublicphaseroots(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   425
        self, repo: "localrepo.localrepository"
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   426
    ) -> Set[int]:
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   427
        """returns the roots of all non-public phases
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   428
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   429
        The roots are not minimized, so if the secret revisions are
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   430
        descendants of draft revisions, their roots will still be present.
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   431
        """
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   432
        repo = repo.unfiltered()
51415
1df8d84e7c99 phases: gather the logic for phasesets update in a single method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51412
diff changeset
   433
        self._ensure_phase_sets(repo)
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   434
        return set().union(
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   435
            *[
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   436
                revs
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
   437
                for phase, revs in self._phaseroots.items()
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   438
                if phase != public
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   439
            ]
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   440
        )
45114
e2d17974a869 phases: provide a test and accessor for non-public phase roots
Joerg Sonnenberger <joerg@bec.de>
parents: 45063
diff changeset
   441
51585
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   442
    def get_raw_set(
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   443
        self,
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   444
        repo: "localrepo.localrepository",
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   445
        phase: int,
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   446
    ) -> Set[int]:
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   447
        """return the set of revision in that phase
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   448
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   449
        The returned set is not filtered and might contains revision filtered
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   450
        for the passed repoview.
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   451
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   452
        The returned set might be the internal one and MUST NOT be mutated to
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   453
        avoid side effect.
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   454
        """
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   455
        if phase == public:
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   456
            raise error.ProgrammingError("cannot get_set for public phase")
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   457
        self._ensure_phase_sets(repo.unfiltered())
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   458
        revs = self._phasesets.get(phase)
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   459
        if revs is None:
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   460
            return set()
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   461
        return revs
c11d21faa73c phases: introduce a performant efficient way to access revision in a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51583
diff changeset
   462
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   463
    def getrevset(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   464
        self,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   465
        repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   466
        phases: Iterable[int],
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   467
        subset: Optional[Any] = None,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   468
    ) -> Any:
46644
77e129be10de typing: add some type annotations to mercurial/phases.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
   469
        # TODO: finish typing this
31016
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30634
diff changeset
   470
        """return a smartset for the given phases"""
51417
e0d329491709 phases: pass an unfiltered repository to _ensure_phase_sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51416
diff changeset
   471
        self._ensure_phase_sets(repo.unfiltered())
35309
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   472
        phases = set(phases)
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   473
        publicphase = public in phases
44004
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43730
diff changeset
   474
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   475
        if publicphase:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   476
            # In this case, phases keeps all the *other* phases.
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   477
            phases = set(allphases).difference(phases)
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   478
            if not phases:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   479
                return smartset.fullreposet(repo)
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   480
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   481
        # fast path: _phasesets contains the interesting sets,
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   482
        # might only need a union and post-filtering.
44065
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
   483
        revsneedscopy = False
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   484
        if len(phases) == 1:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   485
            [p] = phases
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   486
            revs = self._phasesets[p]
44065
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
   487
            revsneedscopy = True  # Don't modify _phasesets
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   488
        else:
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   489
            # revs has the revisions in all *other* phases.
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   490
            revs = set.union(*[self._phasesets[p] for p in phases])
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   491
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   492
        def _addwdir(wdirsubset, wdirrevs):
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   493
            if wdirrev in wdirsubset and repo[None].phase() in phases:
44065
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
   494
                if revsneedscopy:
ab41dad7345e phases: make phasecache._phasesets immutable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44064
diff changeset
   495
                    wdirrevs = wdirrevs.copy()
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   496
                # The working dir would never be in the # cache, but it was in
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   497
                # the subset being filtered for its phase (or filtered out,
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   498
                # depending on publicphase), so add it to the output to be
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   499
                # included (or filtered out).
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   500
                wdirrevs.add(wdirrev)
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   501
            return wdirrevs
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   502
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   503
        if not publicphase:
31016
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30634
diff changeset
   504
            if repo.changelog.filteredrevs:
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30634
diff changeset
   505
                revs = revs - repo.changelog.filteredrevs
44004
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43730
diff changeset
   506
35330
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   507
            if subset is None:
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   508
                return smartset.baseset(revs)
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   509
            else:
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   510
                revs = _addwdir(subset, revs)
35330
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   511
                return subset & smartset.baseset(revs)
31016
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30634
diff changeset
   512
        else:
35330
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   513
            if subset is None:
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   514
                subset = smartset.fullreposet(repo)
44004
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43730
diff changeset
   515
44064
8eb3c52337a6 phases: reduce code duplication in phasecache.getrevset
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44004
diff changeset
   516
            revs = _addwdir(subset, revs)
44004
9c1fd975e9ac phases: make the working directory consistently a draft
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 43730
diff changeset
   517
35309
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   518
            if not revs:
35330
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   519
                return subset
0c1aff6d73a7 revset: use phasecache.getrevset to calculate public()
Jun Wu <quark@fb.com>
parents: 35309
diff changeset
   520
            return subset.filter(lambda r: r not in revs)
31016
bf81d3b7b2ba phases: add a getrevset method to phasecache
Jun Wu <quark@fb.com>
parents: 30634
diff changeset
   521
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   522
    def copy(self):
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   523
        # Shallow copy meant to ensure isolation in
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   524
        # advance/retractboundary(), nothing more.
23631
b8260abfeb7d bundlerepo: implement safe phasecache
Eric Sumner <ericsumner@fb.com>
parents: 23361
diff changeset
   525
        ph = self.__class__(None, None, _load=False)
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
   526
        ph._phaseroots = self._phaseroots.copy()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   527
        ph.dirty = self.dirty
35441
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35330
diff changeset
   528
        ph._loadedrevslen = self._loadedrevslen
51418
c9c017b34464 phasees: properly shallow caopy the phase sets dictionary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51417
diff changeset
   529
        if self._phasesets is None:
c9c017b34464 phasees: properly shallow caopy the phase sets dictionary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51417
diff changeset
   530
            ph._phasesets = None
c9c017b34464 phasees: properly shallow caopy the phase sets dictionary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51417
diff changeset
   531
        else:
c9c017b34464 phasees: properly shallow caopy the phase sets dictionary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51417
diff changeset
   532
            ph._phasesets = self._phasesets.copy()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   533
        return ph
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   534
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   535
    def replace(self, phcache):
25613
a13c18c14ade phase: document the replace method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25611
diff changeset
   536
        """replace all values in 'self' with content of phcache"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   537
        for a in (
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
   538
            '_phaseroots',
50592
0f83dc22efbc safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50396
diff changeset
   539
            'dirty',
0f83dc22efbc safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50396
diff changeset
   540
            '_loadedrevslen',
0f83dc22efbc safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50396
diff changeset
   541
            '_phasesets',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
   542
        ):
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   543
            setattr(self, a, getattr(phcache, a))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   544
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
   545
    def _getphaserevsnative(self, repo):
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   546
        repo = repo.unfiltered()
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
   547
        return repo.changelog.computephases(self._phaseroots)
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   548
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
   549
    def _computephaserevspure(self, repo):
24519
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   550
        repo = repo.unfiltered()
35309
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   551
        cl = repo.changelog
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 45117
diff changeset
   552
        self._phasesets = {phase: set() for phase in allphases}
39271
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   553
        lowerroots = set()
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   554
        for phase in reversed(trackedphases):
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   555
            roots = self._phaseroots[phase]
39271
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   556
            if roots:
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   557
                ps = set(cl.descendants(roots))
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   558
                for root in roots:
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   559
                    ps.add(root)
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   560
                ps.difference_update(lowerroots)
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   561
                lowerroots.update(ps)
fd7376fa60e7 phase: use `trackedphases` in `_getphaserevsnative`
Boris Feld <boris.feld@octobus.net>
parents: 39262
diff changeset
   562
                self._phasesets[phase] = ps
35441
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35330
diff changeset
   563
        self._loadedrevslen = len(cl)
24519
de3acfabaddc phases: move pure phase computation in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24444
diff changeset
   564
51415
1df8d84e7c99 phases: gather the logic for phasesets update in a single method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51412
diff changeset
   565
    def _ensure_phase_sets(self, repo: "localrepo.localrepository") -> None:
51419
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   566
        """ensure phase information is loaded in the object"""
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   567
        assert repo.filtername is None
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   568
        update = -1
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   569
        cl = repo.changelog
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   570
        cl_size = len(cl)
35309
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   571
        if self._phasesets is None:
51419
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   572
            update = 0
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   573
        else:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   574
            if cl_size > self._loadedrevslen:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   575
                # check if an incremental update is worth it.
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   576
                # note we need a tradeoff here because the whole logic is not
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   577
                # stored and implemented in native code nd datastructure.
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   578
                # Otherwise the incremental update woul always be a win.
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   579
                missing = cl_size - self._loadedrevslen
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   580
                if missing <= INCREMENTAL_PHASE_SETS_UPDATE_MAX_UPDATE:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   581
                    update = self._loadedrevslen
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   582
                else:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   583
                    update = 0
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   584
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   585
        if update == 0:
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   586
            try:
31152
b7cef987356d phases: remove experimental.nativephaseskillswitch
Jun Wu <quark@fb.com>
parents: 31053
diff changeset
   587
                res = self._getphaserevsnative(repo)
35441
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35330
diff changeset
   588
                self._loadedrevslen, self._phasesets = res
24444
27e3ba73fbb1 phase: default to C implementation for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 23878
diff changeset
   589
            except AttributeError:
24599
2a73829ebe17 phases: make two functions private for phase computation
Laurent Charignon <lcharignon@fb.com>
parents: 24520
diff changeset
   590
                self._computephaserevspure(repo)
51415
1df8d84e7c99 phases: gather the logic for phasesets update in a single method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51412
diff changeset
   591
            assert self._loadedrevslen == len(repo.changelog)
51419
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   592
        elif update > 0:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   593
            # good candidate for native code
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   594
            assert update == self._loadedrevslen
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   595
            if self.hasnonpublicphases(repo):
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   596
                start = self._loadedrevslen
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   597
                get_phase = self.phase
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   598
                rev_phases = [0] * missing
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   599
                parents = cl.parentrevs
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   600
                sets = {phase: set() for phase in self._phasesets}
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   601
                for phase, roots in self._phaseroots.items():
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   602
                    # XXX should really store the max somewhere
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   603
                    for r in roots:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   604
                        if r >= start:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   605
                            rev_phases[r - start] = phase
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   606
                for rev in range(start, cl_size):
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   607
                    phase = rev_phases[rev - start]
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   608
                    p1, p2 = parents(rev)
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   609
                    if p1 == nullrev:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   610
                        p1_phase = public
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   611
                    elif p1 >= start:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   612
                        p1_phase = rev_phases[p1 - start]
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   613
                    else:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   614
                        p1_phase = max(phase, get_phase(repo, p1))
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   615
                    if p2 == nullrev:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   616
                        p2_phase = public
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   617
                    elif p2 >= start:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   618
                        p2_phase = rev_phases[p2 - start]
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   619
                    else:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   620
                        p2_phase = max(phase, get_phase(repo, p2))
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   621
                    phase = max(phase, p1_phase, p2_phase)
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   622
                    if phase > public:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   623
                        rev_phases[rev - start] = phase
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   624
                        sets[phase].add(rev)
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   625
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   626
                # Be careful to preserve shallow-copied values: do not update
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   627
                # phaseroots values, replace them.
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   628
                for phase, extra in sets.items():
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   629
                    if extra:
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   630
                        self._phasesets[phase] = self._phasesets[phase] | extra
e57d4b868a3e phases: incrementally update the phase sets when reasonable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51418
diff changeset
   631
            self._loadedrevslen = cl_size
22894
c40be72dc177 phases: move root phase assignment to it's own function
Durham Goode <durham@fb.com>
parents: 22893
diff changeset
   632
22893
9672f0b2cdd9 phases: add invalidate function
Durham Goode <durham@fb.com>
parents: 22080
diff changeset
   633
    def invalidate(self):
35442
56745e58df07 phases: initialize number of loaded revisions to 0
Yuya Nishihara <yuya@tcha.org>
parents: 35441
diff changeset
   634
        self._loadedrevslen = 0
25593
9e551f155810 phase: invalidate the phase's set cache alongside the revs
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25592
diff changeset
   635
        self._phasesets = None
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   636
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
   637
    def phase(self, repo: "localrepo.localrepository", rev: int) -> int:
35309
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   638
        # We need a repo argument here to be able to build _phasesets
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   639
        # if necessary. The repository instance is not stored in
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   640
        # phasecache to avoid reference cycles. The changelog instance
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   641
        # is not stored because it is a filecache() property and can
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   642
        # be replaced without us being notified.
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   643
        if rev == nullrev:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   644
            return public
19984
7d5e7799a29f rebase: fix rebase aborts when 'tip-1' is public (issue4082)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   645
        if rev < nullrev:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   646
            raise ValueError(_(b'cannot lookup negative revision'))
51415
1df8d84e7c99 phases: gather the logic for phasesets update in a single method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51412
diff changeset
   647
        # double check self._loadedrevslen to avoid an extra method call as
1df8d84e7c99 phases: gather the logic for phasesets update in a single method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51412
diff changeset
   648
        # python is slow for that.
35441
98cc121099fe phases: rename _phasemaxrev to _loadedrevslen to clarify it isn't max value
Yuya Nishihara <yuya@tcha.org>
parents: 35330
diff changeset
   649
        if rev >= self._loadedrevslen:
51417
e0d329491709 phases: pass an unfiltered repository to _ensure_phase_sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51416
diff changeset
   650
            self._ensure_phase_sets(repo.unfiltered())
35309
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   651
        for phase in trackedphases:
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   652
            if rev in self._phasesets[phase]:
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   653
                return phase
d13526333835 phases: drop the list with phase of each rev, always comput phase sets
Joerg Sonnenberger <joerg@bec.de>
parents: 34876
diff changeset
   654
        return public
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   655
51404
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   656
    def write(self, repo):
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   657
        if not self.dirty:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   658
            return
51404
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   659
        f = repo.svfs(b'phaseroots', b'w', atomictemp=True, checkambig=True)
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   660
        try:
51404
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   661
            self._write(repo.unfiltered(), f)
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   662
        finally:
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   663
            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
   664
51404
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   665
    def _write(self, repo, fp):
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   666
        assert repo.filtername is None
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   667
        to_node = repo.changelog.node
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
   668
        for phase, roots in self._phaseroots.items():
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   669
            for r in sorted(roots):
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   670
                h = to_node(r)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   671
                fp.write(b'%i %s\n' % (phase, hex(h)))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16626
diff changeset
   672
        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
   673
51420
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   674
    def _updateroots(self, repo, phase, newroots, tr, invalidate=True):
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
   675
        self._phaseroots[phase] = newroots
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   676
        self.dirty = True
51420
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   677
        if invalidate:
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   678
            self.invalidate()
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   679
51404
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   680
        assert repo.filtername is None
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   681
        wrepo = weakref.ref(repo)
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   682
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   683
        def tr_write(fp):
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   684
            repo = wrepo()
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   685
            assert repo is not None
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   686
            self._write(repo, fp)
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   687
04111ef08fb0 phases: always write with a repo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51403
diff changeset
   688
        tr.addfilegenerator(b'phase', (b'phaseroots',), tr_write)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   689
        tr.hookargs[b'phases_moved'] = b'1'
22080
37f46575d9c2 phase: attach phase to the transaction instead of the lock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22079
diff changeset
   690
45790
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45789
diff changeset
   691
    def registernew(self, repo, tr, targetphase, revs):
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
   692
        repo = repo.unfiltered()
45790
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45789
diff changeset
   693
        self._retractboundary(repo, tr, targetphase, [], revs=revs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   694
        if tr is not None and b'phases' in tr.changes:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   695
            phasetracking = tr.changes[b'phases']
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
   696
            phase = self.phase
45790
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45789
diff changeset
   697
            for rev in sorted(revs):
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
   698
                revphase = phase(repo, rev)
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
   699
                _trackphasechange(phasetracking, rev, None, revphase)
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
   700
        repo.invalidatevolatilesets()
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
   701
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45550
diff changeset
   702
    def advanceboundary(
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   703
        self, repo, tr, targetphase, nodes=None, revs=None, dryrun=None
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45550
diff changeset
   704
    ):
33450
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
   705
        """Set all 'nodes' to phase 'targetphase'
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
   706
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
   707
        Nodes with a phase lower than 'targetphase' are not affected.
38218
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
   708
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
   709
        If dryrun is True, no actions will be performed
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
   710
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
   711
        Returns a set of revs whose phase is changed or should be changed
33450
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
   712
        """
51408
330d74750668 phases: fast path public phase advance when everything is public
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51407
diff changeset
   713
        if targetphase == public and not self.hasnonpublicphases(repo):
330d74750668 phases: fast path public phase advance when everything is public
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51407
diff changeset
   714
            return set()
51422
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   715
        repo = repo.unfiltered()
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   716
        cl = repo.changelog
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   717
        torev = cl.index.rev
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   718
        # 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
   719
        # phaseroots values, replace them.
51422
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   720
        new_revs = set()
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   721
        if revs is not None:
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   722
            new_revs.update(revs)
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   723
        if nodes is not None:
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   724
            new_revs.update(torev(node) for node in nodes)
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   725
        if not new_revs:  # bail out early to avoid the loadphaserevs call
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   726
            return (
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   727
                set()
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   728
            )  # note: why do people call advanceboundary with nothing?
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   729
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   730
        if tr is None:
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   731
            phasetracking = None
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   732
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   733
            phasetracking = tr.changes.get(b'phases')
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   734
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   735
        affectable_phases = sorted(
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   736
            p for p in allphases if p > targetphase and self._phaseroots[p]
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   737
        )
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   738
        # filter revision already in the right phases
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   739
        candidates = new_revs
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   740
        new_revs = set()
51422
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   741
        self._ensure_phase_sets(repo)
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   742
        for phase in affectable_phases:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   743
            found = candidates & self._phasesets[phase]
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   744
            new_revs |= found
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   745
            candidates -= found
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   746
            if not candidates:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   747
                break
51422
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   748
        if not new_revs:
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   749
            return set()
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   750
51422
709525b26cf5 phases: apply similar early filtering to advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51421
diff changeset
   751
        # search for affected high phase changesets and roots
51505
c9ceb4f60256 phases: avoid N² behavior in `advanceboundary`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51424
diff changeset
   752
        seen = set(new_revs)
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   753
        push = heapq.heappush
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   754
        pop = heapq.heappop
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   755
        parents = cl.parentrevs
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   756
        get_phase = self.phase
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   757
        changed = {}  # set of revisions to be changed
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   758
        # set of root deleted by this path
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   759
        delroots = set()
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   760
        new_roots = {p: set() for p in affectable_phases}
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   761
        new_target_roots = set()
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   762
        # revision to walk down
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   763
        revs = [-r for r in new_revs]
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   764
        heapq.heapify(revs)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   765
        while revs:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   766
            current = -pop(revs)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   767
            current_phase = get_phase(repo, current)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   768
            changed[current] = current_phase
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   769
            p1, p2 = parents(current)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   770
            if p1 == nullrev:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   771
                p1_phase = public
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   772
            else:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   773
                p1_phase = get_phase(repo, p1)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   774
            if p2 == nullrev:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   775
                p2_phase = public
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   776
            else:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   777
                p2_phase = get_phase(repo, p2)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   778
            # do we have a root ?
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   779
            if current_phase != p1_phase and current_phase != p2_phase:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   780
                # do not record phase, because we could have "duplicated"
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   781
                # roots, were one root is shadowed by the very same roots of an
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   782
                # higher phases
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   783
                delroots.add(current)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   784
            # schedule a walk down if needed
51505
c9ceb4f60256 phases: avoid N² behavior in `advanceboundary`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51424
diff changeset
   785
            if p1_phase > targetphase and p1 not in seen:
c9ceb4f60256 phases: avoid N² behavior in `advanceboundary`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51424
diff changeset
   786
                seen.add(p1)
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   787
                push(revs, -p1)
51505
c9ceb4f60256 phases: avoid N² behavior in `advanceboundary`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51424
diff changeset
   788
            if p2_phase > targetphase and p2 not in seen:
c9ceb4f60256 phases: avoid N² behavior in `advanceboundary`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51424
diff changeset
   789
                seen.add(p2)
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   790
                push(revs, -p2)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   791
            if p1_phase < targetphase and p2_phase < targetphase:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   792
                new_target_roots.add(current)
33451
e44d54260c32 phases: track phase movements in 'advanceboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33450
diff changeset
   793
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   794
        # the last iteration was done with the smallest value
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   795
        min_current = current
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   796
        # do we have unwalked children that might be new roots
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   797
        if (min_current + len(changed)) < len(cl):
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   798
            for r in range(min_current, len(cl)):
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   799
                if r in changed:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   800
                    continue
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   801
                phase = get_phase(repo, r)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   802
                if phase <= targetphase:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   803
                    continue
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   804
                p1, p2 = parents(r)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   805
                if not (p1 in changed or p2 in changed):
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   806
                    continue  # not affected
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   807
                if p1 != nullrev and p1 not in changed:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   808
                    p1_phase = get_phase(repo, p1)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   809
                    if p1_phase == phase:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   810
                        continue  # not a root
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   811
                if p2 != nullrev and p2 not in changed:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   812
                    p2_phase = get_phase(repo, p2)
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   813
                    if p2_phase == phase:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   814
                        continue  # not a root
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   815
                new_roots[phase].add(r)
33450
d017f1d37378 phases: extract the intermediate set of affected revs
Boris Feld <boris.feld@octobus.net>
parents: 33449
diff changeset
   816
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   817
        # apply the changes
38218
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
   818
        if not dryrun:
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   819
            for r, p in changed.items():
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   820
                _trackphasechange(phasetracking, r, p, targetphase)
51424
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   821
            if targetphase > public:
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   822
                self._phasesets[targetphase].update(changed)
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   823
            for phase in affectable_phases:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   824
                roots = self._phaseroots[phase]
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   825
                removed = roots & delroots
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   826
                if removed or new_roots[phase]:
51424
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   827
                    self._phasesets[phase].difference_update(changed)
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   828
                    # Be careful to preserve shallow-copied values: do not
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   829
                    # update phaseroots values, replace them.
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   830
                    final_roots = roots - delroots | new_roots[phase]
51424
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   831
                    self._updateroots(
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   832
                        repo, phase, final_roots, tr, invalidate=False
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   833
                    )
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   834
            if new_target_roots:
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   835
                # Thanks for previous filtering, we can't replace existing
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   836
                # roots
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   837
                new_target_roots |= self._phaseroots[targetphase]
51424
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   838
                self._updateroots(
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   839
                    repo, targetphase, new_target_roots, tr, invalidate=False
3cee8706f53b phases: directly update the phase sets in advanceboundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51423
diff changeset
   840
                )
38218
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
   841
            repo.invalidatevolatilesets()
51423
23950e39281f phases: large rework of advance boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51422
diff changeset
   842
        return changed
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   843
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
   844
    def retractboundary(self, repo, tr, targetphase, nodes):
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
   845
        if tr is None:
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
   846
            phasetracking = None
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
   847
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   848
            phasetracking = tr.changes.get(b'phases')
33458
cf694e6422f0 phases: track phase changes from 'retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33457
diff changeset
   849
        repo = repo.unfiltered()
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   850
        retracted = self._retractboundary(repo, tr, targetphase, nodes)
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   851
        if retracted and phasetracking is not None:
51410
eababb7b4a82 phases: leverage the collected information to record phase update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51409
diff changeset
   852
            for r, old_phase in sorted(retracted.items()):
eababb7b4a82 phases: leverage the collected information to record phase update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51409
diff changeset
   853
                _trackphasechange(phasetracking, r, old_phase, targetphase)
33452
7b25a56366cf phases: extract the core of boundary retraction in '_retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33451
diff changeset
   854
        repo.invalidatevolatilesets()
7b25a56366cf phases: extract the core of boundary retraction in '_retractboundary'
Boris Feld <boris.feld@octobus.net>
parents: 33451
diff changeset
   855
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   856
    def _retractboundary(self, repo, tr, targetphase, nodes=None, revs=None):
51407
71ae6fee2b9d phases: fast path retract of public phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51406
diff changeset
   857
        if targetphase == public:
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   858
            return {}
49450
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   859
        if (
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   860
            targetphase == internal
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   861
            and not supportinternal(repo)
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   862
            or targetphase == archived
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   863
            and not supportarchived(repo)
b57c95a0f5f9 phase: introduce a dedicated function to check for the archived phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
   864
        ):
40417
49c7b701fdc2 phase: add an archived phase
Boris Feld <boris.feld@octobus.net>
parents: 39299
diff changeset
   865
            name = phasenames[targetphase]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   866
            msg = b'this repository does not support the %s phase' % name
39299
7775c1fb8fa0 phases: enforce internal phase support
Boris Feld <boris.feld@octobus.net>
parents: 39297
diff changeset
   867
            raise error.ProgrammingError(msg)
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   868
        assert repo.filtername is None
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   869
        cl = repo.changelog
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   870
        torev = cl.index.rev
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   871
        new_revs = set()
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   872
        if revs is not None:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   873
            new_revs.update(revs)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   874
        if nodes is not None:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   875
            new_revs.update(torev(node) for node in nodes)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   876
        if not new_revs:  # bail out early to avoid the loadphaserevs call
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   877
            return {}  # note: why do people call retractboundary with nothing ?
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   878
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   879
        if nullrev in new_revs:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   880
            raise error.Abort(_(b'cannot change null revision phase'))
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   881
51421
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   882
        # Filter revision that are already in the right phase
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   883
        self._ensure_phase_sets(repo)
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   884
        for phase, revs in self._phasesets.items():
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   885
            if phase >= targetphase:
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   886
                new_revs -= revs
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   887
        if not new_revs:  # all revisions already in the right phases
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   888
            return {}
2eb93812d2a5 phases: filter revision that are already in the right phase
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51420
diff changeset
   889
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   890
        # Compute change in phase roots by walking the graph
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   891
        #
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   892
        # note: If we had a cheap parent → children mapping we could do
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   893
        # something even cheaper/more-bounded
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   894
        #
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   895
        # The idea would be to walk from item in new_revs stopping at
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   896
        # descendant with phases >= target_phase.
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   897
        #
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   898
        # 1) This detect new_revs that are not new_roots (either already >=
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   899
        #    target_phase or reachable though another new_revs
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   900
        # 2) This detect replaced current_roots as we reach them
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   901
        # 3) This can avoid walking to the tip if we retract over a small
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   902
        #    branch.
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   903
        #
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   904
        # So instead, we do a variation of this, we walk from the smaller new
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   905
        # revision to the tip to avoid missing any potential children.
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   906
        #
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   907
        # The following code would be a good candidate for native code… if only
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   908
        # we could knew the phase of a changeset efficiently in native code.
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   909
        parents = cl.parentrevs
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   910
        phase = self.phase
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   911
        new_roots = set()  # roots added by this phases
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   912
        changed_revs = {}  # revision affected by this call
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   913
        replaced_roots = set()  # older roots replaced by this call
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   914
        currentroots = self._phaseroots[targetphase]
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   915
        start = min(new_revs)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   916
        end = len(cl)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   917
        rev_phases = [None] * (end - start)
51517
4ee50d98d35c phases: update the phase set as we go during retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51516
diff changeset
   918
4ee50d98d35c phases: update the phase set as we go during retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51516
diff changeset
   919
        this_phase_set = self._phasesets[targetphase]
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   920
        for r in range(start, end):
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   921
            # gather information about the current_rev
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   922
            r_phase = phase(repo, r)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   923
            p_phase = None  # phase inherited from parents
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   924
            p1, p2 = parents(r)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   925
            if p1 >= start:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   926
                p1_phase = rev_phases[p1 - start]
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   927
                if p1_phase is not None:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   928
                    p_phase = p1_phase
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   929
            if p2 >= start:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   930
                p2_phase = rev_phases[p2 - start]
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   931
                if p2_phase is not None:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   932
                    if p_phase is not None:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   933
                        p_phase = max(p_phase, p2_phase)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   934
                    else:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   935
                        p_phase = p2_phase
26909
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   936
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   937
            # assess the situation
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   938
            if r in new_revs and r_phase < targetphase:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   939
                if p_phase is None or p_phase < targetphase:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   940
                    new_roots.add(r)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   941
                rev_phases[r - start] = targetphase
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   942
                changed_revs[r] = r_phase
51517
4ee50d98d35c phases: update the phase set as we go during retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51516
diff changeset
   943
                this_phase_set.add(r)
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   944
            elif p_phase is None:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   945
                rev_phases[r - start] = r_phase
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   946
            else:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   947
                if p_phase > r_phase:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   948
                    rev_phases[r - start] = p_phase
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   949
                else:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   950
                    rev_phases[r - start] = r_phase
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   951
                if p_phase == targetphase:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   952
                    if p_phase > r_phase:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   953
                        changed_revs[r] = r_phase
51517
4ee50d98d35c phases: update the phase set as we go during retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51516
diff changeset
   954
                        this_phase_set.add(r)
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   955
                    elif r in currentroots:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   956
                        replaced_roots.add(r)
51420
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   957
            sets = self._phasesets
51516
e0f92bd98c24 phases: avoid a potentially costly dictionary interation in some case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51505
diff changeset
   958
            if targetphase > draft:
e0f92bd98c24 phases: avoid a potentially costly dictionary interation in some case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51505
diff changeset
   959
                for r, old in changed_revs.items():
e0f92bd98c24 phases: avoid a potentially costly dictionary interation in some case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51505
diff changeset
   960
                    if old > public:
e0f92bd98c24 phases: avoid a potentially costly dictionary interation in some case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51505
diff changeset
   961
                        sets[old].discard(r)
26909
e36118815a39 phase: improve retractboundary perf
Durham Goode <durham@fb.com>
parents: 26587
diff changeset
   962
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   963
        if new_roots:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   964
            assert changed_revs
51420
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   965
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   966
            final_roots = new_roots | currentroots - replaced_roots
51420
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   967
            self._updateroots(
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   968
                repo,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   969
                targetphase,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   970
                final_roots,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   971
                tr,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   972
                invalidate=False,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   973
            )
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   974
            if targetphase > 1:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   975
                retracted = set(changed_revs)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   976
                for lower_phase in range(1, targetphase):
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   977
                    lower_roots = self._phaseroots.get(lower_phase)
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   978
                    if lower_roots is None:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   979
                        continue
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   980
                    if lower_roots & retracted:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   981
                        simpler_roots = lower_roots - retracted
51420
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   982
                        self._updateroots(
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   983
                            repo,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   984
                            lower_phase,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   985
                            simpler_roots,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   986
                            tr,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   987
                            invalidate=False,
ac1c75188440 phases: invalidate the phases set less often on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51419
diff changeset
   988
                        )
51409
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   989
            return changed_revs
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   990
        else:
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   991
            assert not changed_revs
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   992
            assert not replaced_roots
2f39c7aeb549 phases: large rewrite on retract boundary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51408
diff changeset
   993
            return {}
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
   994
51401
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
   995
    def register_strip(
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
   996
        self,
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
   997
        repo,
51401
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
   998
        tr,
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
   999
        strip_rev: int,
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1000
    ):
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1001
        """announce a strip to the phase cache
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1002
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1003
        Any roots higher than the stripped revision should be dropped.
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1004
        """
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
  1005
        for targetphase, roots in list(self._phaseroots.items()):
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
  1006
            filtered = {r for r in roots if r >= strip_rev}
51401
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1007
            if filtered:
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
  1008
                self._updateroots(repo, targetphase, roots - filtered, tr)
51401
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1009
        self.invalidate()
8f2ea3fa50fd phases: explicitly filter stripped revision at strip time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51290
diff changeset
  1010
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1011
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45550
diff changeset
  1012
def advanceboundary(repo, tr, targetphase, nodes, revs=None, dryrun=None):
15454
5a7dde5adec8 phases: add a moveboundary function to move phases boundaries
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15419
diff changeset
  1013
    """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
  1014
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
  1015
    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
  1016
    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
  1017
38218
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1018
    Simplify boundary to contains phase roots only.
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1019
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1020
    If dryrun is True, no actions will be performed
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1021
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1022
    Returns a set of revs whose phase is changed or should be changed
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1023
    """
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45550
diff changeset
  1024
    if revs is None:
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45550
diff changeset
  1025
        revs = []
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
  1026
    phcache = repo._phasecache.copy()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1027
    changes = phcache.advanceboundary(
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45550
diff changeset
  1028
        repo, tr, targetphase, nodes, revs=revs, dryrun=dryrun
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1029
    )
38218
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1030
    if not dryrun:
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1031
        repo._phasecache.replace(phcache)
36ba5dba372d advanceboundary: add dryrun parameter
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38158
diff changeset
  1032
    return changes
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
  1033
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1034
22070
c1ca47204590 phase: add a transaction argument to retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22069
diff changeset
  1035
def retractboundary(repo, tr, targetphase, nodes):
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
  1036
    """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
  1037
    necessary.
15482
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
  1038
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
  1039
    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
  1040
    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
  1041
a667c89e49b3 phases: add retractboundary function to move boundary backward
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15481
diff changeset
  1042
    Simplify boundary to contains phase roots only."""
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
  1043
    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
  1044
    phcache.retractboundary(repo, tr, targetphase, nodes)
16658
6b3d31d04a69 phases: make advance/retractboundary() atomic
Patrick Mezard <patrick@mezard.eu>
parents: 16657
diff changeset
  1045
    repo._phasecache.replace(phcache)
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1046
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1047
45790
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45789
diff changeset
  1048
def registernew(repo, tr, targetphase, revs):
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1049
    """register a new revision and its phase
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1050
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1051
    Code adding revisions to the repository should use this function to
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1052
    set new changeset in their target phase (or higher).
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1053
    """
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1054
    phcache = repo._phasecache.copy()
45790
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45789
diff changeset
  1055
    phcache.registernew(repo, tr, targetphase, revs)
33453
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1056
    repo._phasecache.replace(phcache)
f6b7617a85bb phases: add a 'registernew' method to set new phases
Boris Feld <boris.feld@octobus.net>
parents: 33452
diff changeset
  1057
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1058
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1059
def listphases(repo: "localrepo.localrepository") -> Dict[bytes, bytes]:
16724
00535da82faf phases: fix typos in docstrings
Martin Geisler <martin@geisler.net>
parents: 16659
diff changeset
  1060
    """List phases root for serialization over pushkey"""
32000
511a62669f1b phases: emit phases to pushkey protocol in deterministic order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31342
diff changeset
  1061
    # Use ordered dictionary so behavior is deterministic.
511a62669f1b phases: emit phases to pushkey protocol in deterministic order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31342
diff changeset
  1062
    keys = util.sortdict()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1063
    value = b'%i' % draft
34816
e2c42f751b06 phase: filter out non-draft item in "draft root"
Boris Feld <boris.feld@octobus.net>
parents: 34710
diff changeset
  1064
    cl = repo.unfiltered().changelog
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
  1065
    to_node = cl.node
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
  1066
    for root in repo._phasecache._phaseroots[draft]:
51406
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
  1067
        if repo._phasecache.phase(repo, root) <= draft:
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51405
diff changeset
  1068
            keys[hex(to_node(root))] = value
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
  1069
25624
f0745da75056 publishing: use new helper method
Matt Mackall <mpm@selenic.com>
parents: 25614
diff changeset
  1070
    if repo.publishing():
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
  1071
        # 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
  1072
        # 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
  1073
        # 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
  1074
        # push phase boundary
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1075
        #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
  1076
        # 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
  1077
        # 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
  1078
        # 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
  1079
        #
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1080
        # 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
  1081
        # 2) repo B make changeset X public
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
  1082
        # 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
  1083
        #    X as now public should
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1084
        #
16725
b0fb4f57d076 phases: wrap docstrings at 70 characters
Martin Geisler <martin@geisler.net>
parents: 16724
diff changeset
  1085
        # 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
  1086
        # client phase data.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1087
        keys[b'publishing'] = b'True'
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1088
    return keys
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1089
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1090
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1091
def pushphase(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1092
    repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1093
    nhex: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1094
    oldphasestr: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1095
    newphasestr: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1096
) -> bool:
17535
63e302be813f en-us: serialization
timeless@mozdev.org
parents: 17205
diff changeset
  1097
    """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
  1098
    repo = repo.unfiltered()
27861
3315a9c2019c with: use context manager for lock in pushphase
Bryan O'Sullivan <bryano@fb.com>
parents: 26909
diff changeset
  1099
    with repo.lock():
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1100
        currentphase = repo[nhex].phase()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1101
        newphase = abs(int(newphasestr))  # let's avoid negative index surprise
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1102
        oldphase = abs(int(oldphasestr))  # let's avoid negative index surprise
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1103
        if currentphase == oldphase and newphase < oldphase:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1104
            with repo.transaction(b'pushkey-phase') as tr:
27861
3315a9c2019c with: use context manager for lock in pushphase
Bryan O'Sullivan <bryano@fb.com>
parents: 26909
diff changeset
  1105
                advanceboundary(repo, tr, newphase, [bin(nhex)])
32822
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32000
diff changeset
  1106
            return True
16051
2aa5b51f310f phases: don't complain if cset is already public on pushkey (issue3230)
Matt Mackall <mpm@selenic.com>
parents: 16030
diff changeset
  1107
        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
  1108
            # raced, but got correct result
32822
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32000
diff changeset
  1109
            return True
15648
79cc89de5be1 phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15482
diff changeset
  1110
        else:
32822
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32000
diff changeset
  1111
            return False
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
  1112
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1113
33031
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1114
def subsetphaseheads(repo, subset):
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1115
    """Finds the phase heads for a subset of a history
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1116
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1117
    Returns a list indexed by phase number where each item is a list of phase
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1118
    head nodes.
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1119
    """
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1120
    cl = repo.changelog
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1121
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
  1122
    headsbyphase = {i: [] for i in allphases}
50392
385a4f8056e5 bundle: include required phases when saving a bundle (issue6794)
Jason R. Coombs <jaraco@jaraco.com>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50387
diff changeset
  1123
    for phase in allphases:
385a4f8056e5 bundle: include required phases when saving a bundle (issue6794)
Jason R. Coombs <jaraco@jaraco.com>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50387
diff changeset
  1124
        revset = b"heads(%%ln & _phase(%d))" % phase
33031
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1125
        headsbyphase[phase] = [cl.node(r) for r in repo.revs(revset, subset)]
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1126
    return headsbyphase
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1127
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1128
34321
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34320
diff changeset
  1129
def updatephases(repo, trgetter, headsbyphase):
33031
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1130
    """Updates the repo with the given phase heads"""
45116
361a7444bc41 phases: updatephases should not skip internal phase
Joerg Sonnenberger <joerg@bec.de>
parents: 45114
diff changeset
  1131
    # Now advance phase boundaries of all phases
34321
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34320
diff changeset
  1132
    #
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34320
diff changeset
  1133
    # run the update (and fetch transaction) only if there are actually things
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34320
diff changeset
  1134
    # to update. This avoid creating empty transaction during no-op operation.
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34320
diff changeset
  1135
45116
361a7444bc41 phases: updatephases should not skip internal phase
Joerg Sonnenberger <joerg@bec.de>
parents: 45114
diff changeset
  1136
    for phase in allphases:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1137
        revset = b'%ln - _phase(%s)'
39293
278eb4541758 phases: simplify revset in updatephases
Boris Feld <boris.feld@octobus.net>
parents: 39275
diff changeset
  1138
        heads = [c.node() for c in repo.set(revset, headsbyphase[phase], phase)]
34321
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34320
diff changeset
  1139
        if heads:
4ef472b975ff bundle2: only grab a transaction when 'phase-heads' affect the repository
Boris Feld <boris.feld@octobus.net>
parents: 34320
diff changeset
  1140
            advanceboundary(repo, trgetter(), phase, heads)
33031
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 32822
diff changeset
  1141
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1142
51581
e0194b3ea312 phases: use revision number in analyze_remote_phases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51580
diff changeset
  1143
def analyze_remote_phases(
e0194b3ea312 phases: use revision number in analyze_remote_phases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51580
diff changeset
  1144
    repo,
e0194b3ea312 phases: use revision number in analyze_remote_phases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51580
diff changeset
  1145
    subset: Collection[int],
e0194b3ea312 phases: use revision number in analyze_remote_phases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51580
diff changeset
  1146
    roots: Dict[bytes, bytes],
e0194b3ea312 phases: use revision number in analyze_remote_phases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51580
diff changeset
  1147
) -> Tuple[Collection[int], Collection[int]]:
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
  1148
    """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
  1149
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
  1150
    * 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
  1151
    * 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
  1152
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
  1153
    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
  1154
    """
18002
9bc5873e52af clfilter: phases logic should be unfiltered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17979
diff changeset
  1155
    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
  1156
    # build list from dictionary
51579
87655e6dc108 phases: convert remote phase root to node while reading them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51578
diff changeset
  1157
    draft_roots = []
87655e6dc108 phases: convert remote phase root to node while reading them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51578
diff changeset
  1158
    to_rev = repo.changelog.index.get_rev
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
  1159
    for nhex, phase in roots.items():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1160
        if nhex == b'publishing':  # ignore data related to publish option
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
  1161
            continue
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
  1162
        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
  1163
        phase = int(phase)
28174
f16b84b1e40e phases: use constants for phase values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27874
diff changeset
  1164
        if phase == public:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46644
diff changeset
  1165
            if node != repo.nullid:
51578
231a92eb1936 phases: more compact error handling in analyzeremotephases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51517
diff changeset
  1166
                msg = _(b'ignoring inconsistent public root from remote: %s\n')
231a92eb1936 phases: more compact error handling in analyzeremotephases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51517
diff changeset
  1167
                repo.ui.warn(msg % nhex)
28174
f16b84b1e40e phases: use constants for phase values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27874
diff changeset
  1168
        elif phase == draft:
51579
87655e6dc108 phases: convert remote phase root to node while reading them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51578
diff changeset
  1169
            rev = to_rev(node)
87655e6dc108 phases: convert remote phase root to node while reading them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51578
diff changeset
  1170
            if rev is not None:  # to filter unknown nodes
87655e6dc108 phases: convert remote phase root to node while reading them
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51578
diff changeset
  1171
                draft_roots.append(rev)
15892
592b3d1742a1 phases: simplify phase exchange and movement over pushkey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15821
diff changeset
  1172
        else:
51578
231a92eb1936 phases: more compact error handling in analyzeremotephases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51517
diff changeset
  1173
            msg = _(b'ignoring unexpected root from remote: %i %s\n')
231a92eb1936 phases: more compact error handling in analyzeremotephases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51517
diff changeset
  1174
            repo.ui.warn(msg % (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
  1175
    # compute heads
51581
e0194b3ea312 phases: use revision number in analyze_remote_phases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51580
diff changeset
  1176
    public_heads = new_heads(repo, subset, draft_roots)
e0194b3ea312 phases: use revision number in analyze_remote_phases
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51580
diff changeset
  1177
    return public_heads, draft_roots
15649
ca7c4254a21a phases: add a function to compute heads from root
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15648
diff changeset
  1178
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1179
51583
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1180
class RemotePhasesSummary:
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1181
    """summarize phase information on the remote side
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1182
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1183
    :publishing: True is the remote is publishing
51583
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1184
    :public_heads: list of remote public phase heads (revs)
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1185
    :draft_heads: list of remote draft phase heads (revs)
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1186
    :draft_roots: list of remote draft phase root (revs)
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1187
    """
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1188
51583
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1189
    def __init__(
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1190
        self,
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1191
        repo,
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1192
        remote_subset: Collection[int],
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1193
        remote_roots: Dict[bytes, bytes],
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1194
    ):
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1195
        unfi = repo.unfiltered()
51583
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1196
        self._allremoteroots: Dict[bytes, bytes] = remote_roots
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1197
51583
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1198
        self.publishing: bool = bool(remote_roots.get(b'publishing', False))
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1199
51583
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1200
        heads, roots = analyze_remote_phases(repo, remote_subset, remote_roots)
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1201
        self.public_heads: Collection[int] = heads
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1202
        self.draft_roots: Collection[int] = roots
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1203
        # Get the list of all "heads" revs draft on remote
51582
d8287e43540f phases: stop using `repo.set` in `remotephasessummary`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51581
diff changeset
  1204
        dheads = unfi.revs(b'heads(%ld::%ld)', roots, remote_subset)
51583
22cc679a7312 phases: move RemotePhasesSummary to revision number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51582
diff changeset
  1205
        self.draft_heads: Collection[int] = dheads
34819
eb6375651974 phase: gather remote phase information in a summary object
Boris Feld <boris.feld@octobus.net>
parents: 34816
diff changeset
  1206
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1207
51580
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1208
def new_heads(
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1209
    repo,
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1210
    heads: Collection[int],
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1211
    roots: Collection[int],
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1212
) -> Collection[int]:
15954
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
  1213
    """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
  1214
b345f851d056 phase: extracts heads computation logics from analyzeremotephases
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15953
diff changeset
  1215
    * `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
  1216
    * `roots`: define the second we subtract from the first"""
39146
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1217
    # prevent an import cycle
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1218
    # phases > dagop > patch > copies > scmutil > obsolete > obsutil > phases
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1219
    from . import dagop
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1220
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1221
    if not roots:
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1222
        return heads
51580
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1223
    if not heads or heads == [nullrev]:
39146
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1224
        return []
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1225
    # The logic operated on revisions, convert arguments early for convenience
51580
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1226
    # PERF-XXX: maybe heads could directly comes as a set without impacting
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1227
    # other user of that value
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1228
    new_heads = set(heads)
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1229
    new_heads.discard(nullrev)
39146
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1230
    # compute the area we need to remove
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1231
    affected_zone = repo.revs(b"(%ld::%ld)", roots, new_heads)
39146
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1232
    # heads in the area are no longer heads
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1233
    new_heads.difference_update(affected_zone)
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1234
    # revisions in the area have children outside of it,
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1235
    # They might be new heads
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1236
    candidates = repo.revs(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1237
        b"parents(%ld + (%ld and merge())) and not null", roots, affected_zone
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1238
    )
39146
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1239
    candidates -= affected_zone
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1240
    if new_heads or candidates:
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1241
        # remove candidate that are ancestors of other heads
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1242
        new_heads.update(candidates)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1243
        prunestart = repo.revs(b"parents(%ld) and not null", new_heads)
39146
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1244
        pruned = dagop.reachableroots(repo, candidates, prunestart)
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1245
        new_heads.difference_update(pruned)
f736fdbe546a remotephase: avoid full changelog iteration (issue5964)
Boris Feld <boris.feld@octobus.net>
parents: 39141
diff changeset
  1246
51580
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1247
    # PERF-XXX: do we actually need a sorted list here? Could we simply return
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1248
    # a set?
b70628a9aa7e phases: use revision number in new_heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51579
diff changeset
  1249
    return sorted(new_heads)
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
  1250
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1251
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1252
def newcommitphase(ui: "uimod.ui") -> int:
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
  1253
    """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
  1254
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
  1255
    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
  1256
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
  1257
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1258
    v = ui.config(b'phases', b'new-commit')
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
  1259
    try:
45117
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
  1260
        return phasenumber2[v]
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
  1261
    except KeyError:
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
  1262
        raise error.ConfigError(
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
  1263
            _(b"phases.new-commit: not a valid phase name ('%s')") % v
b1e51ef4e536 phases: sparsify phase lists
Joerg Sonnenberger <joerg@bec.de>
parents: 45116
diff changeset
  1264
        )
16030
308406677e9d phases: allow phase name in phases.new-commit settings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 16025
diff changeset
  1265
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1266
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1267
def hassecret(repo: "localrepo.localrepository") -> bool:
17671
fdd0fc046cf1 clfilter: introduce a `hassecret` function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17537
diff changeset
  1268
    """utility function that check if a repo have any secret changeset."""
51403
68289ed170c7 phases: mark `phasecache.phaseroots` private
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51401
diff changeset
  1269
    return bool(repo._phasecache._phaseroots[secret])
34710
cdf833d7de98 phase: add a dedicated txnclose-phase hook
Boris Feld <boris.feld@octobus.net>
parents: 34563
diff changeset
  1270
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40580
diff changeset
  1271
51287
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1272
def preparehookargs(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1273
    node: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1274
    old: Optional[int],
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1275
    new: Optional[int],
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51285
diff changeset
  1276
) -> Dict[bytes, bytes]:
34710
cdf833d7de98 phase: add a dedicated txnclose-phase hook
Boris Feld <boris.feld@octobus.net>
parents: 34563
diff changeset
  1277
    if old is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1278
        old = b''
34710
cdf833d7de98 phase: add a dedicated txnclose-phase hook
Boris Feld <boris.feld@octobus.net>
parents: 34563
diff changeset
  1279
    else:
34876
eb1b964b354b phases: pass phase names to hooks instead of internal values
Kevin Bullock <kbullock+mercurial@ringworld.org>
parents: 34819
diff changeset
  1280
        old = phasenames[old]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1281
    return {b'node': node, b'oldphase': old, b'phase': phasenames[new]}