hgext3rd/evolve/obshistory.py
author Raphaël Gomès <rgomes@octobus.net>
Tue, 06 Aug 2019 11:07:16 +0200
changeset 4801 16c1398b0063
parent 4752 8a73a8df63b6
child 4814 48b30ff742cb
permissions -rw-r--r--
python3: prefix all regex to work with python 2 and 3
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
2522
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
    10
import re
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
    11
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    12
from mercurial import (
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    13
    commands,
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    14
    error,
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
    15
    graphmod,
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
    16
    patch,
3883
ed460e7ee8aa compat: drop compatibility hack for mercurial <4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3838
diff changeset
    17
    obsutil,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    18
    node as nodemod,
4752
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
    19
    pycompat,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    20
    scmutil,
3083
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
    21
    util,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    22
)
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    23
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    24
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
    25
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    26
from . import (
2693
f4b0351fa813 evolve: adapt to function migrate to obsutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2678
diff changeset
    27
    compat,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    28
    exthelper,
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    29
)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    30
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    31
eh = exthelper.exthelper()
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    32
3080
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    33
# Config
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    34
efd = {'default': True} # pass a default value unless the config is registered
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    35
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    36
@eh.extsetup
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    37
def enableeffectflags(ui):
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    38
    item = (getattr(ui, '_knownconfig', {})
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    39
            .get('experimental', {})
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    40
            .get('evolution.effect-flags'))
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    41
    if item is not None:
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    42
        item.default = True
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    43
        efd.clear()
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    44
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    45
@eh.command(
4715
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    46
    b'obslog|olog',
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    47
    [(b'G', b'graph', True, _(b"show the revision DAG")),
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    48
     (b'r', b'rev', [], _(b'show the specified revision or revset'), _(b'REV')),
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    49
     (b'a', b'all', False, _(b'show all related changesets, not only precursors')),
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    50
     (b'p', b'patch', False, _(b'show the patch between two obs versions')),
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    51
     (b'f', b'filternonlocal', False, _(b'filter out non local commits')),
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    52
     ] + commands.formatteropts,
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    53
    _(b'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
    54
def cmdobshistory(ui, repo, *revs, **opts):
3454
56277182c029 obslog: drop period from summary line in accordance with convention
Martin von Zweigbergk <martinvonz@google.com>
parents: 3407
diff changeset
    55
    """show the obsolescence history of the specified revisions
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    56
2418
4993d1812311 olog: document the default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2416
diff changeset
    57
    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
    58
    working copy parent.
4993d1812311 olog: document the default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2416
diff changeset
    59
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    60
    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
    61
    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
    62
    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
    63
    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
    64
    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
    65
    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
    66
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    67
    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
    68
    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
    69
    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
    70
2678
da2b3e5e4f69 docs: some fixes to the help text
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2640
diff changeset
    71
    The output is a graph by default but can deactivated with the option
da2b3e5e4f69 docs: some fixes to the help text
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2640
diff changeset
    72
    '--no-graph'.
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    73
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    74
    '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
    75
    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
    76
    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
    77
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    78
    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
    79
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    80
    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
    81
    """
3701
29c413a7dfb5 compat: drop compatibility layer for pager
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3697
diff changeset
    82
    ui.pager('obslog')
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    83
    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
    84
    if not revs:
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    85
        revs = ['.']
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    86
    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
    87
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    88
    if opts['graph']:
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    89
        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
    90
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    91
    revs.reverse()
2955
b899a94472fd obslog: uniformize `_debugobshistoryrevs` and `_debugobshistorygraph` arguments
Alain Leufroy
parents: 2954
diff changeset
    92
    _debugobshistoryrevs(ui, repo, revs, opts)
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    93
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
    94
def _successorsandmarkers(repo, ctx):
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
    95
    """compute the raw data needed for computing obsfate
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
    96
    Returns a list of dict, one dict per successors set
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
    97
    """
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
    98
    ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
    99
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   100
    # closestsuccessors returns an empty list for pruned revisions, remap it
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   101
    # into a list containing an empty list for future processing
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   102
    if ssets == []:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   103
        ssets = [[]]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   104
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   105
    # Try to recover pruned markers
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   106
    succsmap = repo.obsstore.successors
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   107
    fullsuccessorsets = [] # successor set + markers
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   108
    for sset in ssets:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   109
        if sset:
3932
35b2d201eb71 compat: fix obslog compatiblity with 4.3
Boris Feld <boris.feld@octobus.net>
parents: 3921
diff changeset
   110
            fullsuccessorsets.append(compat.wrap_succs(sset))
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   111
        else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   112
            # successorsset return an empty set() when ctx or one of its
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   113
            # successors is pruned.
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   114
            # In this case, walk the obs-markers tree again starting with ctx
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   115
            # and find the relevant pruning obs-makers, the ones without
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   116
            # successors.
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   117
            # Having these markers allow us to compute some information about
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   118
            # its fate, like who pruned this changeset and when.
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   119
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   120
            # XXX we do not catch all prune markers (eg rewritten then pruned)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   121
            # (fix me later)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   122
            foundany = False
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   123
            for mark in succsmap.get(ctx.node(), ()):
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   124
                if not mark[1]:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   125
                    foundany = True
3932
35b2d201eb71 compat: fix obslog compatiblity with 4.3
Boris Feld <boris.feld@octobus.net>
parents: 3921
diff changeset
   126
                    sset = compat._succs()
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   127
                    sset.markers.add(mark)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   128
                    fullsuccessorsets.append(sset)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   129
            if not foundany:
3932
35b2d201eb71 compat: fix obslog compatiblity with 4.3
Boris Feld <boris.feld@octobus.net>
parents: 3921
diff changeset
   130
                fullsuccessorsets.append(compat._succs())
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   131
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   132
    values = []
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   133
    for sset in fullsuccessorsets:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   134
        values.append({'successors': sset, 'markers': sset.markers})
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   135
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   136
    return values
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   137
3483
f03845bfd015 compat: add wrapper for logcmdutil functions
Yuya Nishihara <yuya@tcha.org>
parents: 3407
diff changeset
   138
class obsmarker_printer(compat.changesetprinter):
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   139
    """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
   140
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   141
    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
   142
    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
   143
3921
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   144
    def __init__(self, ui, repo, *args, **kwargs):
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   145
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   146
        if kwargs.pop('obspatch', False):
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   147
            if compat.changesetdiffer is None:
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   148
                kwargs['matchfn'] = scmutil.matchall(repo)
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   149
            else:
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   150
                kwargs['differ'] = scmutil.matchall(repo)
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   151
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   152
        super(obsmarker_printer, self).__init__(ui, repo, *args, **kwargs)
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   153
        diffopts = kwargs.get('diffopts', {})
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   154
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   155
        # Compat 4.6
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   156
        if not util.safehasattr(self, "_includediff"):
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   157
            self._includediff = diffopts and diffopts.get('patch')
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   158
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   159
        self.template = diffopts and diffopts.get('template')
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   160
        self.filter = diffopts and diffopts.get('filternonlocal')
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   161
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   162
    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
   163
        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
   164
            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
   165
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   166
            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
   167
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   168
            _props = {"template": self.template}
2956
bc9bc1778463 obslog: fix `--template` with `--graph` option
Alain Leufroy
parents: 2955
diff changeset
   169
            fm = self.ui.formatter('debugobshistory', _props)
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   170
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   171
            _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
   172
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   173
            markerfm = fm.nested("markers")
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   174
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   175
            # Succs markers
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   176
            if self.filter is False:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   177
                succs = self.repo.obsstore.successors.get(changenode, ())
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   178
                succs = sorted(succs)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   179
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   180
                for successor in succs:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   181
                    _debugobshistorydisplaymarker(markerfm, successor,
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   182
                                                  ctx.node(), self.repo,
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   183
                                                  self._includediff)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   184
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   185
            else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   186
                r = _successorsandmarkers(self.repo, ctx)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   187
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   188
                for succset in sorted(r):
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   189
                    markers = succset["markers"]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   190
                    if not markers:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   191
                        continue
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   192
                    successors = succset["successors"]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   193
                    _debugobshistorydisplaysuccsandmarkers(markerfm, successors, markers, ctx.node(), self.repo, self._includediff)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   194
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   195
            markerfm.end()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   196
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   197
            markerfm.plain('\n')
2955
b899a94472fd obslog: uniformize `_debugobshistoryrevs` and `_debugobshistorygraph` arguments
Alain Leufroy
parents: 2954
diff changeset
   198
            fm.end()
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   199
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   200
            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
   201
        else:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   202
            ### 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
   203
            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
   204
            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
   205
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   206
    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
   207
        ''' 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
   208
        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
   209
        '''
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   210
        pass
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   211
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   212
def patchavailable(node, repo, successors):
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   213
    if node not in repo:
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   214
        return False, "context is not local"
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   215
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   216
    if len(successors) == 0:
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   217
        return False, "no successors"
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   218
    elif len(successors) > 1:
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   219
        return False, "too many successors (%d)" % len(successors)
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   220
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   221
    succ = successors[0]
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   222
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   223
    if succ not in repo:
3054
bc890c6c9b2f obslog: spell out successor completely
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2957
diff changeset
   224
        return False, "successor is unknown locally"
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   225
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   226
    # Check that both node and succ have the same parents
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   227
    nodep1, nodep2 = repo[node].p1(), repo[node].p2()
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   228
    succp1, succp2 = repo[succ].p1(), repo[succ].p2()
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   229
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   230
    if nodep1 != succp1 or nodep2 != succp2:
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   231
        return False, "changesets rebased"
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   232
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   233
    return True, succ
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   234
3402
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   235
def getmarkerdescriptionpatch(repo, basedesc, succdesc):
2640
e278271d2391 obslog: add a comment about the final new line of descriptions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2639
diff changeset
   236
    # description are stored without final new line,
e278271d2391 obslog: add a comment about the final new line of descriptions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2639
diff changeset
   237
    # add one to avoid ugly diff
3402
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   238
    basedesc += '\n'
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   239
    succdesc += '\n'
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   240
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   241
    # fake file name
3400
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   242
    basename = "changeset-description"
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   243
    succname = "changeset-description"
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   244
3499
512706514555 obsfate: fix changeset description diff computing
Boris Feld <boris.feld@octobus.net>
parents: 3484
diff changeset
   245
    d = compat.strdiff(basedesc, succdesc, basename, succname)
3604
d24ba168a532 obslog: cleanup patch handling after 4.1 compat drop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3519
diff changeset
   246
    uheaders, hunks = d
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   247
3604
d24ba168a532 obslog: cleanup patch handling after 4.1 compat drop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3519
diff changeset
   248
    # Copied from patch.diff
d24ba168a532 obslog: cleanup patch handling after 4.1 compat drop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3519
diff changeset
   249
    text = ''.join(sum((list(hlines) for hrange, hlines in hunks), []))
d24ba168a532 obslog: cleanup patch handling after 4.1 compat drop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3519
diff changeset
   250
    patch = "\n".join(uheaders + [text])
3400
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   251
3399
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   252
    return patch
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   253
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   254
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
   255
    ''' 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
   256
    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
   257
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   258
    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
   259
        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
   260
        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
   261
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   262
    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
   263
        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
   264
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   265
    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
   266
        # 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
   267
        return True
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   268
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   269
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
   270
    """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
   271
    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
   272
    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
   273
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   274
    >>> 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
   275
    True
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   276
    >>> 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
   277
    False
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   278
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   279
    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
   280
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   281
    """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   282
    visited = set()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   283
    o = object()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   284
    path = [o]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   285
    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
   286
    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
   287
    while stack:
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   288
        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
   289
            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
   290
                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
   291
                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
   292
            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
   293
                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
   294
                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
   295
                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
   296
                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
   297
                break
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   298
        else:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   299
            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
   300
            stack.pop()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   301
    return False
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   302
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   303
def _obshistorywalker(repo, revs, walksuccessors=False, filternonlocal=False):
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   304
    """ 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
   305
    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
   306
    (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
   307
    """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   308
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   309
    # 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
   310
    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
   311
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   312
    # 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
   313
    shown = set()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   314
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   315
    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
   316
        """ 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
   317
        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
   318
        """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   319
        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
   320
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   321
    # 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
   322
    while candidates:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   323
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   324
        # 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
   325
        # already shown
4741
e8727a27e380 py3: filter() now returns a generator, so wrap when we need a list
Martin von Zweigbergk <martinvonz@google.com>
parents: 4738
diff changeset
   326
        validcandidates = list(filter(isvalidcandidate, candidates))
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   327
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   328
        # If we likely have a cycle
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   329
        if not validcandidates:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   330
            cycle = cyclic(nodesucc)
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   331
            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
   332
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   333
            # Then choose a random node from the cycle
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   334
            breaknode = sorted(cycle)[0]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   335
            # And display it by force
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   336
            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
   337
                          % nodemod.short(breaknode))
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   338
            validcandidates = [breaknode]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   339
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   340
        # 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
   341
        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
   342
            # 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
   343
            candidates.remove(cand)
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   344
            # 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
   345
            try:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   346
                del nodesucc[cand]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   347
            except KeyError:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   348
                pass
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   349
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   350
            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
   351
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   352
            # 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
   353
            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
   354
                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
   355
            else:
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   356
                if filternonlocal is False:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   357
                    changectx = missingchangectx(repo, cand)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   358
                else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   359
                    continue
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   360
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   361
            if filternonlocal is False:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   362
                relations = nodeprec.get(cand, ())
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   363
            else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   364
                relations = obsutil.closestpredecessors(repo, cand)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   365
            # print("RELATIONS", relations, list(closestpred))
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   366
            childrens = [(graphmod.PARENT, x) for x in relations]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   367
            # print("YIELD", changectx, childrens)
3728
0fc78fdca4b8 obshistory: use a more appropriate type for obslog entries
Anton Shestakov <av6@dwimlabs.net>
parents: 3701
diff changeset
   368
            yield (cand, graphmod.CHANGESET, changectx, childrens)
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   369
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
   370
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
   371
    """ 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
   372
    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
   373
    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
   374
    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
   375
    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
   376
    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
   377
    - 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
   378
    - 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
   379
    - 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
   380
    """
2840
dfad30be866c context: precursors was deprecated
Boris Feld <boris.feld@octobus.net>
parents: 2832
diff changeset
   381
    precursors = repo.obsstore.predecessors
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
   382
    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
   383
    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
   384
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   385
    # 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
   386
    nodesucc = dict()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   387
    # Childrens
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   388
    nodeprec = dict()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   389
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   390
    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
   391
    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
   392
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   393
    # 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
   394
    while nodes:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   395
        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
   396
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   397
        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
   398
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   399
        nodeprec[node] = []
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   400
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   401
        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
   402
            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
   403
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   404
            # 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
   405
            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
   406
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   407
            # 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
   408
            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
   409
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   410
            # 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
   411
            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
   412
                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
   413
                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
   414
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
   415
        # 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
   416
        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
   417
            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
   418
                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
   419
                    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
   420
                        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
   421
                        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
   422
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   423
    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
   424
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   425
def _debugobshistorygraph(ui, repo, revs, opts):
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   426
4752
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
   427
    displayer = obsmarker_printer(ui, repo.unfiltered(), obspatch=True,
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
   428
                                  diffopts=pycompat.byteskwargs(opts),
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
   429
                                  buffered=True)
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   430
    edges = graphmod.asciiedges
4752
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
   431
    walker = _obshistorywalker(repo.unfiltered(), revs, opts.get('all', False),
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
   432
                               opts.get('filternonlocal', False))
3483
f03845bfd015 compat: add wrapper for logcmdutil functions
Yuya Nishihara <yuya@tcha.org>
parents: 3407
diff changeset
   433
    compat.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
   434
2955
b899a94472fd obslog: uniformize `_debugobshistoryrevs` and `_debugobshistorygraph` arguments
Alain Leufroy
parents: 2954
diff changeset
   435
def _debugobshistoryrevs(ui, repo, revs, opts):
2633
59e85fbb31b6 obslog: small renaming of _debugobshistorysingle
Boris Feld <boris.feld@octobus.net>
parents: 2610
diff changeset
   436
    """ Display the obsolescence history for revset
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   437
    """
4752
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
   438
    fm = ui.formatter('debugobshistory', pycompat.byteskwargs(opts))
2840
dfad30be866c context: precursors was deprecated
Boris Feld <boris.feld@octobus.net>
parents: 2832
diff changeset
   439
    precursors = repo.obsstore.predecessors
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   440
    successors = repo.obsstore.successors
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   441
    nodec = repo.changelog.node
2635
9ab35c37b85a obslog: pass directly unfiltered_repo
Boris Feld <boris.feld@octobus.net>
parents: 2634
diff changeset
   442
    unfi = repo.unfiltered()
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   443
    nodes = [nodec(r) for r in revs]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   444
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   445
    seen = set(nodes)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   446
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   447
    while nodes:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   448
        ctxnode = nodes.pop()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   449
2635
9ab35c37b85a obslog: pass directly unfiltered_repo
Boris Feld <boris.feld@octobus.net>
parents: 2634
diff changeset
   450
        _debugobshistorydisplaynode(fm, unfi, ctxnode)
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   451
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   452
        succs = successors.get(ctxnode, ())
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   453
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   454
        markerfm = fm.nested("markers")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   455
        for successor in sorted(succs):
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   456
            includediff = opts and opts.get("patch")
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   457
            _debugobshistorydisplaymarker(markerfm, successor, ctxnode, unfi, includediff)
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   458
        markerfm.end()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   459
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   460
        precs = precursors.get(ctxnode, ())
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   461
        for p in sorted(precs):
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   462
            # Only show nodes once
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   463
            if p[0] not in seen:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   464
                seen.add(p[0])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   465
                nodes.append(p[0])
2955
b899a94472fd obslog: uniformize `_debugobshistoryrevs` and `_debugobshistorygraph` arguments
Alain Leufroy
parents: 2954
diff changeset
   466
    fm.end()
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   467
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   468
def _debugobshistorydisplaynode(fm, repo, node):
2635
9ab35c37b85a obslog: pass directly unfiltered_repo
Boris Feld <boris.feld@octobus.net>
parents: 2634
diff changeset
   469
    if node in repo:
9ab35c37b85a obslog: pass directly unfiltered_repo
Boris Feld <boris.feld@octobus.net>
parents: 2634
diff changeset
   470
        _debugobshistorydisplayctx(fm, repo[node])
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   471
    else:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   472
        _debugobshistorydisplaymissingctx(fm, node)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   473
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   474
def _debugobshistorydisplayctx(fm, ctx):
3729
1b1badb3d2fc obshistory: make obslog work when a commit doesn't have any description
Anton Shestakov <av6@dwimlabs.net>
parents: 3728
diff changeset
   475
    shortdescription = ctx.description().strip()
1b1badb3d2fc obshistory: make obslog work when a commit doesn't have any description
Anton Shestakov <av6@dwimlabs.net>
parents: 3728
diff changeset
   476
    if shortdescription:
1b1badb3d2fc obshistory: make obslog work when a commit doesn't have any description
Anton Shestakov <av6@dwimlabs.net>
parents: 3728
diff changeset
   477
        shortdescription = shortdescription.splitlines()[0]
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   478
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   479
    fm.startitem()
4747
fa6aafa2857d py3: replace str(ctx) by bytes(ctx)
Martin von Zweigbergk <martinvonz@google.com>
parents: 4741
diff changeset
   480
    fm.write('node', '%s', bytes(ctx),
2404
c07f752137f4 label: rename 'evolve.short_node' to 'evolve.node'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2403
diff changeset
   481
             label="evolve.node")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   482
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   483
3506
6b4272bbb65d evolve: update code for not implicitly converting ctx to revision
Boris Feld <boris.feld@octobus.net>
parents: 3499
diff changeset
   484
    fm.write('rev', '(%d)', ctx.rev(),
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   485
             label="evolve.rev")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   486
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   487
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   488
    fm.write('shortdescription', '%s', shortdescription,
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   489
             label="evolve.short_description")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   490
    fm.plain('\n')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   491
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   492
def _debugobshistorydisplaymissingctx(fm, nodewithoutctx):
2406
31255706b591 obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2404
diff changeset
   493
    hexnode = nodemod.short(nodewithoutctx)
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   494
    fm.startitem()
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   495
    fm.write('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
   496
             label="evolve.node evolve.missing_change_ctx")
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   497
    fm.plain('\n')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   498
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   499
def _debugobshistorydisplaymarker(fm, marker, node, repo, includediff=False):
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   500
    succnodes = marker[1]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   501
    date = marker[4]
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   502
    metadata = dict(marker[3])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   503
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   504
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   505
    fm.plain('  ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   506
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   507
    # Detect pruned revisions
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   508
    if len(succnodes) == 0:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   509
        verb = 'pruned'
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   510
    else:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   511
        verb = 'rewritten'
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   512
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   513
    fm.write('verb', '%s', verb,
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   514
             label="evolve.verb")
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   515
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   516
    effectflag = metadata.get('ef1')
2455
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   517
    if effectflag is not None:
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   518
        try:
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   519
            effectflag = int(effectflag)
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   520
        except ValueError:
d93a50a9abf5 effectflag: handle invalid data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2454
diff changeset
   521
            effectflag = None
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   522
    if effectflag:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   523
        effect = []
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   524
2456
63be7982d593 effectflag: add a small comment to suggest improvement
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2455
diff changeset
   525
        # 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
   526
        if effectflag & DESCCHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   527
            effect.append('description')
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   528
        if effectflag & METACHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   529
            effect.append('meta')
2492
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   530
        if effectflag & USERCHANGED:
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   531
            effect.append('user')
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   532
        if effectflag & DATECHANGED:
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   533
            effect.append('date')
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   534
        if effectflag & BRANCHCHANGED:
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   535
            effect.append('branch')
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   536
        if effectflag & PARENTCHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   537
            effect.append('parent')
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   538
        if effectflag & DIFFCHANGED:
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   539
            effect.append('content')
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   540
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   541
        if effect:
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   542
            fmteffect = fm.formatlist(effect, 'effect', sep=', ')
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   543
            fm.write('effect', '(%s)', fmteffect)
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   544
2832
07b9fcf8b6d3 output: update obsfate / obslog output order
Boris Feld <boris.feld@octobus.net>
parents: 2697
diff changeset
   545
    if len(succnodes) > 0:
07b9fcf8b6d3 output: update obsfate / obslog output order
Boris Feld <boris.feld@octobus.net>
parents: 2697
diff changeset
   546
        fm.plain(' as ')
07b9fcf8b6d3 output: update obsfate / obslog output order
Boris Feld <boris.feld@octobus.net>
parents: 2697
diff changeset
   547
07b9fcf8b6d3 output: update obsfate / obslog output order
Boris Feld <boris.feld@octobus.net>
parents: 2697
diff changeset
   548
        shortsnodes = (nodemod.short(succnode) for succnode in sorted(succnodes))
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   549
        nodes = fm.formatlist(shortsnodes, 'succnodes', sep=', ')
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   550
        fm.write('succnodes', '%s', nodes,
2832
07b9fcf8b6d3 output: update obsfate / obslog output order
Boris Feld <boris.feld@octobus.net>
parents: 2697
diff changeset
   551
                 label="evolve.node")
07b9fcf8b6d3 output: update obsfate / obslog output order
Boris Feld <boris.feld@octobus.net>
parents: 2697
diff changeset
   552
3519
2823c82ad8a4 obslog: add the operation to the Obslog output
Boris Feld <boris.feld@octobus.net>
parents: 3506
diff changeset
   553
    operation = metadata.get('operation')
2823c82ad8a4 obslog: add the operation to the Obslog output
Boris Feld <boris.feld@octobus.net>
parents: 3506
diff changeset
   554
    if operation:
2823c82ad8a4 obslog: add the operation to the Obslog output
Boris Feld <boris.feld@octobus.net>
parents: 3506
diff changeset
   555
        fm.plain(' using ')
2823c82ad8a4 obslog: add the operation to the Obslog output
Boris Feld <boris.feld@octobus.net>
parents: 3506
diff changeset
   556
        fm.write('operation', '%s', operation, label="evolve.operation")
2823c82ad8a4 obslog: add the operation to the Obslog output
Boris Feld <boris.feld@octobus.net>
parents: 3506
diff changeset
   557
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   558
    fm.plain(' by ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   559
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   560
    fm.write('user', '%s', metadata['user'],
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   561
             label="evolve.user")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   562
    fm.plain(' ')
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   563
2957
586c9ace20b3 obslog: simplify formatter keys
Alain Leufroy
parents: 2956
diff changeset
   564
    fm.write('date', '(%s)', fm.formatdate(date),
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   565
             label="evolve.date")
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   566
3214
9fe2b3fd7fc7 obslog: add initial support for showing note in obslog
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3181
diff changeset
   567
    # initial support for showing note
9fe2b3fd7fc7 obslog: add initial support for showing note in obslog
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3181
diff changeset
   568
    if metadata.get('note'):
9fe2b3fd7fc7 obslog: add initial support for showing note in obslog
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3181
diff changeset
   569
        fm.plain('\n    note: ')
3223
73b4e84df0bd obsnote: don't add '' to note while showing it in obslog
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3214
diff changeset
   570
        fm.write('note', "%s", metadata['note'], label="evolve.note")
3214
9fe2b3fd7fc7 obslog: add initial support for showing note in obslog
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3181
diff changeset
   571
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   572
    # Patch display
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   573
    if includediff is True:
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   574
        _patchavailable = patchavailable(node, repo, marker[1])
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   575
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   576
        if _patchavailable[0] is True:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   577
            succ = _patchavailable[1]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   578
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   579
            basectx = repo[node]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   580
            succctx = repo[succ]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   581
            # Description patch
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   582
            descriptionpatch = getmarkerdescriptionpatch(repo,
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   583
                                                         basectx.description(),
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   584
                                                         succctx.description())
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   585
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   586
            if descriptionpatch:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   587
                # add the diffheader
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   588
                diffheader = "diff -r %s -r %s changeset-description\n" % \
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   589
                             (basectx, succctx)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   590
                descriptionpatch = diffheader + descriptionpatch
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   591
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   592
                def tolist(text):
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   593
                    return [text]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   594
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   595
                fm.plain("\n")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   596
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   597
                for chunk, label in patch.difflabel(tolist, descriptionpatch):
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   598
                    chunk = chunk.strip('\t')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   599
                    if chunk and chunk != '\n':
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   600
                        fm.plain('    ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   601
                    fm.write('desc-diff', '%s', chunk, label=label)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   602
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   603
            # Content patch
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   604
            diffopts = patch.diffallopts(repo.ui, {})
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   605
            matchfn = scmutil.matchall(repo)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   606
            firstline = True
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   607
            for chunk, label in patch.diffui(repo, node, succ, matchfn,
4399
3722557b008c obshistory: omit keyword arguments with default values in patch.diffui() calls
Anton Shestakov <av6@dwimlabs.net>
parents: 4260
diff changeset
   608
                                             opts=diffopts):
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   609
                if firstline:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   610
                    fm.plain('\n')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   611
                    firstline = False
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   612
                if chunk and chunk != '\n':
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   613
                    fm.plain('    ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   614
                fm.write('patch', '%s', chunk, label=label)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   615
        else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   616
            nopatch = "    (No patch available, %s)" % _patchavailable[1]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   617
            fm.plain("\n")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   618
            # TODO: should be in json too
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   619
            fm.plain(nopatch)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   620
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   621
    fm.plain("\n")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   622
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   623
def _debugobshistorydisplaysuccsandmarkers(fm, succnodes, markers, node, repo, includediff=False):
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   624
    """
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   625
    This function is a duplication of _debugobshistorydisplaymarker modified
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   626
    to accept multiple markers as input.
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   627
    """
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   628
    fm.startitem()
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   629
    fm.plain('  ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   630
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   631
    # Detect pruned revisions
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   632
    verb = _successorsetverb(succnodes, markers)["verb"]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   633
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   634
    fm.write('verb', '%s', verb,
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   635
             label="evolve.verb")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   636
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   637
    # Effect flag
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   638
    metadata = [dict(marker[3]) for marker in markers]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   639
    ef1 = [data.get('ef1') for data in metadata]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   640
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   641
    effectflag = 0
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   642
    for ef in ef1:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   643
        if ef:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   644
            effectflag |= int(ef)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   645
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   646
    if effectflag:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   647
        effect = []
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   648
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   649
        # XXX should be a dict
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   650
        if effectflag & DESCCHANGED:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   651
            effect.append('description')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   652
        if effectflag & METACHANGED:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   653
            effect.append('meta')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   654
        if effectflag & USERCHANGED:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   655
            effect.append('user')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   656
        if effectflag & DATECHANGED:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   657
            effect.append('date')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   658
        if effectflag & BRANCHCHANGED:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   659
            effect.append('branch')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   660
        if effectflag & PARENTCHANGED:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   661
            effect.append('parent')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   662
        if effectflag & DIFFCHANGED:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   663
            effect.append('content')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   664
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   665
        if effect:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   666
            fmteffect = fm.formatlist(effect, 'effect', sep=', ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   667
            fm.write('effect', '(%s)', fmteffect)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   668
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   669
    if len(succnodes) > 0:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   670
        fm.plain(' as ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   671
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   672
        shortsnodes = (nodemod.short(succnode) for succnode in sorted(succnodes))
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   673
        nodes = fm.formatlist(shortsnodes, 'succnodes', sep=', ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   674
        fm.write('succnodes', '%s', nodes,
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   675
                 label="evolve.node")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   676
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   677
    # Operations
3932
35b2d201eb71 compat: fix obslog compatiblity with 4.3
Boris Feld <boris.feld@octobus.net>
parents: 3921
diff changeset
   678
    operations = compat.markersoperations(markers)
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   679
    if operations:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   680
        fm.plain(' using ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   681
        fm.write('operation', '%s', ", ".join(operations), label="evolve.operation")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   682
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   683
    fm.plain(' by ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   684
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   685
    # Users
3932
35b2d201eb71 compat: fix obslog compatiblity with 4.3
Boris Feld <boris.feld@octobus.net>
parents: 3921
diff changeset
   686
    users = compat.markersusers(markers)
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   687
    fm.write('user', '%s', ", ".join(users),
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   688
             label="evolve.user")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   689
    fm.plain(' ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   690
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   691
    # Dates
3932
35b2d201eb71 compat: fix obslog compatiblity with 4.3
Boris Feld <boris.feld@octobus.net>
parents: 3921
diff changeset
   692
    dates = compat.markersdates(markers)
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   693
    if dates:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   694
        min_date = min(dates)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   695
        max_date = max(dates)
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   696
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   697
        if min_date == max_date:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   698
            fm.write("date", "(at %s)", fm.formatdate(min_date), label="evolve.date")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   699
        else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   700
            fm.write("date", "(between %s and %s)", fm.formatdate(min_date),
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   701
                     fm.formatdate(max_date), label="evolve.date")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   702
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   703
    # initial support for showing note
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   704
    # if metadata.get('note'):
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   705
    #     fm.plain('\n    note: ')
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   706
    #     fm.write('note', "%s", metadata['note'], label="evolve.note")
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   707
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   708
    # Patch display
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   709
    if includediff is True:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   710
        _patchavailable = patchavailable(node, repo, succnodes)
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   711
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   712
        if _patchavailable[0] is True:
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   713
            succ = _patchavailable[1]
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   714
3402
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   715
            basectx = repo[node]
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   716
            succctx = repo[succ]
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   717
            # Description patch
3402
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   718
            descriptionpatch = getmarkerdescriptionpatch(repo,
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   719
                                                         basectx.description(),
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   720
                                                         succctx.description())
3399
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   721
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   722
            if descriptionpatch:
3400
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   723
                # add the diffheader
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   724
                diffheader = "diff -r %s -r %s changeset-description\n" % \
3402
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   725
                             (basectx, succctx)
3400
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   726
                descriptionpatch = diffheader + descriptionpatch
3399
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   727
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   728
                def tolist(text):
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   729
                    return [text]
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   730
3400
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   731
                fm.plain("\n")
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   732
3399
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   733
                for chunk, label in patch.difflabel(tolist, descriptionpatch):
3400
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   734
                    chunk = chunk.strip('\t')
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   735
                    if chunk and chunk != '\n':
3399
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   736
                        fm.plain('    ')
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   737
                    fm.write('desc-diff', '%s', chunk, label=label)
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   738
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   739
            # Content patch
3398
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   740
            diffopts = patch.diffallopts(repo.ui, {})
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   741
            matchfn = scmutil.matchall(repo)
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   742
            firstline = True
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   743
            for chunk, label in patch.diffui(repo, node, succ, matchfn,
4399
3722557b008c obshistory: omit keyword arguments with default values in patch.diffui() calls
Anton Shestakov <av6@dwimlabs.net>
parents: 4260
diff changeset
   744
                                             opts=diffopts):
3398
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   745
                if firstline:
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   746
                    fm.plain('\n')
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   747
                    firstline = False
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   748
                if chunk and chunk != '\n':
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   749
                    fm.plain('    ')
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   750
                fm.write('patch', '%s', chunk, label=label)
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   751
        else:
3398
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   752
            nopatch = "    (No patch available, %s)" % _patchavailable[1]
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   753
            fm.plain("\n")
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   754
            # TODO: should be in json too
3398
d67e6080e11b obslog: colorize the patch shown using `hg obslog -p`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3223
diff changeset
   755
            fm.plain(nopatch)
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   756
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   757
    fm.plain("\n")
2446
4b2f4da124a2 effectflag: allow to save effect of change in obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 2441
diff changeset
   758
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
   759
# 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
   760
DESCCHANGED = 1 << 0 # action changed the description
2522
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   761
METACHANGED = 1 << 1 # action change the meta
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
   762
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
   763
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
   764
USERCHANGED = 1 << 4 # the user changed
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   765
DATECHANGED = 1 << 5 # the date changed
c9f1118b33d6 effectflag: split effect flag meta
Boris Feld <boris.feld@octobus.net>
parents: 2490
diff changeset
   766
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
   767
2522
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   768
METABLACKLIST = [
4801
16c1398b0063 python3: prefix all regex to work with python 2 and 3
Raphaël Gomès <rgomes@octobus.net>
parents: 4752
diff changeset
   769
    re.compile(br'^__touch-noise__$'),
16c1398b0063 python3: prefix all regex to work with python 2 and 3
Raphaël Gomès <rgomes@octobus.net>
parents: 4752
diff changeset
   770
    re.compile(br'^branch$'),
16c1398b0063 python3: prefix all regex to work with python 2 and 3
Raphaël Gomès <rgomes@octobus.net>
parents: 4752
diff changeset
   771
    re.compile(br'^.*-source$'),
16c1398b0063 python3: prefix all regex to work with python 2 and 3
Raphaël Gomès <rgomes@octobus.net>
parents: 4752
diff changeset
   772
    re.compile(br'^.*_source$'),
16c1398b0063 python3: prefix all regex to work with python 2 and 3
Raphaël Gomès <rgomes@octobus.net>
parents: 4752
diff changeset
   773
    re.compile(br'^source$'),
2522
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   774
]
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   775
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   776
def ismetablacklisted(metaitem):
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   777
    """ Check that the key of a meta item (extrakey, extravalue) does not
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   778
    match at least one of the blacklist pattern
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   779
    """
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   780
    metakey = metaitem[0]
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   781
    for pattern in METABLACKLIST:
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   782
        if pattern.match(metakey):
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   783
            return False
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   784
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   785
    return True
a1cc2a0b9f6f effetflag: detect other meta (extra) changes
Boris Feld <boris.feld@octobus.net>
parents: 2520
diff changeset
   786
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   787
def _prepare_hunk(hunk):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   788
    """Drop all information but the username and patch"""
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   789
    cleanunk = []
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   790
    for line in hunk.splitlines():
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   791
        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
   792
            if line.startswith(b'@@'):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   793
                line = b'@@\n'
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   794
            cleanunk.append(line)
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   795
    return cleanunk
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   796
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   797
def _getdifflines(iterdiff):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   798
    """return a cleaned up lines"""
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   799
    try:
4738
45508676ed00 py3: replace iter.next() by next(iter)
Martin von Zweigbergk <martinvonz@google.com>
parents: 4715
diff changeset
   800
        lines = next(iterdiff)
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   801
    except StopIteration:
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   802
        return None
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   803
    return _prepare_hunk(lines)
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   804
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   805
def _getobsfate(successorssets):
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   806
    """ 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
   807
    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
   808
    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
   809
    - pruned
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   810
    - diverged
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   811
    - superseed
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   812
    - superseed_split
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   813
    """
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   814
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   815
    if len(successorssets) == 0:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   816
        # The commit has been pruned
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   817
        return 'pruned'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   818
    elif len(successorssets) > 1:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   819
        return 'diverged'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   820
    else:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   821
        # 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
   822
        successors = successorssets[0]
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   823
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   824
        if len(successors) == 1:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   825
            return 'superseed'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   826
        else:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   827
            return 'superseed_split'
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   828
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   829
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
   830
    """ Return a tuple containing:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   831
    - 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
   832
    - 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
   833
    or has diverged
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   834
    """
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   835
    if successorssets is None:
3697
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3607
diff changeset
   836
        successorssets = obsutil.successorssets(repo, revnode)
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   837
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   838
    fate = _getobsfate(successorssets)
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   839
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   840
    # 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
   841
    if len(successorssets) == 1:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   842
        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
   843
    else:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   844
        successors = []
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   845
        for succset in successorssets:
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   846
            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
   847
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   848
    return (fate, successors)
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   849
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   850
def _successorsetdates(successorset, markers):
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   851
    """returns the max date and the min date of the markers list
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   852
    """
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   853
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   854
    if not markers:
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   855
        return {}
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   856
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   857
    dates = [m[4] for m in markers]
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   858
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   859
    return {
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   860
        'min_date': min(dates),
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   861
        'max_date': max(dates)
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   862
    }
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   863
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   864
def _successorsetusers(successorset, markers):
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   865
    """ Returns a sorted list of markers users without duplicates
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   866
    """
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   867
    if not markers:
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   868
        return {}
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   869
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   870
    # Check that user is present in meta
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   871
    markersmeta = [dict(m[3]) for m in markers]
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   872
    users = set(meta.get('user') for meta in markersmeta if meta.get('user'))
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   873
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   874
    return {'users': sorted(users)}
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   875
2896
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   876
VERBMAPPING = {
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   877
    DESCCHANGED: "reworded",
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   878
    METACHANGED: "meta-changed",
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   879
    USERCHANGED: "reauthored",
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   880
    DATECHANGED: "date-changed",
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   881
    BRANCHCHANGED: "branch-changed",
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   882
    PARENTCHANGED: "rebased",
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   883
    DIFFCHANGED: "amended"
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   884
}
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   885
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   886
def _successorsetverb(successorset, markers):
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   887
    """ Return the verb summarizing the successorset
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   888
    """
2896
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   889
    verb = None
2606
02129bed002c obsfate: improve prune support in _successorsetverb
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2604
diff changeset
   890
    if not successorset:
02129bed002c obsfate: improve prune support in _successorsetverb
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2604
diff changeset
   891
        verb = 'pruned'
2607
054d92586e43 obsfate: use 'split' as verb when appropriate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2606
diff changeset
   892
    elif len(successorset) == 1:
2896
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   893
        # Check for effect flag
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   894
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   895
        metadata = [dict(marker[3]) for marker in markers]
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   896
        ef1 = [data.get('ef1') for data in metadata]
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   897
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   898
        if all(ef1):
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   899
            combined = 0
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   900
            for ef in ef1:
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   901
                combined |= int(ef)
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   902
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   903
            # Combined will be in VERBMAPPING only of one bit is set
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   904
            if combined in VERBMAPPING:
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   905
                verb = VERBMAPPING[combined]
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   906
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   907
        if verb is None:
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   908
            verb = 'rewritten'
2606
02129bed002c obsfate: improve prune support in _successorsetverb
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2604
diff changeset
   909
    else:
2607
054d92586e43 obsfate: use 'split' as verb when appropriate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2606
diff changeset
   910
        verb = 'split'
2606
02129bed002c obsfate: improve prune support in _successorsetverb
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2604
diff changeset
   911
    return {'verb': verb}
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   912
3181
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   913
# Use a more advanced version of obsfateverb that uses effect-flag
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   914
if util.safehasattr(obsutil, 'obsfateverb'):
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   915
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   916
    @eh.wrapfunction(obsutil, 'obsfateverb')
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   917
    def obsfateverb(orig, *args, **kwargs):
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   918
        return _successorsetverb(*args, **kwargs)['verb']
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   919
3083
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   920
# Hijack callers of successorsetverb
3181
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   921
elif util.safehasattr(obsutil, 'obsfateprinter'):
3083
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   922
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   923
    @eh.wrapfunction(obsutil, 'obsfateprinter')
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   924
    def obsfateprinter(orig, successors, markers, ui):
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   925
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   926
        def closure(successors):
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   927
            return _successorsetverb(successors, markers)['verb']
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   928
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   929
        if not util.safehasattr(obsutil, 'successorsetverb'):
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   930
            return orig(successors, markers, ui)
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   931
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   932
        # Save the old value
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   933
        old = obsutil.successorsetverb
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   934
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   935
        try:
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   936
            # Replace by own
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   937
            obsutil.successorsetverb = closure
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   938
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   939
            # Call the orig
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   940
            result = orig(successors, markers, ui)
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   941
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   942
            # And return result
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   943
            return result
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   944
        finally:
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   945
            # Replace the old one
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   946
            obsutil.successorsetverb = old
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
   947
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   948
FORMATSSETSFUNCTIONS = [
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   949
    _successorsetdates,
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   950
    _successorsetusers,
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   951
    _successorsetverb
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   952
]
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   953
2609
81a94da65dca obsfate: mark successorsetallmarkers public
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2608
diff changeset
   954
def successorsetallmarkers(successorset, pathscache):
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   955
    """compute all successors of a successorset.
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   956
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   957
    pathscache must contains all successors starting from selected nodes
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   958
    or revision. This way, iterating on each successor, we can take all
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   959
    precursors and have the subgraph of all obsmarkers between roots to
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   960
    successors.
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   961
    """
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   962
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   963
    markers = set()
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   964
    seen = set()
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   965
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   966
    for successor in successorset:
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   967
        stack = [successor]
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   968
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   969
        while stack:
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   970
            element = stack.pop()
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   971
            seen.add(element)
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   972
            for prec, mark in pathscache.get(element, []):
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   973
                if prec not in seen:
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   974
                    # Process element precursors
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   975
                    stack.append(prec)
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   976
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   977
                if mark not in markers:
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   978
                    markers.add(mark)
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   979
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   980
    return markers
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   981
2610
ee37ab3de5f7 obsfate: split markers fetch from successor set annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2609
diff changeset
   982
def preparesuccessorset(successorset, rawmarkers):
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   983
    """ For a successor set, get all related markers, compute the set of user,
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   984
    the min date and the max date
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   985
    """
2604
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   986
    hex = nodemod.hex
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   987
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   988
    successorset = [hex(n) for n in successorset]
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   989
2604
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   990
    # hex the binary nodes in the markers
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   991
    markers = []
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   992
    for m in rawmarkers:
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   993
        hexprec = hex(m[0])
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   994
        hexsucs = tuple(hex(n) for n in m[1])
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   995
        hexparents = None
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   996
        if m[5] is not None:
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   997
            hexparents = tuple(hex(n) for n in m[5])
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   998
        newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:]
3bcc9d3bac33 template: use hex node in the obsmarkers used in the obsfate template
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2603
diff changeset
   999
        markers.append(newmarker)
2603
23f1c3b9052f template: use hex successors in obsfate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2592
diff changeset
  1000
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1001
    # Format basic data
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1002
    data = {
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1003
        "successors": sorted(successorset),
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1004
        "markers": sorted(markers)
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1005
    }
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1006
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1007
    # Call an extensible list of functions to override or add new data
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1008
    for function in FORMATSSETSFUNCTIONS:
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1009
        data.update(function(successorset, markers))
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1010
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
  1011
    return data