hgext3rd/evolve/obshistory.py
author Boris Feld <boris.feld@octobus.net>
Tue, 30 May 2017 11:39:45 +0200
changeset 2520 5fb5d096348c
parent 2492 c9f1118b33d6
child 2522 a1cc2a0b9f6f
permissions -rw-r--r--
effectflag: better diff detection Improve the diff detection algorithm to have less false positive like in the case of a rebase that move the hunk in the file but the hunk stays the same.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     1
# Code dedicated to display and exploration of the obsolescence history
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     2
#
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     3
# This module content aims at being upstreamed enventually.
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     4
#
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     5
# Copyright 2017 Octobus SAS <contact@octobus.net>
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     6
#
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     7
# This software may be used and distributed according to the terms of the
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     8
# GNU General Public License version 2 or any later version.
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     9
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    10
from mercurial import (
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    11
    cmdutil,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    12
    commands,
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    13
    error,
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    14
    graphmod,
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
    15
    obsolete,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    16
    node as nodemod,
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    17
    scmutil,
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    18
)
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    19
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    20
from mercurial.i18n import _
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    21
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    22
from . import (
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    23
    exthelper,
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    24
)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    25
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    26
eh = exthelper.exthelper()
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    27
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    28
@eh.command(
2441
80b5fc054219 evolve: adding longer aliases for olog
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 2418
diff changeset
    29
    'obslog|olog',
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    30
    [('G', 'graph', True, _("show the revision DAG")),
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
    31
     ('r', 'rev', [], _('show the specified revision or revset'), _('REV')),
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
    32
     ('a', 'all', False, _('show all related changesets, not only precursors'))
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    33
    ] + commands.formatteropts,
2416
23c0bef0b5d4 obshistory: rename the command to "olog"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2415
diff changeset
    34
    _('hg olog [OPTION]... [REV]'))
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    35
def cmdobshistory(ui, repo, *revs, **opts):
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    36
    """show the obsolescence history of the specified revisions.
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    37
2418
4993d1812311 olog: document the default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2416
diff changeset
    38
    If no revision range is specified, we display the log for the current
4993d1812311 olog: document the default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2416
diff changeset
    39
    working copy parent.
4993d1812311 olog: document the default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2416
diff changeset
    40
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    41
    By default this command prints the selected revisions and all its
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    42
    precursors. For precursors pointing on existing revisions in the repository,
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    43
    it will display revisions node id, revision number and the first line of the
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    44
    description. For precursors pointing on non existing revisions in the
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    45
    repository (that can happen when exchanging obsolescence-markers), display
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    46
    only the node id.
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    47
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    48
    In both case, for each node, its obsolescence marker will be displayed with
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    49
    the obsolescence operation (rewritten or pruned) in addition of the user and
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    50
    date of the operation.
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    51
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    52
    The output is a graph by default but can deactivated with the option '--no-
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    53
    graph'.
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    54
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    55
    'o' is a changeset, '@' is a working directory parent, 'x' is obsolete,
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    56
    and '+' represents a fork where the changeset from the lines below is a
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    57
    parent of the 'o' merge on the same line.
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    58
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    59
    Paths in the DAG are represented with '|', '/' and so forth.
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    60
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    61
    Returns 0 on success.
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    62
    """
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    63
    revs = list(revs) + opts['rev']
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    64
    if not revs:
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    65
        revs = ['.']
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    66
    revs = scmutil.revrange(repo, revs)
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    67
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    68
    if opts['graph']:
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    69
        return _debugobshistorygraph(ui, repo, revs, opts)
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    70
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    71
    fm = ui.formatter('debugobshistory', opts)
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    72
    revs.reverse()
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    73
    _debugobshistorysingle(fm, repo, revs)
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    74
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    75
    fm.end()
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    76
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    77
class obsmarker_printer(cmdutil.changeset_printer):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    78
    """show (available) information about a node
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    79
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    80
    We display the node, description (if available) and various information
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    81
    about obsolescence markers affecting it"""
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    82
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    83
    def show(self, ctx, copies=None, matchfn=None, **props):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    84
        if self.buffered:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    85
            self.ui.pushbuffer(labeled=True)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    86
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    87
            changenode = ctx.node()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    88
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    89
            fm = self.ui.formatter('debugobshistory', props)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    90
            _debugobshistorydisplaynode(fm, self.repo, changenode)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    91
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    92
            succs = self.repo.obsstore.successors.get(changenode, ())
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    93
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    94
            markerfm = fm.nested("debugobshistory.markers")
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    95
            for successor in sorted(succs):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    96
                _debugobshistorydisplaymarker(markerfm, self.repo, successor)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    97
            markerfm.end()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    98
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    99
            markerfm.plain('\n')
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   100
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   101
            self.hunk[ctx.node()] = self.ui.popbuffer()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   102
        else:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   103
            ### graph output is buffered only
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   104
            msg = 'cannot be used outside of the graphlog (yet)'
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   105
            raise error.ProgrammingError(msg)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   106
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   107
    def flush(self, ctx):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   108
        ''' changeset_printer has some logic around buffering data
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   109
        in self.headers that we don't use
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   110
        '''
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   111
        pass
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   112
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   113
class missingchangectx(object):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   114
    ''' a minimal object mimicking changectx for change contexts
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   115
    references by obs markers but not available locally '''
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   116
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   117
    def __init__(self, repo, nodeid):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   118
        self._repo = repo
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   119
        self._node = nodeid
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   120
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   121
    def node(self):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   122
        return self._node
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   123
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   124
    def obsolete(self):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   125
        # If we don't have it locally, it's obsolete
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   126
        return True
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   127
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   128
def cyclic(graph):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   129
    """Return True if the directed graph has a cycle.
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   130
    The graph must be represented as a dictionary mapping vertices to
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   131
    iterables of neighbouring vertices. For example:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   132
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   133
    >>> cyclic({1: (2,), 2: (3,), 3: (1,)})
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   134
    True
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   135
    >>> cyclic({1: (2,), 2: (3,), 3: (4,)})
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   136
    False
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   137
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   138
    Taken from: https://codereview.stackexchange.com/a/86067
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   139
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   140
    """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   141
    visited = set()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   142
    o = object()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   143
    path = [o]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   144
    path_set = set(path)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   145
    stack = [iter(graph)]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   146
    while stack:
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   147
        for v in sorted(stack[-1]):
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   148
            if v in path_set:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   149
                path_set.remove(o)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   150
                return path_set
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   151
            elif v not in visited:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   152
                visited.add(v)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   153
                path.append(v)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   154
                path_set.add(v)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   155
                stack.append(iter(graph.get(v, ())))
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   156
                break
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   157
        else:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   158
            path_set.remove(path.pop())
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   159
            stack.pop()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   160
    return False
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   161
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   162
def _obshistorywalker(repo, revs, walksuccessors=False):
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   163
    """ Directly inspired by graphmod.dagwalker,
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   164
    walk the obs marker tree and yield
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   165
    (id, CHANGESET, ctx, [parentinfo]) tuples
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   166
    """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   167
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   168
    # Get the list of nodes and links between them
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   169
    candidates, nodesucc, nodeprec = _obshistorywalker_links(repo, revs, walksuccessors)
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   170
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   171
    # Shown, set of nodes presents in items
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   172
    shown = set()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   173
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   174
    def isvalidcandidate(candidate):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   175
        """ Function to filter candidates, check the candidate succ are
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   176
        in shown set
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   177
        """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   178
        return nodesucc.get(candidate, set()).issubset(shown)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   179
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   180
    # While we have some nodes to show
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   181
    while candidates:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   182
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   183
        # Filter out candidates, returns only nodes with all their successors
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   184
        # already shown
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   185
        validcandidates = filter(isvalidcandidate, candidates)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   186
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   187
        # If we likely have a cycle
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   188
        if not validcandidates:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   189
            cycle = cyclic(nodesucc)
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   190
            assert cycle
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   191
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   192
            # Then choose a random node from the cycle
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   193
            breaknode = sorted(cycle)[0]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   194
            # And display it by force
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   195
            repo.ui.debug('obs-cycle detected, forcing display of %s\n'
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   196
                          % nodemod.short(breaknode))
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   197
            validcandidates = [breaknode]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   198
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   199
        # Display all valid candidates
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   200
        for cand in sorted(validcandidates):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   201
            # Remove candidate from candidates set
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   202
            candidates.remove(cand)
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   203
            # And remove it from nodesucc in case of future cycle detected
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   204
            try:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   205
                del nodesucc[cand]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   206
            except KeyError:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   207
                pass
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   208
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   209
            shown.add(cand)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   210
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   211
            # Add the right changectx class
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   212
            if cand in repo:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   213
                changectx = repo[cand]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   214
            else:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   215
                changectx = missingchangectx(repo, cand)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   216
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   217
            childrens = [(graphmod.PARENT, x) for x in nodeprec.get(cand, ())]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   218
            yield (cand, 'M', changectx, childrens)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   219
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   220
def _obshistorywalker_links(repo, revs, walksuccessors=False):
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   221
    """ Iterate the obs history tree starting from revs, traversing
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   222
    each revision precursors recursively.
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   223
    If walksuccessors is True, also check that every successor has been
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   224
    walked, which ends up walking on all connected obs markers. It helps
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   225
    getting a better view with splits and divergences.
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   226
    Return a tuple of:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   227
    - The list of node crossed
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   228
    - The dictionnary of each node successors, values are a set
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   229
    - The dictionnary of each node precursors, values are a list
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   230
    """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   231
    precursors = repo.obsstore.precursors
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   232
    successors = repo.obsstore.successors
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   233
    nodec = repo.changelog.node
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   234
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   235
    # Parents, set of parents nodes seen during walking the graph for node
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   236
    nodesucc = dict()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   237
    # Childrens
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   238
    nodeprec = dict()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   239
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   240
    nodes = [nodec(r) for r in revs]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   241
    seen = set(nodes)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   242
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   243
    # Iterate on each node
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   244
    while nodes:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   245
        node = nodes.pop()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   246
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   247
        precs = precursors.get(node, ())
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   248
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   249
        nodeprec[node] = []
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   250
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   251
        for prec in sorted(precs):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   252
            precnode = prec[0]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   253
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   254
            # Mark node as prec successor
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   255
            nodesucc.setdefault(precnode, set()).add(node)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   256
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   257
            # Mark precnode as node precursor
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   258
            nodeprec[node].append(precnode)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   259
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   260
            # Add prec for future processing if not node already processed
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   261
            if precnode not in seen:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   262
                seen.add(precnode)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   263
                nodes.append(precnode)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   264
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   265
        # Also walk on successors if the option is enabled
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   266
        if walksuccessors:
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   267
            for successor in successors.get(node, ()):
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   268
                for succnodeid in successor[1]:
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   269
                    if succnodeid not in seen:
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   270
                        seen.add(succnodeid)
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   271
                        nodes.append(succnodeid)
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   272
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   273
    return sorted(seen), nodesucc, nodeprec
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   274
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   275
def _debugobshistorygraph(ui, repo, revs, opts):
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   276
    displayer = obsmarker_printer(ui, repo.unfiltered(), None, opts, buffered=True)
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   277
    edges = graphmod.asciiedges
