mercurial/stabletailgraph/stabletailsort.py
author Matt Harbison <matt_harbison@yahoo.com>
Thu, 12 Sep 2024 16:27:58 -0400
changeset 51860 1c5810ce737e
parent 50525 8fb3e942473a
permissions -rw-r--r--
typing: add `from __future__ import annotations` to remaining source files Most of these look newer than when the original imports referenced in the previous commit were dropped, so these weren't covered by the backout. These were found with: hg files mercurial hgext hgext3rd -I '**.py' -X '**/thirdparty' \ | xargs grep -L 'from __future__ import annotations' All of the `__init__.py` files that finds are empty, so those were ignored and the rest manually edited.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50423
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     1
# stabletailsort.py - stable ordering of revisions
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     2
#
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     3
# Copyright 2021-2023 Pacien TRAN-GIRARD <pacien.trangirard@pacien.net>
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     4
#
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     7
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     8
"""
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
     9
Stable-tail sort computation.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    10
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    11
The "stable-tail sort", or STS, is a reverse topological ordering of the
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    12
ancestors of a node, which tends to share large suffixes with the stable-tail
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    13
sort of ancestors and other nodes, giving it its name.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    14
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    15
Its properties should make it suitable for making chunks of ancestors with high
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    16
reuse and incrementality for example.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    17
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    18
This module and implementation are experimental. Most functions are not yet
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    19
optimised to operate on large production graphs.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    20
"""
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    21
51860
1c5810ce737e typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents: 50525
diff changeset
    22
from __future__ import annotations
1c5810ce737e typing: add `from __future__ import annotations` to remaining source files
Matt Harbison <matt_harbison@yahoo.com>
parents: 50525
diff changeset
    23
50423
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    24
import itertools
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    25
from ..node import nullrev
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    26
from .. import ancestor
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    27
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    28
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    29
def _sorted_parents(cl, p1, p2):
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    30
    """
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    31
    Chooses and returns the pair (px, pt) from (p1, p2).
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    32
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    33
    Where
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    34
    "px" denotes the parent starting the "exclusive" part, and
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    35
    "pt" denotes the parent starting the "Tail" part.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    36
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    37
    "px" is chosen as the parent with the lowest rank with the goal of
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    38
    minimising the size of the exclusive part and maximise the size of the
50456
e1496403b08c stabletailgraph: fix terminology in doc
pacien <pacien.trangirard@pacien.net>
parents: 50423
diff changeset
    39
    tail part, hopefully reducing the overall complexity of the stable-tail
e1496403b08c stabletailgraph: fix terminology in doc
pacien <pacien.trangirard@pacien.net>
parents: 50423
diff changeset
    40
    sort.
50423
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    41
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    42
    In case of equal ranks, the stable node ID is used as a tie-breaker.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    43
    """
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    44
    r1, r2 = cl.fast_rank(p1), cl.fast_rank(p2)
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    45
    if r1 < r2:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    46
        return (p1, p2)
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    47
    elif r1 > r2:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    48
        return (p2, p1)
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    49
    elif cl.node(p1) < cl.node(p2):
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    50
        return (p1, p2)
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    51
    else:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    52
        return (p2, p1)
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    53
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    54
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    55
def _nonoedipal_parent_revs(cl, rev):
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    56
    """
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    57
    Returns the non-œdipal parent pair of the given revision.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    58
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    59
    An œdipal merge is a merge with parents p1, p2 with either
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    60
    p1 in ancestors(p2) or p2 in ancestors(p1).
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    61
    In the first case, p1 is the œdipal parent.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    62
    In the second case, p2 is the œdipal parent.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    63
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    64
    Œdipal edges start empty exclusive parts. They do not bring new ancestors.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    65
    As such, they can be skipped when computing any topological sort or any
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    66
    iteration over the ancestors of a node.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    67
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    68
    The œdipal edges are eliminated here using the rank information.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    69
    """
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    70
    p1, p2 = cl.parentrevs(rev)
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    71
    if p1 == nullrev or cl.fast_rank(p2) == cl.fast_rank(rev) - 1:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    72
        return p2, nullrev
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    73
    elif p2 == nullrev or cl.fast_rank(p1) == cl.fast_rank(rev) - 1:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    74
        return p1, nullrev
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    75
    else:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    76
        return p1, p2
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    77
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    78
50524
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    79
def _parents(cl, rev):
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    80
    p1, p2 = _nonoedipal_parent_revs(cl, rev)
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    81
    if p2 == nullrev:
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    82
        return p1, p2
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    83
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    84
    return _sorted_parents(cl, p1, p2)
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    85
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
    86
50522
1a4f54574e3d stabletailgraph: clarify naiveness of current implementation
pacien <pacien.trangirard@pacien.net>
parents: 50456
diff changeset
    87
