hgext3rd/evolve/obshistory.py
author Anton Shestakov <av6@dwimlabs.net>
Thu, 07 May 2020 01:29:24 +0200
changeset 5348 a9f9edb168a1
parent 5347 2d48fc2c47fc
child 5349 e8660b28bfee
permissions -rw-r--r--
obslog: add a --origin flag to show predecessors instead of successors This flag will be turned on by default in the next changeset.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     1
# Code dedicated to display and exploration of the obsolescence history
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     2
#
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     3
# This module content aims at being upstreamed enventually.
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     4
#
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     5
# Copyright 2017 Octobus SAS <contact@octobus.net>
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     6
#
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     7
# This software may be used and distributed according to the terms of the
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     8
# GNU General Public License version 2 or any later version.
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     9
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,
5181
c979d64a2589 compat: drop 4.5 compatibility layer for log utility
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5173
diff changeset
    16
    logcmdutil,
5182
df5e6e3884bc compat: drop 4.5 compatibility for strdiff
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5181
diff changeset
    17
    mdiff,
5181
c979d64a2589 compat: drop 4.5 compatibility layer for log utility
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5173
diff changeset
    18
    node as nodemod,
3883
ed460e7ee8aa compat: drop compatibility hack for mercurial <4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3838
diff changeset
    19
    obsutil,
5181
c979d64a2589 compat: drop 4.5 compatibility layer for log utility
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5173
diff changeset
    20
    patch,
4752
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
    21
    pycompat,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    22
    scmutil,
3083
e91ca8b5ecf7 obsfate: use core version of obsfate if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3080
diff changeset
    23
    util,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    24
)
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    25
5330
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
    26
from mercurial.utils import dateutil
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
    27
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    28
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
    29
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    30
from . import (
2693
f4b0351fa813 evolve: adapt to function migrate to obsutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2678
diff changeset
    31
    compat,
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    32
    exthelper,
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    33
)
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    34
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    35
eh = exthelper.exthelper()
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    36
3080
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    37
# Config
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
    38
efd = {b'default': True} # pass a default value unless the config is registered
3080
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    39
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    40
@eh.extsetup
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    41
def enableeffectflags(ui):
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    42
    item = (getattr(ui, '_knownconfig', {})
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
    43
            .get(b'experimental', {})
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
    44
            .get(b'evolution.effect-flags'))
3080
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    45
    if item is not None:
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    46
        item.default = True
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    47
        efd.clear()
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 3071
diff changeset
    48
5072
3c1a5754d983 obshistory: remove unused ismetablacklisted()
Anton Shestakov <av6@dwimlabs.net>
parents: 5071
diff changeset
    49
@eh.extsetup
3c1a5754d983 obshistory: remove unused ismetablacklisted()
Anton Shestakov <av6@dwimlabs.net>
parents: 5071
diff changeset
    50
def addtouchnoise(ui):
3c1a5754d983 obshistory: remove unused ismetablacklisted()
Anton Shestakov <av6@dwimlabs.net>
parents: 5071
diff changeset
    51
    obsutil.METABLACKLIST.append(re.compile(br'^__touch-noise__$'))
5345
a73cdef2e33f evolve: rename `evolve_source_*` to `divergence_source_*`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5344
diff changeset
    52
    obsutil.METABLACKLIST.append(re.compile(br'^divergence_source_local$'))
a73cdef2e33f evolve: rename `evolve_source_*` to `divergence_source_*`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5344
diff changeset
    53
    obsutil.METABLACKLIST.append(re.compile(br'^divergence_source_other$'))
