hgext3rd/evolve/obshistory.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 18 May 2017 11:29:23 +0200
changeset 2406 31255706b591
parent 2404 c07f752137f4
child 2407 783a74c60a5e
permissions -rw-r--r--
obshistory: import 'node' as 'nodemod' This simplify the next changeset.
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 (
2406
31255706b591 obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2404
diff changeset
    11
    node as nodemod,
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    12
)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    13
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    14
def _debugobshistorysingle(fm, repo, revs):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    15
    """ Display the obsolescence history for a single revision
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    16
    """
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    17
    precursors = repo.obsstore.precursors
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    18
    successors = repo.obsstore.successors
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    19
    nodec = repo.changelog.node
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    20
    nodes = [nodec(r) for r in revs]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    21
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    22
    seen = set(nodes)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    23
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    24
    while nodes:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    25
        ctxnode = nodes.pop()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    26
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    27
        _debugobshistorydisplaynode(fm, repo, ctxnode)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    28
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    29
        succs = successors.get(ctxnode, ())
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    30
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    31
        markerfm = fm.nested("debugobshistory.markers")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    32
        for successor in sorted(succs):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    33
            _debugobshistorydisplaymarker(markerfm, repo, successor)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    34
        markerfm.end()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    35
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    36
        precs = precursors.get(ctxnode, ())
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    37
        for p in sorted(precs):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    38
            # Only show nodes once
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    39
            if p[0] not in seen:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    40
                seen.add(p[0])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    41
                nodes.append(p[0])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    42
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    43
def _debugobshistorydisplaynode(fm, repo, node):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    44
    if node in repo.unfiltered():
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    45
        _debugobshistorydisplayctx(fm, repo.unfiltered()[node])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    46
    else:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    47
        _debugobshistorydisplaymissingctx(fm, node)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    48
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    49
def _debugobshistorydisplayctx(fm, ctx):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    50
    shortdescription = ctx.description().splitlines()[0]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    51
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    52
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    53
    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
    54
             label="evolve.node")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    55
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    56
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    57
    fm.write('debugobshistory.rev', '(%d)', int(ctx),
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    58
             label="evolve.rev")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    59
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    60
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    61
    fm.write('debugobshistory.shortdescription', '%s', shortdescription,
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    62
             label="evolve.short_description")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    63
    fm.plain('\n')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    64
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    65
def _debugobshistorydisplaymissingctx(fm, nodewithoutctx):
2406
31255706b591 obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2404
diff changeset
    66
    hexnode = nodemod.short(nodewithoutctx)
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    67
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    68
    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
    69
             label="evolve.node evolve.missing_change_ctx")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    70
    fm.plain('\n')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    71
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    72
def _debugobshistorydisplaymarker(fm, repo, marker):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    73
    succnodes = marker[1]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    74
    date = marker[4]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    75
    metadata = dict(marker[3])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    76
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    77
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    78
    fm.plain('  ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    79
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    80
    # Detect pruned revisions
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    81
    if len(succnodes) == 0:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    82
        verb = 'pruned'
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    83
    else:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    84
        verb = 'rewritten'
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    85
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    86
    fm.write('debugobshistory.verb', '%s', verb,
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    87
             label="evolve.verb")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    88
    fm.plain(' by ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    89
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    90
    fm.write('debugobshistory.marker_user', '%s', metadata['user'],
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    91
             label="evolve.user")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    92
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    93
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    94
    fm.write('debugobshistory.marker_date', '(%s)', fm.formatdate(date),
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    95
             label="evolve.date")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    96
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    97
    if len(succnodes) > 0:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    98
        fm.plain(' as ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    99
2406
31255706b591 obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2404
diff changeset
   100
        shortsnodes = (nodemod.short(succnode) for succnode in sorted(succnodes))
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   101
        nodes = fm.formatlist(shortsnodes, 'debugobshistory.succnodes', sep=', ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   102
        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
   103
                 label="evolve.node")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   104
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   105
    fm.plain("\n")