def _stable_tail_sort_naive(cl, head_rev):
50423
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    88
    """
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    89
    Naive topological iterator of the ancestors given by the stable-tail sort.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    90
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    91
    The stable-tail sort of a node "h" is defined as the sequence:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    92
    sts(h) := [h] + excl(h) + sts(pt(h))
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    93
    where excl(h) := u for u in sts(px(h)) if u not in ancestors(pt(h))
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    94
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    95
    This implementation uses a call-stack whose size is
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    96
    O(number of open merges).
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    97
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    98
    As such, this implementation exists mainly as a defining reference.
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
    99
    """
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   100
    cursor_rev = head_rev
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   101
    while cursor_rev != nullrev:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   102
        yield cursor_rev
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   103
50524
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
   104
        px, pt = _parents(cl, cursor_rev)
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
   105
        if pt == nullrev:
dc372251d4dc stabletailgraph: extract _parents util func
pacien <pacien.trangirard@pacien.net>
parents: 50523
diff changeset
   106
            cursor_rev = px
50423
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   107
        else:
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   108
            tail_ancestors = ancestor.lazyancestors(
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   109
                cl.parentrevs, (pt,), inclusive=True
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   110
            )
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   111
            exclusive_ancestors = (
50522
1a4f54574e3d stabletailgraph: clarify naiveness of current implementation
pacien <pacien.trangirard@pacien.net>
parents: 50456
diff changeset
   112
                a
1a4f54574e3d stabletailgraph: clarify naiveness of current implementation
pacien <pacien.trangirard@pacien.net>
parents: 50456
diff changeset
   113
                for a in _stable_tail_sort_naive(cl, px)
1a4f54574e3d stabletailgraph: clarify naiveness of current implementation
pacien <pacien.trangirard@pacien.net>
parents: 50456
diff changeset
   114
                if a not in tail_ancestors
50423
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   115
            )
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   116
50523
4fd2f7ab4177 stabletailgraph: clarify excl part size computation
pacien <pacien.trangirard@pacien.net>
parents: 50522
diff changeset
   117
            # Notice that excl(cur) is disjoint from ancestors(pt),
4fd2f7ab4177 stabletailgraph: clarify excl part size computation
pacien <pacien.trangirard@pacien.net>
parents: 50522
diff changeset
   118
            # so there is no double-counting:
4fd2f7ab4177 stabletailgraph: clarify excl part size computation
pacien <pacien.trangirard@pacien.net>
parents: 50522
diff changeset
   119
            # rank(cur) = len([cur]) + len(excl(cur)) + rank(pt)
50423
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   120
            excl_part_size = cl.fast_rank(cursor_rev) - cl.fast_rank(pt) - 1
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   121
            yield from itertools.islice(exclusive_ancestors, excl_part_size)
f0d2b18f0274 stabletailgraph: implement stable-tail sort
pacien <pacien.trangirard@pacien.net>
parents:
diff changeset
   122
            cursor_rev = pt
50525
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   123
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   124
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   125
def _find_all_leaps_naive(cl, head_rev):
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   126
    """
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   127
    Yields the leaps in the stable-tail sort of the given revision.
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   128
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   129
    A leap is a pair of revisions (source, target) consecutive in the
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   130
    stable-tail sort of a head, for which target != px(source).
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   131
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   132
    Leaps are yielded in the same order as encountered in the stable-tail sort,
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   133
    from head to root.
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   134
    """
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   135
    sts = _stable_tail_sort_naive(cl, head_rev)
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   136
    prev = next(sts)
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   137
    for current in sts:
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   138
        if current != _parents(cl, prev)[0]:
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   139
            yield (prev, current)
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   140
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   141
        prev = current
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   142
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   143
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   144
def _find_specific_leaps_naive(cl, head_rev):
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   145
    """
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   146
    Returns the specific leaps in the stable-tail sort of the given revision.
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   147
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   148
    Specific leaps are leaps appear in the stable-tail sort of a given
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   149
    revision, but not in the stable-tail sort of any of its ancestors.
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   150
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   151
    The final leaps (leading to the pt of the considered merge) are omitted.
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   152
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   153
    Only merge nodes can have associated specific leaps.
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   154
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   155
    This implementations uses the whole leap sets of the given revision and
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   156
    of its parents.
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   157
    """
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   158
    px, pt = _parents(cl, head_rev)
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   159
    if px == nullrev or pt == nullrev:
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   160
        return  # linear nodes cannot have specific leaps
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   161
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   162
    parents_leaps = set(_find_all_leaps_naive(cl, px))
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   163
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   164
    sts = _stable_tail_sort_naive(cl, head_rev)
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   165
    prev = next(sts)
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   166
    for current in sts:
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   167
        if current == pt:
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   168
            break
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   169
        if current != _parents(cl, prev)[0]:
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   170
            leap = (prev, current)
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   171
            if leap not in parents_leaps:
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   172
                yield leap
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   173
8fb3e942473a stabletailgraph: naive version of leap computation
pacien <pacien.trangirard@pacien.net>
parents: 50524
diff changeset
   174
        prev = current