5072
3c1a5754d983 obshistory: remove unused ismetablacklisted()
Anton Shestakov <av6@dwimlabs.net>
parents: 5071
diff changeset
    54
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    55
@eh.command(
4715
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    56
    b'obslog|olog',
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    57
    [(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
    58
     (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
    59
     (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
    60
     (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
    61
     (b'f', b'filternonlocal', False, _(b'filter out non local commits')),
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
    62
     (b'o', b'origin', False, _(b'show origin of changesets instead of fate')),
4715
12c8b24757f4 py3: use byte strings for @command registrations
Martin von Zweigbergk <martinvonz@google.com>
parents: 4430
diff changeset
    63
     ] + commands.formatteropts,
4921
a7c01a2a3974 branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4918 4915
diff changeset
    64
    _(b'hg olog [OPTION]... [[-r] REV]...'),
4894
f9743b13de6d help: categorizing evolve and topic commands
Rodrigo Damazio <rdamazio@google.com>
parents: 4827
diff changeset
    65
    **compat.helpcategorykwargs('CATEGORY_CHANGE_NAVIGATION'))
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    66
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
    67
    """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
    68
2418
4993d1812311 olog: document the default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2416
diff changeset
    69
    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
    70
    working copy parent.
4993d1812311 olog: document the default value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2416
diff changeset
    71
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    72
    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
    73
    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
    74
    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
    75
    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
    76
    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
    77
    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
    78
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    79
    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
    80
    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
    81
    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
    82
2678
da2b3e5e4f69 docs: some fixes to the help text
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2640
diff changeset
    83
    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
    84
    '--no-graph'.
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    85
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    86
    '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
    87
    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
    88
    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
    89
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    90
    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
    91
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    92
    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
    93
    """
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
    94
    ui.pager(b'obslog')
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    95
    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
    96
    if not revs:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
    97
        revs = [b'.']
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
    98
    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
    99
5173
dbbb48d93f18 obslog: remove the separate "obslog -f" implementation and use the common one
Anton Shestakov <av6@dwimlabs.net>
parents: 5172
diff changeset
   100
    # Use the default template unless the user provided one.
dbbb48d93f18 obslog: remove the separate "obslog -f" implementation and use the common one
Anton Shestakov <av6@dwimlabs.net>
parents: 5172
diff changeset
   101
    if not opts['template']:
4949
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   102
        opts['template'] = DEFAULT_TEMPLATE
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   103
2415
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
   104
    if opts['graph']:
5301
35c15057e2e5 obshistory: rename graph/revs-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5300
diff changeset
   105
        return displaygraph(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
   106
89a5dabbb43d obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2411
diff changeset
   107
    revs.reverse()
5301
35c15057e2e5 obshistory: rename graph/revs-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5300
diff changeset
   108
    displayrevs(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
   109
4983
6d40e0166522 obslog: make {node} the full node and leave shortening to template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4953
diff changeset
   110
TEMPLATE_MISSING_NODE = b"""{label("evolve.node evolve.missing_change_ctx", node|short)}"""
6d40e0166522 obslog: make {node} the full node and leave shortening to template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4953
diff changeset
   111
TEMPLATE_PRESENT_NODE = b"""{label("evolve.node", node|short)} {label("evolve.rev", "({rev})")} {label("evolve.short_description", desc|firstline)}"""
4949
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   112
TEMPLATE_FIRST_LINE = b"""{if(rev, "%(presentnode)s", "%(missingnode)s")}""" % {
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   113
    b"presentnode": TEMPLATE_PRESENT_NODE,
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   114
    b"missingnode": TEMPLATE_MISSING_NODE
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   115
}
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   116
TEMPLATE_PREDNODES = b"""{label("evolve.node", join(prednodes % "{prednode|short}", ", "))}"""
4951
7bfd3fed5d1f obslog: make {succnodes} be full hex nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 4950
diff changeset
   117
TEMPLATE_SUCCNODES = b"""{label("evolve.node", join(succnodes % "{succnode|short}", ", "))}"""
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   118
TEMPLATE_NODES = b"""{if(prednodes, "from %(prednodes)s")}{if(succnodes, "as %(succnodes)s")}""" % {
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   119
    b"prednodes": TEMPLATE_PREDNODES,
4949
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   120
    b"succnodes": TEMPLATE_SUCCNODES
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   121
}
5307
66a913cc53af obshistory: restructure templates a bit, drop default verb ("pruned")
Anton Shestakov <av6@dwimlabs.net>
parents: 5306
diff changeset
   122
TEMPLATE_REWRITE = b"""{label("evolve.verb", verb)}{if(effects, "({join(effects, ", ")})")}"""
5169
897b371cd0c5 obslog: make operation template property into operations
Anton Shestakov <av6@dwimlabs.net>
parents: 5168
diff changeset
   123
TEMPLATE_OPERATIONS = b"""{if(operations, "using {label("evolve.operation", join(operations, ", "))}")}"""
5168
c7ca43bba6c5 obslog: make user template property into users
Anton Shestakov <av6@dwimlabs.net>
parents: 5166
diff changeset
   124
TEMPLATE_USERS = b"""by {label("evolve.user", join(users, ", "))}"""
5171
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   125
TEMPLATE_ONE_DATE = b"""({date(max(dates), "%a %b %d %H:%M:%S %Y %1%2")})"""
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   126
TEMPLATE_MANY_DATES = b"""(between {date(min(dates), "%a %b %d %H:%M:%S %Y %1%2")} and {date(max(dates), "%a %b %d %H:%M:%S %Y %1%2")})"""
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   127
TEMPLATE_DATES = b"""{label("evolve.date", ifeq(min(dates), max(dates), "%(onedate)s", "%(manydates)s"))}""" % {
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   128
    b"onedate": TEMPLATE_ONE_DATE,
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   129
    b"manydates": TEMPLATE_MANY_DATES
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   130
}
5170
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   131
TEMPLATE_NOTES = b"""{if(notes, notes % "\n    note: {label("evolve.note", note)}")}"""
4952
b135591bec1a obslog: make {patch} not be indented and leave that to the template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4951
diff changeset
   132
TEMPLATE_PATCH = b"""{if(patch, "{patch}")}{if(nopatchreason, "\n(No patch available, {nopatchreason})")}"""
4949
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   133
DEFAULT_TEMPLATE = (b"""%(firstline)s
5307
66a913cc53af obshistory: restructure templates a bit, drop default verb ("pruned")
Anton Shestakov <av6@dwimlabs.net>
parents: 5306
diff changeset
   134
{markers %% "  {separate(" ", "%(rewrite)s", "%(nodes)s", "%(operations)s", "%(users)s", "%(dates)s")}%(notes)s{indent(descdiff, "    ")}{indent("%(patch)s", "    ")}\n"}
4949
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   135
""") % {
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   136
    b"firstline": TEMPLATE_FIRST_LINE,
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   137
    b"rewrite": TEMPLATE_REWRITE,
5307
66a913cc53af obshistory: restructure templates a bit, drop default verb ("pruned")
Anton Shestakov <av6@dwimlabs.net>
parents: 5306
diff changeset
   138
    b"nodes": TEMPLATE_NODES,
5169
897b371cd0c5 obslog: make operation template property into operations
Anton Shestakov <av6@dwimlabs.net>
parents: 5168
diff changeset
   139
    b"operations": TEMPLATE_OPERATIONS,
5168
c7ca43bba6c5 obslog: make user template property into users
Anton Shestakov <av6@dwimlabs.net>
parents: 5166
diff changeset
   140
    b"users": TEMPLATE_USERS,
5171
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   141
    b"dates": TEMPLATE_DATES,
5170
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   142
    b"notes": TEMPLATE_NOTES,
4952
b135591bec1a obslog: make {patch} not be indented and leave that to the template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4951
diff changeset
   143
    b"patch": TEMPLATE_PATCH,
4949
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   144
}
eb9bcef7cc5f obslog: redefine default output as a template, unless -f was given
Martin von Zweigbergk <martinvonz@google.com>
parents: 4948
diff changeset
   145
5328
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   146
def groupbyfoldid(predsets):
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   147
    """ Group nodes and related obsmarkers by fold-id metadata.
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   148
    """
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   149
    groups = {}
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   150
    for (nodes, markers) in predsets:
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   151
        grouped = False
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   152
        for marker in markers:
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   153
            metadata = dict(marker[3])
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   154
            foldid = metadata.get(b'fold-id')
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   155
            if foldid is not None:
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   156
                groups.setdefault(foldid, []).append((nodes, markers))
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   157
                grouped = True
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   158
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   159
        if not grouped:
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   160
            yield (nodes, markers)
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   161
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   162
    for foldid in sorted(groups):
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   163
        groupnodes = set()
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   164
        groupmarkers = set()
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   165
        for (nodes, markers) in groups[foldid]:
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   166
            groupnodes.update(nodes)
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   167
            groupmarkers.update(markers)
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   168
        yield (tuple(sorted(groupnodes)), tuple(sorted(groupmarkers)))
a81631766575 obshistory: add a function to group predsets by fold-id
Anton Shestakov <av6@dwimlabs.net>
parents: 5327
diff changeset
   169
5329
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   170
def predecessorsandmarkers(repo, node):
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   171
    """ Compute data needed for obsorigin.
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   172
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   173
    Return a generator of (nodes, markers) tuples, where nodes is a tuple of
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   174
    predecessor nodes and markers is a tuple of obsolescence markers.
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   175
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   176
    Using tuples for everything means no problems with sorted().
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   177
    """
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   178
    predecessors = repo.obsstore.predecessors
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   179
    stack = [(node, ())]
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   180
    seen = {node}
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   181
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   182
    while stack:
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   183
        node, path = stack.pop()
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   184
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   185
        for marker in sorted(predecessors.get(node, ())):
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   186
            prednode = marker[0]
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   187
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   188
            # Basic cycle protection
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   189
            if prednode in seen:
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   190
                continue
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   191
            seen.add(prednode)
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   192
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   193
            if prednode in repo:
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   194
                yield ((prednode,), path + (marker,))
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   195
            else:
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   196
                stack.append((prednode, path + (marker,)))
0dc4c16506fc obshistory: add predecessorsandmarkers()
Anton Shestakov <av6@dwimlabs.net>
parents: 5328
diff changeset
   197
5346
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   198
def _originmarkers(repo, ctx, filternonlocal):
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   199
    predecessors = repo.obsstore.predecessors
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   200
    successors = repo.obsstore.successors
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   201
    if filternonlocal:
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   202
        r = predecessorsandmarkers(repo, ctx.node())
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   203
        for (nodes, markers) in sorted(groupbyfoldid(r)):
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   204
            yield (nodes, markers)
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   205
    else:
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   206
        markers = predecessors.get(ctx.node(), ())
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   207
        data = (((marker[0],), (marker,)) for marker in markers)
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   208
        for (nodes, markers) in sorted(groupbyfoldid(data)):
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   209
            yield (nodes, markers)
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   210
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   211
    # finding prune markers
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   212
    for marker in successors.get(ctx.node(), ()):
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   213
        if not marker[1]:
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   214
            yield ((), (marker,))
b117e4732656 obshistory: add _originmarkers() function to be used for obslog --origin
Anton Shestakov <av6@dwimlabs.net>
parents: 5345
diff changeset
   215
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   216
def _nodesandmarkers(repo, ctx, filternonlocal, origin):
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   217
    """ Return data for obslog and obsolescence-related template keywords.
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   218
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   219
    If `filternonlocal` is True, skip filtered nodes (but still gather
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   220
    obsolescence markers), otherwise the result will contain nodes unknown
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   221
    locally if they are found in the obsolescence markers.
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   222
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   223
    If `origin` is True, look at predecessors of ctx. Otherwise return
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   224
    successors and appropriate obsmarkers.
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   225
    """
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   226
    if origin:
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   227
        for (nodes, markers) in _originmarkers(repo, ctx, filternonlocal):
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   228
            yield (nodes, markers)
5306
1e2f3fa129f2 obshistory: prepare data for displaymarkers() in a separate function
Anton Shestakov <av6@dwimlabs.net>
parents: 5305
diff changeset
   229
    else:
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   230
        if filternonlocal:
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   231
            r = obsutil.successorsandmarkers(repo, ctx)
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   232
            if r is None:
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   233
                r = []
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   234
            for succset in sorted(r):
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   235
                if succset[b'markers']:
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   236
                    yield (succset[b'successors'], succset[b'markers'])
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   237
        else:
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   238
            markers = repo.obsstore.successors.get(ctx.node(), ())
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   239
            for marker in sorted(markers):
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   240
                yield (marker[1], [marker])
5306
1e2f3fa129f2 obshistory: prepare data for displaymarkers() in a separate function
Anton Shestakov <av6@dwimlabs.net>
parents: 5305
diff changeset
   241
5181
c979d64a2589 compat: drop 4.5 compatibility layer for log utility
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5173
diff changeset
   242
class obsmarker_printer(logcmdutil.changesetprinter):
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   243
    """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
   244
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   245
    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
   246
    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
   247
3921
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   248
    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
   249
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   250
        if kwargs.pop('obspatch', False):
5181
c979d64a2589 compat: drop 4.5 compatibility layer for log utility
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5173
diff changeset
   251
            if logcmdutil.changesetdiffer is None:
3921
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   252
                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
   253
            else:
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   254
                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
   255
28824ad64a12 compat: restore compatibility with Mercurial <= 4.5
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3884
diff changeset
   256
        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
   257
        diffopts = kwargs.get('diffopts', {})
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   258
5193
a4d081923c81 compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents: 5182
diff changeset
   259
        # hg <= 4.6 (3fe1c9263024)
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   260
        if not util.safehasattr(self, "_includediff"):
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   261
            self._includediff = diffopts and diffopts.get(b'patch')
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   262
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   263
        self.template = diffopts and diffopts.get(b'template')
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   264
        self.filter = diffopts and diffopts.get(b'filternonlocal')
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   265
        self.origin = diffopts and diffopts.get(b'origin')
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   266
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   267
    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
   268
        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
   269
            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
   270
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   271
            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
   272
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   273
            _props = {b"template": self.template}
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   274
            fm = self.ui.formatter(b'debugobshistory', _props)
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   275
5300
372dc6c5692a obshistory: rename node/ctx-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5216
diff changeset
   276
            displaynode(fm, self.repo, changenode)
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   277
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   278
            markerfm = fm.nested(b"markers")
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   279
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   280
            data = _nodesandmarkers(self.repo, ctx, self.filter, self.origin)
5306
1e2f3fa129f2 obshistory: prepare data for displaymarkers() in a separate function
Anton Shestakov <av6@dwimlabs.net>
parents: 5305
diff changeset
   281
            for nodes, markers in data:
1e2f3fa129f2 obshistory: prepare data for displaymarkers() in a separate function
Anton Shestakov <av6@dwimlabs.net>
parents: 5305
diff changeset
   282
                displaymarkers(self.ui, markerfm, nodes, markers, ctx.node(),
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   283
                               self.repo, self._includediff,
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   284
                               successive=not self.origin)
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   285
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   286
            markerfm.end()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   287
4940
93c89814a5d8 obslog: avoid using a formatter after calling end() on it
Martin von Zweigbergk <martinvonz@google.com>
parents: 4939
diff changeset
   288
            fm.plain(b'\n')
2955
b899a94472fd obslog: uniformize `_debugobshistoryrevs` and `_debugobshistorygraph` arguments
Alain Leufroy
parents: 2954
diff changeset
   289
            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
   290
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   291
            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
   292
        else:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   293
            ### graph output is buffered only
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   294
            msg = b'cannot be used outside of the graphlog (yet)'
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   295
            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
   296
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   297
    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
   298
        ''' 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
   299
        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
   300
        '''
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   301
        pass
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   302
5305
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   303
def patchavailable(node, repo, candidates, successive=True):
5326
99c25397889e obshistory: add a docstring to patchavailable()
Anton Shestakov <av6@dwimlabs.net>
parents: 5321
diff changeset
   304
    """ Check if it's possible to get a diff between node and candidates.
99c25397889e obshistory: add a docstring to patchavailable()
Anton Shestakov <av6@dwimlabs.net>
parents: 5321
diff changeset
   305
99c25397889e obshistory: add a docstring to patchavailable()
Anton Shestakov <av6@dwimlabs.net>
parents: 5321
diff changeset
   306
    `candidates` contains nodes, which can be either successors (`successive`
99c25397889e obshistory: add a docstring to patchavailable()
Anton Shestakov <av6@dwimlabs.net>
parents: 5321
diff changeset
   307
    is True) or predecessors (`successive` is False) of `node`.
99c25397889e obshistory: add a docstring to patchavailable()
Anton Shestakov <av6@dwimlabs.net>
parents: 5321
diff changeset
   308
    """
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   309
    if node not in repo:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   310
        return False, b"context is not local"
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   311
5305
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   312
    if len(candidates) == 0:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   313
        if successive:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   314
            msg = b"no successors"
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   315
        else:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   316
            msg = b"no predecessors"
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   317
        return False, msg
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   318
    elif len(candidates) > 1:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   319
        if successive:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   320
            msg = b"too many successors (%d)"
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   321
        else:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   322
            msg = b"too many predecessors (%d)"
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   323
        return False, msg % len(candidates)
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   324
5305
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   325
    cand = candidates[0]
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   326
5305
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   327
    if cand not in repo:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   328
        if successive:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   329
            msg = b"successor is unknown locally"
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   330
        else:
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   331
            msg = b"predecessor is unknown locally"
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   332
        return False, msg
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   333
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   334
    # Check that both node and cand have the same parents
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   335
    nodep1, nodep2 = repo[node].p1(), repo[node].p2()
5305
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   336
    candp1, candp2 = repo[cand].p1(), repo[cand].p2()
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   337
5305
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   338
    if nodep1 != candp1 or nodep2 != candp2:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   339
        return False, b"changesets rebased"
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   340
5305
292de4cca111 obshistory: make patchavailable() handle predecessors too
Anton Shestakov <av6@dwimlabs.net>
parents: 5303
diff changeset
   341
    return True, cand
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   342
3402
7a322f58fee3 obshistory: pass the csets description in getmarkerdescriptionpatch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3401
diff changeset
   343
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
   344
    # 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
   345
    # add one to avoid ugly diff
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   346
    basedesc += b'\n'
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   347
    succdesc += b'\n'
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   348
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   349
    # fake file name
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   350
    basename = b"changeset-description"
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   351
    succname = b"changeset-description"
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   352
5182
df5e6e3884bc compat: drop 4.5 compatibility for strdiff
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5181
diff changeset
   353
    uheaders, hunks = mdiff.unidiff(basedesc, b'', succdesc, b'',
df5e6e3884bc compat: drop 4.5 compatibility for strdiff
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5181
diff changeset
   354
                                    basename, succname, False)
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   355
3604
d24ba168a532 obslog: cleanup patch handling after 4.1 compat drop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3519
diff changeset
   356
    # Copied from patch.diff
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   357
    text = b''.join(sum((list(hlines) for hrange, hlines in hunks), []))
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   358
    patch = b"\n".join(uheaders + [text])
3400
6d345d7ca682 obslog: add header to the changeset description diff
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3399
diff changeset
   359
3399
4adf46158b9b obslog: colorize the description diff shown in obslog -p
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3398
diff changeset
   360
    return patch
2639
a5d8062f55ba obslog: also display description patch with --patch
Boris Feld <boris.feld@octobus.net>
parents: 2638
diff changeset
   361
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   362
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
   363
    ''' 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
   364
    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
   365
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   366
    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
   367
        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
   368
        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
   369
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   370
    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
   371
        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
   372
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   373
    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
   374
        # 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
   375
        return True
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   376
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   377
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
   378
    """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
   379
    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
   380
    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
   381
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   382
    >>> 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
   383
    True
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   384
    >>> 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
   385
    False
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   386
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   387
    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
   388
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
    visited = set()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   391
    o = object()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   392
    path = [o]
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   393
    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
   394
    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
   395
    while stack:
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   396
        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
   397
            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
   398
                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
   399
                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
   400
            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
   401
                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
   402
                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
   403
                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
   404
                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
   405
                break
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   406
        else:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   407
            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
   408
            stack.pop()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   409
    return False
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   410
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   411
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
   412
    """ 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
   413
    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
   414
    (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
   415
    """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   416
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   417
    # 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
   418
    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
   419
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   420
    # 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
   421
    shown = set()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   422
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   423
    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
   424
        """ 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
   425
        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
   426
        """
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   427
        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
   428
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   429
    # 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
   430
    while candidates:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   431
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   432
        # 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
   433
        # 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
   434
        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
   435
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   436
        # If we likely have a cycle
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   437
        if not validcandidates:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   438
            cycle = cyclic(nodesucc)
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   439
            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
   440
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   441
            # Then choose a random node from the cycle
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   442
            breaknode = sorted(cycle)[0]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   443
            # And display it by force
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   444
            repo.ui.debug(b'obs-cycle detected, forcing display of %s\n'
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   445
                          % nodemod.short(breaknode))
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   446
            validcandidates = [breaknode]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   447
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   448
        # 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
   449
        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
   450
            # 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
   451
            candidates.remove(cand)
2411
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   452
            # 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
   453
            try:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   454
                del nodesucc[cand]
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   455
            except KeyError:
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   456
                pass
bd937b7ce7d2 debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents: 2407
diff changeset
   457
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   458
            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
   459
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   460
            # 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
   461
            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
   462
                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
   463
            else:
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   464
                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
   465
                    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
   466
                else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   467
                    continue
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   468
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   469
            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
   470
                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
   471
            else:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   472
                relations = obsutil.closestpredecessors(repo, cand)
5216
8c131b97e197 obshistory: give a more correct name to a variable
Anton Shestakov <av6@dwimlabs.net>
parents: 5193
diff changeset
   473
            parents = [(graphmod.PARENT, x) for x in relations]
8c131b97e197 obshistory: give a more correct name to a variable
Anton Shestakov <av6@dwimlabs.net>
parents: 5193
diff changeset
   474
            yield (cand, graphmod.CHANGESET, changectx, parents)
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   475
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
   476
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
   477
    """ 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
   478
    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
   479
    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
   480
    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
   481
    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
   482
    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
   483
    - 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
   484
    - 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
   485
    - 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
   486
    """
2840
dfad30be866c context: precursors was deprecated
Boris Feld <boris.feld@octobus.net>
parents: 2832
diff changeset
   487
    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
   488
    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
   489
    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
   490
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   491
    # 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
   492
    nodesucc = dict()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   493
    # Childrens
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   494
    nodeprec = dict()
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   495
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   496
    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
   497
    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
   498
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   499
    # 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
   500
    while nodes:
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   501
        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
   502
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   503
        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
   504
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   505
        nodeprec[node] = []
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   506
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   507
        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
   508
            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
   509
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   510
            # 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
   511
            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
   512
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   513
            # 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
   514
            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
   515
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   516
            # 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
   517
            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
   518
                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
   519
                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
   520
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
   521
        # 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
   522
        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
   523
            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
   524
                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
   525
                    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
   526
                        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
   527
                        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
   528
2407
783a74c60a5e obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2406
diff changeset
   529
    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
   530
5301
35c15057e2e5 obshistory: rename graph/revs-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5300
diff changeset
   531
def displaygraph(ui, repo, revs, opts):
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   532
4752
8a73a8df63b6 py3: convert opts keys to bytes before passing to core APIs
Martin von Zweigbergk <martinvonz@google.com>
parents: 4747
diff changeset
   533
    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
   534
                                  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
   535
                                  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
   536
    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
   537
    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
   538
                               opts.get('filternonlocal', False))
5181
c979d64a2589 compat: drop 4.5 compatibility layer for log utility
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 5173
diff changeset
   539
    logcmdutil.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
   540
5301
35c15057e2e5 obshistory: rename graph/revs-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5300
diff changeset
   541
def displayrevs(ui, repo, revs, opts):
2633
59e85fbb31b6 obslog: small renaming of _debugobshistorysingle
Boris Feld <boris.feld@octobus.net>
parents: 2610
diff changeset
   542
    """ Display the obsolescence history for revset
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   543
    """
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   544
    fm = ui.formatter(b'debugobshistory', pycompat.byteskwargs(opts))
5303
61538e2db220 obshistory: rename precursors to predecessors in displayrevs()
Anton Shestakov <av6@dwimlabs.net>
parents: 5302
diff changeset
   545
    predecessors = repo.obsstore.predecessors
5309
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   546
    successors = repo.obsstore.successors
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   547
    nodec = repo.changelog.node
2635
9ab35c37b85a obslog: pass directly unfiltered_repo
Boris Feld <boris.feld@octobus.net>
parents: 2634
diff changeset
   548
    unfi = repo.unfiltered()
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   549
    nodes = [nodec(r) for r in revs]
5308
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   550
    seen = set(nodes)
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   551
    toshow = []
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   552
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   553
    origin = opts and opts.get('origin')
5309
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   554
    walksuccessors = opts and opts.get('all')
5308
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   555
    filternonlocal = opts and opts.get('filternonlocal')
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   556
    includediff = opts and opts.get('patch')
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   557
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   558
    while nodes:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   559
        ctxnode = nodes.pop()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   560
5308
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   561
        if ctxnode in unfi:
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   562
            toshow.append(unfi[ctxnode])
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   563
        else:
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   564
            if filternonlocal is False:
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   565
                toshow.append(missingchangectx(unfi, ctxnode))
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   566
5303
61538e2db220 obshistory: rename precursors to predecessors in displayrevs()
Anton Shestakov <av6@dwimlabs.net>
parents: 5302
diff changeset
   567
        preds = predecessors.get(ctxnode, ())
61538e2db220 obshistory: rename precursors to predecessors in displayrevs()
Anton Shestakov <av6@dwimlabs.net>
parents: 5302
diff changeset
   568
        for p in sorted(preds):
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   569
            # Only show nodes once
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   570
            if p[0] not in seen:
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   571
                seen.add(p[0])
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   572
                nodes.append(p[0])
5308
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   573
5309
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   574
        if walksuccessors:
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   575
            for successor in successors.get(ctxnode, ()):
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   576
                for s in successor[1]:
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   577
                    if s not in seen:
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   578
                        seen.add(s)
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   579
                        nodes.append(s)
9923c6d6f0a8 obslog: support --all with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5308
diff changeset
   580
5308
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   581
    for ctx in toshow:
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   582
        displaynode(fm, unfi, ctx.node())
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   583
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   584
        markerfm = fm.nested(b"markers")
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   585
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   586
        data = _nodesandmarkers(unfi, ctx, filternonlocal, origin)
5308
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   587
        for nodes_, markers in data:
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   588
            displaymarkers(ui, markerfm, nodes_, markers, ctx.node(), unfi,
5348
a9f9edb168a1 obslog: add a --origin flag to show predecessors instead of successors
Anton Shestakov <av6@dwimlabs.net>
parents: 5347
diff changeset
   589
                           includediff, successive=not origin)
5308
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   590
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   591
        markerfm.end()
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   592
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   593
        fm.plain(b'\n')
0329246c70f3 obslog: support --filternonlocal with --no-graph
Anton Shestakov <av6@dwimlabs.net>
parents: 5307
diff changeset
   594
2955
b899a94472fd obslog: uniformize `_debugobshistoryrevs` and `_debugobshistorygraph` arguments
Alain Leufroy
parents: 2954
diff changeset
   595
    fm.end()
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   596
5300
372dc6c5692a obshistory: rename node/ctx-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5216
diff changeset
   597
def displaynode(fm, repo, node):
2635
9ab35c37b85a obslog: pass directly unfiltered_repo
Boris Feld <boris.feld@octobus.net>
parents: 2634
diff changeset
   598
    if node in repo:
5300
372dc6c5692a obshistory: rename node/ctx-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5216
diff changeset
   599
        displayctx(fm, repo[node])
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   600
    else:
5300
372dc6c5692a obshistory: rename node/ctx-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5216
diff changeset
   601
        displaymissingctx(fm, node)
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   602
5300
372dc6c5692a obshistory: rename node/ctx-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5216
diff changeset
   603
def displayctx(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
   604
    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
   605
    if shortdescription:
1b1badb3d2fc obshistory: make obslog work when a commit doesn't have any description
Anton Shestakov <av6@dwimlabs.net>
parents: 3728
diff changeset
   606
        shortdescription = shortdescription.splitlines()[0]
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   607
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   608
    fm.startitem()
4917
d1d8e97d32af obslog: make changeset available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4894
diff changeset
   609
    fm.context(ctx=ctx)
4983
6d40e0166522 obslog: make {node} the full node and leave shortening to template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4953
diff changeset
   610
    fm.data(node=ctx.hex())
6d40e0166522 obslog: make {node} the full node and leave shortening to template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4953
diff changeset
   611
    fm.plain(b'%s' % bytes(ctx), label=b"evolve.node")
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   612
    fm.plain(b' ')
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   613
4918
f16274729530 obslog: don't overwrite {rev} keyword from changeset context
Martin von Zweigbergk <martinvonz@google.com>
parents: 4917
diff changeset
   614
    fm.plain(b'(%d)' % ctx.rev(), label=b"evolve.rev")
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   615
    fm.plain(b' ')
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   616
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   617
    fm.write(b'shortdescription', b'%s', shortdescription,
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   618
             label=b"evolve.short_description")
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   619
    fm.plain(b'\n')
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   620
5300
372dc6c5692a obshistory: rename node/ctx-displaying functions
Anton Shestakov <av6@dwimlabs.net>
parents: 5216
diff changeset
   621
def displaymissingctx(fm, nodewithoutctx):
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   622
    fm.startitem()
4983
6d40e0166522 obslog: make {node} the full node and leave shortening to template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4953
diff changeset
   623
    fm.data(node=nodemod.hex(nodewithoutctx))
6d40e0166522 obslog: make {node} the full node and leave shortening to template
Martin von Zweigbergk <martinvonz@google.com>
parents: 4953
diff changeset
   624
    fm.plain(nodemod.short(nodewithoutctx),
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   625
             label=b"evolve.node evolve.missing_change_ctx")
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   626
    fm.plain(b'\n')
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   627
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   628
def displaymarkers(ui, fm, nodes, markers, node, repo, includediff=False,
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   629
                   successive=True):
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   630
    fm.startitem()
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   631
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   632
    if successive:
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   633
        verb = _successorsetverb(nodes, markers)[b"verb"]
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   634
    else:
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   635
        verb = _predecessorsverb(nodes, markers)
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   636
4950
60d2065b720b obslog: remove now-unused code for plain styling
Martin von Zweigbergk <martinvonz@google.com>
parents: 4949
diff changeset
   637
    fm.data(verb=verb)
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   638
5172
52301aff269e obslog: provide successors and multiple markers to marker-displaying function
Anton Shestakov <av6@dwimlabs.net>
parents: 5171
diff changeset
   639
    effects = _markerseffects(markers)
5066
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   640
    if effects:
5166
27845c5aefb3 obslog: use fm.data() instead of fm.write() because it's all templates now
Anton Shestakov <av6@dwimlabs.net>
parents: 5123
diff changeset
   641
        fmteffects = fm.formatlist(effects, b'effect', sep=b', ')
27845c5aefb3 obslog: use fm.data() instead of fm.write() because it's all templates now
Anton Shestakov <av6@dwimlabs.net>
parents: 5123
diff changeset
   642
        fm.data(effects=fmteffects)
2453
ad08aedf25ac obshistory: display informations from the obs marker effect flag
Boris Feld <boris.feld@octobus.net>
parents: 2450
diff changeset
   643
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   644
    if len(nodes) > 0:
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   645
        hexnodes = (nodemod.hex(node) for node in sorted(nodes))
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   646
        if successive:
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   647
            nodelist = fm.formatlist(hexnodes, b'succnode')
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   648
            fm.data(succnodes=nodelist)
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   649
        else:
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   650
            nodelist = fm.formatlist(hexnodes, b'prednode')
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   651
            fm.data(prednodes=nodelist)
2832
07b9fcf8b6d3 output: update obsfate / obslog output order
Boris Feld <boris.feld@octobus.net>
parents: 2697
diff changeset
   652
5169
897b371cd0c5 obslog: make operation template property into operations
Anton Shestakov <av6@dwimlabs.net>
parents: 5168
diff changeset
   653
    # Operations
5172
52301aff269e obslog: provide successors and multiple markers to marker-displaying function
Anton Shestakov <av6@dwimlabs.net>
parents: 5171
diff changeset
   654
    operations = obsutil.markersoperations(markers)
5169
897b371cd0c5 obslog: make operation template property into operations
Anton Shestakov <av6@dwimlabs.net>
parents: 5168
diff changeset
   655
    if operations:
897b371cd0c5 obslog: make operation template property into operations
Anton Shestakov <av6@dwimlabs.net>
parents: 5168
diff changeset
   656
        fm.data(operations=fm.formatlist(operations, name=b'operation', sep=b', '))
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   657
5168
c7ca43bba6c5 obslog: make user template property into users
Anton Shestakov <av6@dwimlabs.net>
parents: 5166
diff changeset
   658
    # Users
5172
52301aff269e obslog: provide successors and multiple markers to marker-displaying function
Anton Shestakov <av6@dwimlabs.net>
parents: 5171
diff changeset
   659
    users = obsutil.markersusers(markers)
5168
c7ca43bba6c5 obslog: make user template property into users
Anton Shestakov <av6@dwimlabs.net>
parents: 5166
diff changeset
   660
    fm.data(users=fm.formatlist(users, name=b'user', sep=b', '))
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   661
5171
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   662
    # Dates
5172
52301aff269e obslog: provide successors and multiple markers to marker-displaying function
Anton Shestakov <av6@dwimlabs.net>
parents: 5171
diff changeset
   663
    dates = obsutil.markersdates(markers)
5171
7f7f40cc6c9b obslog: make date template property into dates
Anton Shestakov <av6@dwimlabs.net>
parents: 5170
diff changeset
   664
    fm.data(dates=fm.formatlist(dates, name=b'date'))
2403
1b348702d79e obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
   665
5170
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   666
    # Notes
5172
52301aff269e obslog: provide successors and multiple markers to marker-displaying function
Anton Shestakov <av6@dwimlabs.net>
parents: 5171
diff changeset
   667
    notes = _markersnotes(markers)
5170
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   668
    if notes:
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   669
        fm.data(notes=fm.formatlist(notes, name=b'note', sep=b'\n'))
3214
9fe2b3fd7fc7 obslog: add initial support for showing note in obslog
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3181
diff changeset
   670
2637
49f2741c4dd7 obslog: add a patch option
Boris Feld <boris.feld@octobus.net>
parents: 2636
diff changeset
   671
    # Patch display
3746
4dcf87849f9d compat: fix obslog with Mercurial 4.6+
Boris Feld <boris.feld@octobus.net>
parents: 3729
diff changeset
   672
    if includediff is True:
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   673
        _patchavailable = patchavailable(node, repo, nodes,
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   674
                                         successive=successive)
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   675
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   676
        if _patchavailable[0] is True:
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   677
            diffnode = _patchavailable[1]
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   678
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   679
            if successive:
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   680
                actx = repo[node]
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   681
                bctx = repo[diffnode]
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   682
            else:
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   683
                actx = repo[diffnode]
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   684
                bctx = repo[node]
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   685
            # Description patch
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   686
            descriptionpatch = getmarkerdescriptionpatch(repo,
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   687
                                                         actx.description(),
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   688
                                                         bctx.description())
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   689
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   690
            if descriptionpatch:
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   691
                # add the diffheader
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   692
                diffheader = b"diff -r %s -r %s changeset-description\n" %\
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   693
                             (actx, bctx)
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   694
                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
   695
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   696
                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
   697
                    return [text]
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   698
4946
bd992b1d4426 obslog: make content and description patches available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4945
diff changeset
   699
                ui.pushbuffer(labeled=True)
bd992b1d4426 obslog: make content and description patches available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4945
diff changeset
   700
                ui.write(b"\n")
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   701
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   702
                for chunk, label in patch.difflabel(tolist, descriptionpatch):
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   703
                    chunk = chunk.strip(b'\t')
4946
bd992b1d4426 obslog: make content and description patches available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4945
diff changeset
   704
                    ui.write(chunk, label=label)
bd992b1d4426 obslog: make content and description patches available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4945
diff changeset
   705
                fm.write(b'descdiff', b'%s', ui.popbuffer())
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   706
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   707
            # Content patch
4946
bd992b1d4426 obslog: make content and description patches available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4945
diff changeset
   708
            ui.pushbuffer(labeled=True)
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   709
            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
   710
            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
   711
            firstline = True
4823
c16fed4908d8 obslog: only indent the first chunk and chunks just after newlines (issue6175)
Anton Shestakov <av6@dwimlabs.net>
parents: 4752
diff changeset
   712
            linestart = True
5347
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   713
            for chunk, label in patch.diffui(repo, actx.node(), bctx.node(),
2d48fc2c47fc obslog: add preliminary support for showing predecessors
Anton Shestakov <av6@dwimlabs.net>
parents: 5346
diff changeset
   714
                                             matchfn, 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
   715
                if firstline:
4946
bd992b1d4426 obslog: make content and description patches available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4945
diff changeset
   716
                    ui.write(b'\n')
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   717
                    firstline = False
4823
c16fed4908d8 obslog: only indent the first chunk and chunks just after newlines (issue6175)
Anton Shestakov <av6@dwimlabs.net>
parents: 4752
diff changeset
   718
                if linestart:
c16fed4908d8 obslog: only indent the first chunk and chunks just after newlines (issue6175)
Anton Shestakov <av6@dwimlabs.net>
parents: 4752
diff changeset
   719
                    linestart = False
4827
4c6dd20e8cc2 branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4814 4823
diff changeset
   720
                if chunk == b'\n':
4823
c16fed4908d8 obslog: only indent the first chunk and chunks just after newlines (issue6175)
Anton Shestakov <av6@dwimlabs.net>
parents: 4752
diff changeset
   721
                    linestart = True
4946
bd992b1d4426 obslog: make content and description patches available to templater
Martin von Zweigbergk <martinvonz@google.com>
parents: 4945
diff changeset
   722
                ui.write(chunk, label=label)
4950
60d2065b720b obslog: remove now-unused code for plain styling
Martin von Zweigbergk <martinvonz@google.com>
parents: 4949
diff changeset
   723
            fm.data(patch=ui.popbuffer())
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   724
        else:
4950
60d2065b720b obslog: remove now-unused code for plain styling
Martin von Zweigbergk <martinvonz@google.com>
parents: 4949
diff changeset
   725
            fm.data(nopatchreason=_patchavailable[1])
3884
16bec7609a08 obslog: add a new flag to filter out non-local nodes
Boris Feld <boris.feld@octobus.net>
parents: 3883
diff changeset
   726
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   727
def _prepare_hunk(hunk):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   728
    """Drop all information but the username and patch"""
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   729
    cleanunk = []
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   730
    for line in hunk.splitlines():
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   731
        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
   732
            if line.startswith(b'@@'):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   733
                line = b'@@\n'
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   734
            cleanunk.append(line)
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   735
    return cleanunk
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   736
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   737
def _getdifflines(iterdiff):
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   738
    """return a cleaned up lines"""
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   739
    try:
4738
45508676ed00 py3: replace iter.next() by next(iter)
Martin von Zweigbergk <martinvonz@google.com>
parents: 4715
diff changeset
   740
        lines = next(iterdiff)
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   741
    except StopIteration:
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   742
        return None
2520
5fb5d096348c effectflag: better diff detection
Boris Feld <boris.feld@octobus.net>
parents: 2492
diff changeset
   743
    return _prepare_hunk(lines)
2450
98613938d098 effectflag: basic diff change detection
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2449
diff changeset
   744
5057
da5cc4e493ff obshistory: drop unused keyword argument to _getobsfateandsuccs()
Anton Shestakov <av6@dwimlabs.net>
parents: 5056
diff changeset
   745
def _getobsfateandsuccs(repo, revnode):
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   746
    """ Return a tuple containing:
5053
196ed65594dc evolve: correct spelling of superseded everywhere else
Anton Shestakov <av6@dwimlabs.net>
parents: 5052
diff changeset
   747
    - the reason a revision is obsolete (diverged, pruned or superseded)
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   748
    - 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
   749
    or has diverged
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   750
    """
5057
da5cc4e493ff obshistory: drop unused keyword argument to _getobsfateandsuccs()
Anton Shestakov <av6@dwimlabs.net>
parents: 5056
diff changeset
   751
    successorssets = obsutil.successorssets(repo, revnode)
5052
b9a7fb0a0a49 evolve: use obsutil._getobsfate() directly
Anton Shestakov <av6@dwimlabs.net>
parents: 4983
diff changeset
   752
    fate = obsutil._getobsfate(successorssets)
2488
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   753
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   754
    # 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
   755
    if len(successorssets) == 1:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   756
        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
   757
    else:
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   758
        successors = []
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   759
        for succset in successorssets:
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   760
            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
   761
1bdbe8f55339 refactor: extract obs fate algorithm from _getobsoletereason
Boris Feld <boris.feld@octobus.net>
parents: 2484
diff changeset
   762
    return (fate, successors)
2490
94f171534918 template: update obsfate to be more human friendly
Boris Feld <boris.feld@octobus.net>
parents: 2488
diff changeset
   763
5170
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   764
def _markersnotes(markers):
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   765
    markersmeta = [dict(m[3]) for m in markers]
5336
b55c0cea3fa2 obshistory: omit duplicate notes of obsolescence operations
Anton Shestakov <av6@dwimlabs.net>
parents: 5330
diff changeset
   766
    notes = {meta.get(b'note') for meta in markersmeta}
5170
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   767
    return sorted(note for note in notes if note)
f8488bdc9e4b obslog: make note template property into notes
Anton Shestakov <av6@dwimlabs.net>
parents: 5169
diff changeset
   768
5067
e07f6af3cfec obshistory: make a {flag value: description} dict for _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5066
diff changeset
   769
EFFECTMAPPING = util.sortdict([
5068
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   770
    (obsutil.DESCCHANGED, b'description'),
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   771
    (obsutil.METACHANGED, b'meta'),
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   772
    (obsutil.USERCHANGED, b'user'),
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   773
    (obsutil.DATECHANGED, b'date'),
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   774
    (obsutil.BRANCHCHANGED, b'branch'),
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   775
    (obsutil.PARENTCHANGED, b'parent'),
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   776
    (obsutil.DIFFCHANGED, b'content'),
5067
e07f6af3cfec obshistory: make a {flag value: description} dict for _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5066
diff changeset
   777
])
e07f6af3cfec obshistory: make a {flag value: description} dict for _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5066
diff changeset
   778
5066
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   779
def _markerseffects(markers):
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   780
    """ Return a list of effects as strings based on effect flags in markers
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   781
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   782
    Return None if verb cannot be more precise than just "rewritten", i.e. when
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   783
    markers collectively have more than one effect in the flags.
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   784
    """
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   785
    metadata = [dict(marker[3]) for marker in markers]
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   786
    ef1 = [data.get(b'ef1') for data in metadata]
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   787
    effects = []
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   788
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   789
    combined = 0
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   790
    for ef in ef1:
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   791
        if ef:
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   792
            combined |= int(ef)
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   793
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   794
    if combined:
5067
e07f6af3cfec obshistory: make a {flag value: description} dict for _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5066
diff changeset
   795
        for key, value in EFFECTMAPPING.items():
e07f6af3cfec obshistory: make a {flag value: description} dict for _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5066
diff changeset
   796
            if combined & key:
e07f6af3cfec obshistory: make a {flag value: description} dict for _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5066
diff changeset
   797
                effects.append(value)
5066
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   798
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   799
    return effects
8dc865544aa1 obshistory: factor out _markerseffects()
Anton Shestakov <av6@dwimlabs.net>
parents: 5065
diff changeset
   800
2896
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   801
VERBMAPPING = {
5068
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   802
    obsutil.DESCCHANGED: b"reworded",
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   803
    obsutil.METACHANGED: b"meta-changed",
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   804
    obsutil.USERCHANGED: b"reauthored",
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   805
    obsutil.DATECHANGED: b"date-changed",
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   806
    obsutil.BRANCHCHANGED: b"branch-changed",
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   807
    obsutil.PARENTCHANGED: b"rebased",
715c85f250e0 obshistory: use effect flags from obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 5067
diff changeset
   808
    obsutil.DIFFCHANGED: b"amended"
2896
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   809
}
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   810
5065
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   811
def _markerspreciseverb(markers):
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   812
    """ Return a more precise verb based on effect flags in markers
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   813
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   814
    Return None if verb cannot be more precise than just "rewritten", i.e. when
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   815
    markers collectively have more than one effect in the flags.
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   816
    """
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   817
    metadata = [dict(marker[3]) for marker in markers]
5115
f44cc9abf21c obshistory: add 'folded' to the list of precise verbs
Anton Shestakov <av6@dwimlabs.net>
parents: 5072
diff changeset
   818
f44cc9abf21c obshistory: add 'folded' to the list of precise verbs
Anton Shestakov <av6@dwimlabs.net>
parents: 5072
diff changeset
   819
    if len(metadata) == 1 and metadata[0].get(b'fold-id') is not None:
f44cc9abf21c obshistory: add 'folded' to the list of precise verbs
Anton Shestakov <av6@dwimlabs.net>
parents: 5072
diff changeset
   820
        return b'folded'
f44cc9abf21c obshistory: add 'folded' to the list of precise verbs
Anton Shestakov <av6@dwimlabs.net>
parents: 5072
diff changeset
   821
5065
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   822
    ef1 = [data.get(b'ef1') for data in metadata]
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   823
    if all(ef1):
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   824
        combined = 0
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   825
        for ef in ef1:
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   826
            combined |= int(ef)
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   827
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   828
        # Combined will be in VERBMAPPING only if one bit is set
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   829
        if combined in VERBMAPPING:
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   830
            return VERBMAPPING[combined]
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   831
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   832
def _successorsetverb(successorset, markers):
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   833
    """ Return the verb summarizing the successorset
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   834
    """
2896
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   835
    verb = None
2606
02129bed002c obsfate: improve prune support in _successorsetverb
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2604
diff changeset
   836
    if not successorset:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   837
        verb = b'pruned'
2607
054d92586e43 obsfate: use 'split' as verb when appropriate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2606
diff changeset
   838
    elif len(successorset) == 1:
5065
877d80a205d1 obshistory: factor out _markerspreciseverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5058
diff changeset
   839
        verb = _markerspreciseverb(markers)
2896
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   840
462adae9fea7 obsfate: use effect flag information for computing a better verb
Boris Feld <boris.feld@octobus.net>
parents: 2840
diff changeset
   841
        if verb is None:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   842
            verb = b'rewritten'
2606
02129bed002c obsfate: improve prune support in _successorsetverb
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2604
diff changeset
   843
    else:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   844
        verb = b'split'
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4801
diff changeset
   845
    return {b'verb': verb}
2591
1991935fb603 obsfate: add a new obsfate template
Boris Feld <boris.feld@octobus.net>
parents: 2586
diff changeset
   846
5327
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   847
def _predecessorsverb(predecessors, markers):
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   848
    """ Return the verb summarizing a set of predecessors and related markers.
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   849
    """
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   850
    verb = None
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   851
    if not predecessors:
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   852
        # we got successors instead of predecessors, and they are empty
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   853
        # (this is a special case for showing prunes)
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   854
        verb = b'pruned'
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   855
    elif len(markers) == 1 and len(markers[0][1]) > 1:
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   856
        # peeked at the successors to see if this is a split
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   857
        verb = b'split'
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   858
    elif len(predecessors) == 1:
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   859
        verb = _markerspreciseverb(markers)
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   860
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   861
        if verb is None:
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   862
            verb = b'rewritten'
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   863
    else:
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   864
        verb = b'folded'
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   865
    return verb
b1a564cb18d0 obshistory: add _predecessorsverb() similar to _successorsetverb()
Anton Shestakov <av6@dwimlabs.net>
parents: 5326
diff changeset
   866
3181
5db76f35efce effect-flag: fix obsfate verb hooking
Boris Feld <boris.feld@octobus.net>
parents: 3115
diff changeset
   867
# Use a more advanced version of obsfateverb that uses effect-flag
5058
c95e68e8a219 obshistory: remove obsfateverb/obsfateprinter patching compatibility
Anton Shestakov <av6@dwimlabs.net>
parents: 5057
diff changeset
   868
@eh.wrapfunction(obsutil, 'obsfateverb')
c95e68e8a219 obshistory: remove obsfateverb/obsfateprinter patching compatibility
Anton Shestakov <av6@dwimlabs.net>
parents: 5057
diff changeset
   869
def obsfateverb(orig, *args, **kwargs):
c95e68e8a219 obshistory: remove obsfateverb/obsfateprinter patching compatibility
Anton Shestakov <av6@dwimlabs.net>
parents: 5057
diff changeset
   870
    return _successorsetverb(*args, **kwargs)[b'verb']
5330
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   871
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   872
def obsoriginprinter(ui, repo, predecessors, markers):
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   873
    """ Build an obsorigin string for a single set of predecessors.
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   874
    """
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   875
    quiet = ui.quiet
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   876
    verbose = ui.verbose
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   877
    normal = not verbose and not quiet
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   878
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   879
    line = []
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   880
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   881
    # Verb
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   882
    line.append(_predecessorsverb(predecessors, markers))
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   883
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   884
    # Operations
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   885
    operations = obsutil.markersoperations(markers)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   886
    if operations:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   887
        line.append(b" using %s" % b", ".join(operations))
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   888
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   889
    # Predecessors
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   890
    if predecessors:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   891
        unfi = repo.unfiltered()
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   892
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   893
        def formatnode(node):
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   894
            if node in unfi:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   895
                return scmutil.formatchangeid(unfi[node])
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   896
            return nodemod.short(node)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   897
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   898
        fmtpredecessors = [formatnode(pred) for pred in predecessors]
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   899
        line.append(b" from %s" % b", ".join(sorted(fmtpredecessors)))
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   900
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   901
    # Users
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   902
    users = obsutil.markersusers(markers)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   903
    # Filter out current user in not verbose mode to reduce amount of
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   904
    # information
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   905
    if not verbose:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   906
        currentuser = ui.username(acceptempty=True)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   907
        if len(users) == 1 and currentuser in users:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   908
            users = None
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   909
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   910
    if (verbose or normal) and users:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   911
        line.append(b" by %s" % b", ".join(users))
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   912
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   913
    # Dates
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   914
    dates = obsutil.markersdates(markers)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   915
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   916
    if dates and verbose:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   917
        min_date = min(dates)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   918
        max_date = max(dates)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   919
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   920
        if min_date == max_date:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   921
            fmtmin_date = dateutil.datestr(min_date, b'%Y-%m-%d %H:%M %1%2')
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   922
            line.append(b" (at %s)" % fmtmin_date)
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   923
        else:
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   924
            fmtmin_date = dateutil.datestr(min_date, b'%Y-%m-%d %H:%M %1%2')
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   925
            fmtmax_date = dateutil.datestr(max_date, b'%Y-%m-%d %H:%M %1%2')
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   926
            line.append(b" (between %s and %s)" % (fmtmin_date, fmtmax_date))
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   927
0bc31f853862 templatekw: add obsorigin keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 5329
diff changeset
   928
    return b"".join(line)