2484
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   278
    walker = _obshistorywalker(repo.unfiltered(), revs, opts.get('all', False))
262d684851dc obshistory: add the all option to obslog to show the while obs tree
Boris Feld <boris.feld@octobus.net>
parents: 2463
diff changeset
   279
    cmdutil.displaygraph(ui, repo, walker, displayer, edges)
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   280
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   281
def _debugobshistorysingle(fm, repo, revs):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   282
    """ Display the obsolescence history for a single revision
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   283
    """
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   284
    precursors = repo.obsstore.precursors
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   285
    successors = repo.obsstore.successors
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   286
    nodec = repo.changelog.node
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   287
    nodes = [nodec(r) for r in revs]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   288
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   289
    seen = set(nodes)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   290
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   291
    while nodes:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   292
        ctxnode = nodes.pop()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   293
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   294
        _debugobshistorydisplaynode(fm, repo, ctxnode)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   295
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   296
        succs = successors.get(ctxnode, ())
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   297
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   298
        markerfm = fm.nested("debugobshistory.markers")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   299
        for successor in sorted(succs):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   300
            _debugobshistorydisplaymarker(markerfm, repo, successor)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   301
        markerfm.end()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   302
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   303
        precs = precursors.get(ctxnode, ())
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   304
        for p in sorted(precs):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   305
            # Only show nodes once
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   306
            if p[0] not in seen:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   307
                seen.add(p[0])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   308
                nodes.append(p[0])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   309
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   310
def _debugobshistorydisplaynode(fm, repo, node):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   311
    if node in repo.unfiltered():
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   312
        _debugobshistorydisplayctx(fm, repo.unfiltered()[node])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   313
    else:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   314
        _debugobshistorydisplaymissingctx(fm, node)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   315
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   316
def _debugobshistorydisplayctx(fm, ctx):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   317
    shortdescription = ctx.description().splitlines()[0]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   318
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   319
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   320
    fm.write('debugobshistory.node', '%s', str(ctx),
2404
c07f752137f4 label: rename 'evolve.short_node' to 'evolve.node'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2403
diff changeset
   321
             label="evolve.node")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   322
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   323
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   324
    fm.write('debugobshistory.rev', '(%d)', int(ctx),
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   325
             label="evolve.rev")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   326
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   327
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   328
    fm.write('debugobshistory.shortdescription', '%s', shortdescription,
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   329
             label="evolve.short_description")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   330
    fm.plain('\n')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   331
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   332
def _debugobshistorydisplaymissingctx(fm, nodewithoutctx):
2406
31255706b591 obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2404
diff changeset
   333
    hexnode = nodemod.short(nodewithoutctx)
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   334
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   335
    fm.write('debugobshistory.node', '%s', hexnode,
2404
c07f752137f4 label: rename 'evolve.short_node' to 'evolve.node'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2403
diff changeset
   336
             label="evolve.node evolve.missing_change_ctx")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   337
    fm.plain('\n')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   338
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   339
def _debugobshistorydisplaymarker(fm, repo, marker):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   340
    succnodes = marker[1]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   341
    date = marker[4]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   342
    metadata = dict(marker[3])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   343
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   344
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   345
    fm.plain('  ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   346
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   347
    # Detect pruned revisions
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   348
    if len(succnodes) == 0:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   349
        verb = 'pruned'
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   350
    else:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   351
        verb = 'rewritten'
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   352
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   353
    fm.write('debugobshistory.verb', '%s', verb,
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   354
             label="evolve.verb")
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   355
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   356
    effectflag = metadata.get('ef1')
2455
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   357
    if effectflag is not None:
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   358
        try:
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   359
            effectflag = int(effectflag)
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   360
        except ValueError:
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   361
            effectflag = None
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   362
    if effectflag:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   363
        effect = []
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   364
2456
63be7982d593 effectflag: add a small comment to suggest improvement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2455
diff changeset
   365
        # XXX should be a dict
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   366
        if effectflag & DESCCHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   367
            effect.append('description')
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   368
        if effectflag & METACHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   369
            effect.append('meta')
2492
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   370
        if effectflag & USERCHANGED:
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   371
            effect.append('user')
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   372
        if effectflag & DATECHANGED:
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   373
            effect.append('date')
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   374
        if effectflag & BRANCHCHANGED:
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   375
            effect.append('branch')
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   376
        if effectflag & PARENTCHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   377
            effect.append('parent')
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   378
        if effectflag & DIFFCHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   379
            effect.append('content')
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   380
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   381
        if effect:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   382
            fmteffect = fm.formatlist(effect, 'debugobshistory.effect', sep=', ')
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   383
            fm.write('debugobshistory.effect', '(%s)', fmteffect)
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   384
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   385
    fm.plain(' by ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   386
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   387
    fm.write('debugobshistory.marker_user', '%s', metadata['user'],
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   388
             label="evolve.user")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   389
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   390
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   391
    fm.write('debugobshistory.marker_date', '(%s)', fm.formatdate(date),
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   392
             label="evolve.date")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   393
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   394
    if len(succnodes) > 0:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   395
        fm.plain(' as ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   396
2406
31255706b591 obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2404
diff changeset
   397
        shortsnodes = (nodemod.short(succnode) for succnode in sorted(succnodes))
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   398
        nodes = fm.formatlist(shortsnodes, 'debugobshistory.succnodes', sep=', ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   399
        fm.write('debugobshistory.succnodes', '%s', nodes,
2404
c07f752137f4 label: rename 'evolve.short_node' to 'evolve.node'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2403
diff changeset
   400
                 label="evolve.node")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   401
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   402
    fm.plain("\n")
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   403
2454
400dbec0849c effetflag: move the flag back with the test of the creation logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2453
diff changeset
   404
# logic around storing and using effect flags
400dbec0849c effetflag: move the flag back with the test of the creation logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2453
diff changeset
   405
DESCCHANGED = 1 << 0 # action changed the description
2492
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   406
METACHANGED = 1 << 1 # action change the meta (user, date, branch, etc...) OLD
2454
400dbec0849c effetflag: move the flag back with the test of the creation logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2453
diff changeset
   407
PARENTCHANGED = 1 << 2 # action change the parent
400dbec0849c effetflag: move the flag back with the test of the creation logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2453
diff changeset
   408
DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset
2492
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   409
USERCHANGED = 1 << 4 # the user changed
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   410
DATECHANGED = 1 << 5 # the date changed
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   411
BRANCHCHANGED = 1 << 6 # the branch changed
2454
400dbec0849c effetflag: move the flag back with the test of the creation logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2453
diff changeset
   412
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   413
def geteffectflag(relation):
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   414
    """compute the effect flag by comparing the source and destination"""
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   415
    effects = 0
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   416
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   417
    source = relation[0]
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   418
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   419
    for changectx in relation[1]:
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   420
        # Check if description has changed
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   421
        if changectx.description() != source.description():
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   422
            effects |= DESCCHANGED
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   423
2448
66f05d5f4769 effectflag: detect meta changes
Boris Feld <boris.feld@octobus.net>
parents: 2446
diff changeset
   424
        # Check if known meta has changed
2492
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   425
        if changectx.user() != source.user():
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   426
            effects |= USERCHANGED
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   427
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   428
        if changectx.date() != source.date():
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   429
            effects |= DATECHANGED
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   430
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   431
        if changectx.branch() != source.branch():
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   432
            effects |= BRANCHCHANGED
2448
66f05d5f4769 effectflag: detect meta changes
Boris Feld <boris.feld@octobus.net>
parents: 2446
diff changeset
   433
2449
0b05142117d2 effectflag: detect parent change
Boris Feld <boris.feld@octobus.net>
parents: 2448
diff changeset
   434
        # Check if at least one of the parent has changes
0b05142117d2 effectflag: detect parent change
Boris Feld <boris.feld@octobus.net>
parents: 2448
diff changeset
   435
        if changectx.parents() != source.parents():
0b05142117d2 effectflag: detect parent change
Boris Feld <boris.feld@octobus.net>
parents: 2448
diff changeset
   436
            effects |= PARENTCHANGED
0b05142117d2 effectflag: detect parent change
Boris Feld <boris.feld@octobus.net>
parents: 2448
diff changeset
   437
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   438
        if not _cmpdiff(source, changectx):
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   439
            effects |= DIFFCHANGED
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   440
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   441
    return effects
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   442
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   443
def _prepare_hunk(hunk):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   444
    """Drop all information but the username and patch"""
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   445
    cleanunk = []
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   446
    for line in hunk.splitlines():
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   447
        if line.startswith(b'# User') or not line.startswith(b'#'):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   448
            if line.startswith(b'@@'):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   449
                line = b'@@\n'
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   450
            cleanunk.append(line)
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   451
    return cleanunk
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   452
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   453
def _getdifflines(iterdiff):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   454
    """return a cleaned up lines"""
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   455
    try:
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   456
        lines = iterdiff.next()
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   457
    except StopIteration:
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   458
        return None
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   459
    return _prepare_hunk(lines)
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   460
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   461
def _cmpdiff(leftctx, rightctx):
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   462
    """return True if both ctx introduce the "same diff"
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   463
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   464
    This is a first and basic implementation, with many shortcoming.
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   465
    """
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   466
    leftdiff = leftctx.diff(git=1)
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   467
    rightdiff = rightctx.diff(git=1)
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   468
    left, right = (0, 0)
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   469
    while None not in (left, right):
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   470
        left = _getdifflines(leftdiff)
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   471
        right = _getdifflines(rightdiff)
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   472
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   473
        if left != right:
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   474
            return False
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   475
    return True
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   476
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   477
@eh.wrapfunction(obsolete, 'createmarkers')
2463
08c552a5eb37 obshistory: be more flexible about createmarkers API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2457
diff changeset
   478
def createmarkerswithbits(orig, repo, relations, flag=0, date=None,
08c552a5eb37 obshistory: be more flexible about createmarkers API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2457
diff changeset
   479
                          metadata=None, **kwargs):
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   480
    """compute 'effect-flag' and augment the created markers
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   481
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   482
    Wrap obsolete.createmarker in order to compute the effect of each
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   483
    relationship and store them as flag in the metadata.
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   484
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   485
    While we experiment, we store flag in a metadata field. This field is
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   486
    "versionned" to easilly allow moving to other meaning for flags.
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   487
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   488
    The comparison of description or other infos just before creating the obs
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   489
    marker might induce overhead in some cases. However it is a good place to
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   490
    start since it automatically makes all markers creation recording more
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   491
    meaningful data. In the future, we can introduce way for commands to
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   492
    provide precomputed effect to avoid the overhead.
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   493
    """
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   494
    if not repo.ui.configbool('experimental', 'evolution.effect-flags', False):
2463
08c552a5eb37 obshistory: be more flexible about createmarkers API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2457
diff changeset
   495
        return orig(repo, relations, flag, date, metadata, **kwargs)
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   496
    if metadata is None:
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   497
        metadata = {}
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   498
    tr = repo.transaction('add-obsolescence-marker')
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   499
    try:
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   500
        for r in relations:
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   501
            # Compute the effect flag for each obsmarker
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   502
            effect = geteffectflag(r)
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   503
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   504
            # Copy the metadata in order to add them, we copy because the
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   505
            # effect flag might be different per relation
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   506
            m = metadata.copy()
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   507
            # we store the effect even if "0". This disctinct markers created
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   508
            # without the feature with markers recording a no-op.
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   509
            m['ef1'] = "%d" % effect
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   510
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   511
            # And call obsolete.createmarkers for creating the obsmarker for real
2463
08c552a5eb37 obshistory: be more flexible about createmarkers API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2457
diff changeset
   512
            orig(repo, [r], flag, date, m, **kwargs)
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   513
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   514
        tr.close()
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   515
    finally:
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   516
        tr.release()
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   517
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   518
def _getobsfate(successorssets):
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   519
    """ Compute a changeset obsolescence fate based on his successorssets.
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   520
    Successors can be the tipmost ones or the immediate ones.
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   521
    Returns one fate in the following list:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   522
    - pruned
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   523
    - diverged
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   524
    - superseed
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   525
    - superseed_split
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   526
    """
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   527
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   528
    if len(successorssets) == 0:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   529
        # The commit has been pruned
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   530
        return 'pruned'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   531
    elif len(successorssets) > 1:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   532
        return 'diverged'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   533
    else:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   534
        # No divergence, only one set of successors
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   535
        successors = successorssets[0]
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   536
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   537
        if len(successors) == 1:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   538
            return 'superseed'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   539
        else:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   540
            return 'superseed_split'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   541
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   542
def _getobsfateandsuccs(repo, revnode, successorssets=None):
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   543
    """ Return a tuple containing:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   544
    - the reason a revision is obsolete (diverged, pruned or superseed)
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   545
    - the list of successors short node if the revision is neither pruned
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   546
    or has diverged
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   547
    """
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   548
    if successorssets is None:
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   549
        successorssets = obsolete.successorssets(repo, revnode)
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   550
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   551
    fate = _getobsfate(successorssets)
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   552
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   553
    # Apply node.short if we have no divergence
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   554
    if len(successorssets) == 1:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   555
        successors = [nodemod.short(node_id) for node_id in successorssets[0]]
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   556
    else:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   557
        successors = []
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   558
        for succset in successorssets:
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   559
            successors.append([nodemod.short(node_id) for node_id in succset])
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   560
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   561
    return (fate, successors)
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   562
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   563
def _humanizedobsfate(fate, successors):
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   564
    """ Returns a humanized string for a changeset fate and its successors
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   565
    """
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   566
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   567
    if fate == 'pruned':
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   568
        return 'pruned'
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   569
    elif fate == 'diverged':
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   570
        msgs = []
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   571
        for successorsset in successors:
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   572
            msgs.append('superseed as %s' % ','.join(successorsset))
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   573
        return ' + '.join(msgs)
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   574
    elif fate in ('superseed', 'superseed_split'):
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   575
        return 'superseed as %s' % ','.join(successors)