hgext/evolve.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 20 Feb 2014 13:59:49 -0800
changeset 807 4dd1cda16fd0
parent 806 895fadf6ba3e
child 808 81a3d9a24e6b
permissions -rw-r--r--
evolve: add a debugobsstorestat command This commands print multiple some data about the content of the obsstore. This will be usefull to provide some metric and insight for obsolescence marker exchange.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     1
# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     2
#                Logilab SA        <contact@logilab.fr>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     3
#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
519
9825c7da5b54 ensure all file have a copyright notice
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 517
diff changeset
     4
#                Patrick Mezard <patrick@mezard.eu>
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     5
#
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     8
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
     9
'''Extends Mercurial feature related to Changeset Evolution
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    10
540
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    11
This extension provides several commands to mutate history and deal with
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    12
issues it may raise.
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    13
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    14
It also:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    15
540
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    16
    - enables the "Changeset Obsolescence" feature of mercurial,
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    17
    - alters core commands and extensions that rewrite history to use
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    18
      this feature,
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    19
    - improves some aspect of the early implementation in 2.3
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    20
'''
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    21
757
0ff862dcddbd evolve: update the tested with statement
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 756
diff changeset
    22
testedwith = '2.7 2.7.1 2.7.2 2.8 2.8.1'
584
af3b0d696e7f evolve: add tested with info
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 577
diff changeset
    23
buglink = 'https://bitbucket.org/marmoute/mutable-history/issues'
af3b0d696e7f evolve: add tested with info
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 577
diff changeset
    24
675
af9cc1e861a4 add an explicite warning when repo contains invalid obsolescence markers
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 674
diff changeset
    25
import sys
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
    26
import random
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
    27
670
97ce1f801309 evolve: drop unused import
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 663
diff changeset
    28
import mercurial
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    29
from mercurial import util
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    30
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    31
try:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    32
    from mercurial import obsolete
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    33
    if not obsolete._enabled:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    34
        obsolete._enabled = True
617
469befc27b26 detect incompatibility with future mercurial 2.5
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 616
diff changeset
    35
    from mercurial import bookmarks
469befc27b26 detect incompatibility with future mercurial 2.5
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 616
diff changeset
    36
    bookmarks.bmstore
591
012e48e80840 evolve: require Mercurial 2.4 to work
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 590
diff changeset
    37
except (ImportError, AttributeError):
647
a2b805bacdc0 evolve: fix version message
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 645
diff changeset
    38
    raise util.Abort('Your Mercurial is too old for this version of Evolve',
618
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 612 617
diff changeset
    39
                     hint='requires version >> 2.4.x')
617
469befc27b26 detect incompatibility with future mercurial 2.5
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 616
diff changeset
    40
585
f013ca072bd9 evolve: detect and abort if 2.4 is detected
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 584
diff changeset
    41
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    42
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    43
from mercurial import bookmarks
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    44
from mercurial import cmdutil
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    45
from mercurial import commands
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    46
from mercurial import context
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    47
from mercurial import copies
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    48
from mercurial import error
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    49
from mercurial import extensions
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    50
from mercurial import hg
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
    51
from mercurial import lock as lockmod
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    52
from mercurial import merge
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    53
from mercurial import node
113
3bdabdbb4140 adapt evolution to phase in core.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 108
diff changeset
    54
from mercurial import phases
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    55
from mercurial import revset
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    56
from mercurial import scmutil
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    57
from mercurial import templatekw
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    58
from mercurial.i18n import _
455
f46a41006136 obsolete: simplify rebase wrapping code and change relation creation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 446
diff changeset
    59
from mercurial.commands import walkopts, commitopts, commitopts2
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    60
from mercurial.node import nullid
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    61
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    62
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    63
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    64
# This extension contains the following code
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    65
#
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    66
# - Extension Helper code
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    67
# - Obsolescence cache
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    68
# - ...
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    69
# - Older format compat
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    70
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    71
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    72
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    73
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    74
### Extension helper                                              ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    75
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    76
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    77
class exthelper(object):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    78
    """Helper for modular extension setup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    79
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    80
    A single helper should be instanciated for each extension. Helper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    81
    methods are then used as decorator for various purpose.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    82
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    83
    All decorators return the original function and may be chained.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    84
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    85
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    86
    def __init__(self):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    87
        self._uicallables = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    88
        self._extcallables = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    89
        self._repocallables = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    90
        self._revsetsymbols = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    91
        self._templatekws = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    92
        self._commandwrappers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    93
        self._extcommandwrappers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    94
        self._functionwrappers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    95
        self._duckpunchers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    96
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    97
    def final_uisetup(self, ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    98
        """Method to be used as the extension uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    99
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   100
        The following operations belong here:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   101
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   102
        - Changes to ui.__class__ . The ui object that will be used to run the
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   103
          command has not yet been created. Changes made here will affect ui
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   104
          objects created after this, and in particular the ui that will be
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   105
          passed to runcommand
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   106
        - Command wraps (extensions.wrapcommand)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   107
        - Changes that need to be visible to other extensions: because
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   108
          initialization occurs in phases (all extensions run uisetup, then all
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   109
          run extsetup), a change made here will be visible to other extensions
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   110
          during extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   111
        - Monkeypatch or wrap function (extensions.wrapfunction) of dispatch
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   112
          module members
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   113
        - Setup of pre-* and post-* hooks
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   114
        - pushkey setup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   115
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   116
        for cont, funcname, func in self._duckpunchers:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   117
            setattr(cont, funcname, func)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   118
        for command, wrapper in self._commandwrappers:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   119
            extensions.wrapcommand(commands.table, command, wrapper)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   120
        for cont, funcname, wrapper in self._functionwrappers:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   121
            extensions.wrapfunction(cont, funcname, wrapper)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   122
        for c in self._uicallables:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   123
            c(ui)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   124
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   125
    def final_extsetup(self, ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   126
        """Method to be used as a the extension extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   127
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   128
        The following operations belong here:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   129
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   130
        - Changes depending on the status of other extensions. (if
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   131
          extensions.find('mq'))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   132
        - Add a global option to all commands
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   133
        - Register revset functions
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   134
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   135
        knownexts = {}
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   136
        for name, symbol in self._revsetsymbols:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   137
            revset.symbols[name] = symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   138
        for name, kw in self._templatekws:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   139
            templatekw.keywords[name] = kw
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   140
        for ext, command, wrapper in self._extcommandwrappers:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   141
            if ext not in knownexts:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   142
                e = extensions.find(ext)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   143
                if e is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   144
                    raise util.Abort('extension %s not found' % ext)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   145
                knownexts[ext] = e.cmdtable
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   146
            extensions.wrapcommand(knownexts[ext], commands, wrapper)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   147
        for c in self._extcallables:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   148
            c(ui)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   149
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   150
    def final_reposetup(self, ui, repo):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   151
        """Method to be used as a the extension reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   152
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   153
        The following operations belong here:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   154
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   155
        - All hooks but pre-* and post-*
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   156
        - Modify configuration variables
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   157
        - Changes to repo.__class__, repo.dirstate.__class__
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   158
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   159
        for c in self._repocallables:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   160
            c(ui, repo)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   161
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   162
    def uisetup(self, call):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   163
        """Decorated function will be executed during uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   164
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   165
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   166
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   167
            @eh.uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   168
            def setupbabar(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   169
                print 'this is uisetup!'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   170
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   171
        self._uicallables.append(call)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   172
        return call
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   173
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   174
    def extsetup(self, call):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   175
        """Decorated function will be executed during extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   176
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   177
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   178
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   179
            @eh.extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   180
            def setupcelestine(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   181
                print 'this is extsetup!'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   182
        """
672
f7834b360f8f evolve: fix extsetup extension helper
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 671
diff changeset
   183
        self._extcallables.append(call)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   184
        return call
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   185
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   186
    def reposetup(self, call):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   187
        """Decorated function will be executed during reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   188
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   189
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   190
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   191
            @eh.reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   192
            def setupzephir(ui, repo):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   193
                print 'this is reposetup!'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   194
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   195
        self._repocallables.append(call)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   196
        return call
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   197
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   198
    def revset(self, symbolname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   199
        """Decorated function is a revset symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   200
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   201
        The name of the symbol must be given as the decorator argument.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   202
        The symbol is added during `extsetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   203
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   204
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   205
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   206
            @eh.revset('hidden')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   207
            def revsetbabar(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   208
                args = revset.getargs(x, 0, 0, 'babar accept no argument')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   209
                return [r for r in subset if 'babar' in repo[r].description()]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   210
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   211
        def dec(symbol):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   212
            self._revsetsymbols.append((symbolname, symbol))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   213
            return symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   214
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   215
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   216
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   217
    def templatekw(self, keywordname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   218
        """Decorated function is a revset keyword
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   219
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   220
        The name of the keyword must be given as the decorator argument.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   221
        The symbol is added during `extsetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   222
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   223
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   224
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   225
            @eh.templatekw('babar')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   226
            def kwbabar(ctx):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   227
                return 'babar'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   228
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   229
        def dec(keyword):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   230
            self._templatekws.append((keywordname, keyword))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   231
            return keyword
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   232
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   233
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   234
    def wrapcommand(self, command, extension=None):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   235
        """Decorated function is a command wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   236
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   237
        The name of the command must be given as the decorator argument.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   238
        The wrapping is installed during `uisetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   239
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   240
        If the second option `extension` argument is provided, the wrapping
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   241
        will be applied in the extension commandtable. This argument must be a
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   242
        string that will be searched using `extension.find` if not found and
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   243
        Abort error is raised. If the wrapping applies to an extension, it is
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   244
        installed during `extsetup`
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   245
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   246
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   247
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   248
            @eh.wrapcommand('summary')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   249
            def wrapsummary(orig, ui, repo, *args, **kwargs):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   250
                ui.note('Barry!')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   251
                return orig(ui, repo, *args, **kwargs)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   252
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   253
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   254
        def dec(wrapper):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   255
            if extension is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   256
                self._commandwrappers.append((command, wrapper))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   257
            else:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   258
                self._extcommandwrappers.append((extension, command, wrapper))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   259
            return wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   260
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   261
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   262
    def wrapfunction(self, container, funcname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   263
        """Decorated function is a function wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   264
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   265
        This function takes two arguments, the container and the name of the
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   266
        function to wrap. The wrapping is performed during `uisetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   267
        (there is no extension support)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   268
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   269
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   270
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   271
            @eh.function(discovery, 'checkheads')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   272
            def wrapfunction(orig, *args, **kwargs):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   273
                ui.note('His head smashed in and his heart cut out')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   274
                return orig(*args, **kwargs)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   275
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   276
        def dec(wrapper):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   277
            self._functionwrappers.append((container, funcname, wrapper))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   278
            return wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   279
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   280
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   281
    def addattr(self, container, funcname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   282
        """Decorated function is to be added to the container
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   283
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   284
        This function takes two arguments, the container and the name of the
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   285
        function to wrap. The wrapping is performed during `uisetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   286
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   287
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   288
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   289
            @eh.function(context.changectx, 'babar')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   290
            def babar(ctx):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   291
                return 'babar' in ctx.description
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   292
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   293
        def dec(func):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   294
            self._duckpunchers.append((container, funcname, func))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   295
            return func
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   296
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   297
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   298
eh = exthelper()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   299
uisetup = eh.final_uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   300
extsetup = eh.final_extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   301
reposetup = eh.final_reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   302
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   303
#####################################################################
805
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   304
### experimental behavior                                         ###
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   305
#####################################################################
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   306
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   307
@eh.wrapfunction(mercurial.obsolete, 'createmarkers')
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   308
def _createmarkers(orig, repo, relations, *args, **kwargs):
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   309
    """register parent information at prune time"""
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   310
    # every time this test is run, a kitten is slain.
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   311
    # Change it as soon as possible
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   312
    if '[,{metadata}]' in orig.__doc__:
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   313
        for idx, rel in enumerate(relations):
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   314
            prec = rel[0]
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   315
            sucs = rel[1]
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   316
            if not sucs:
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   317
                meta = {}
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   318
                if 2 < len(rel):
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   319
                    meta.update(rel[2])
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   320
                for i, p in enumerate(prec.parents(), 1):
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   321
                    meta['p%i' % i] = p.hex()
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   322
                relations[idx] = (prec, sucs, meta)
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   323
    return orig(repo, relations, *args, **kwargs)
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   324
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   325
def createmarkers(*args, **kwargs):
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   326
    return obsolete.createmarkers(*args, **kwargs)
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   327
806
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   328
class pruneobsstore(obsolete.obsstore):
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   329
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   330
    def __init__(self, *args, **kwargs):
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   331
        self.prunedchildren = {}
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   332
        return super(pruneobsstore, self).__init__(*args, **kwargs)
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   333
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   334
    def _load(self, markers):
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   335
        markers = self._prunedetectingmarkers(markers)
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   336
        return super(pruneobsstore, self)._load(markers)
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   337
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   338
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   339
    def _prunedetectingmarkers(self, markers):
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   340
        for m in markers:
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   341
            if not m[1]: # no successors
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   342
                meta = obsolete.decodemeta(m[3])
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   343
                if 'p1' in meta:
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   344
                    p1 = node.bin(meta['p1'])
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   345
                    self.prunedchildren.setdefault(p1, set()).add(m)
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   346
                if 'p2' in meta:
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   347
                    p1 = node.bin(meta['p2'])
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   348
                    self.prunedchildren.setdefault(p2, set()).add(m)
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   349
            yield m
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   350
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   351
obsolete.obsstore = pruneobsstore
895fadf6ba3e evolve: extend obsstore object to use prune parent information
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 805
diff changeset
   352
805
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   353
#####################################################################
577
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   354
### Critical fix                                                  ###
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   355
#####################################################################
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   356
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   357
@eh.wrapfunction(mercurial.obsolete, '_readmarkers')
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   358
def safereadmarkers(orig, data):
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   359
    """safe maker wrapper to remove nullid succesors
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   360
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   361
    Nullid successors was created by older version of evolve.
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   362
    """
675
af9cc1e861a4 add an explicite warning when repo contains invalid obsolescence markers
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 674
diff changeset
   363
    nb = 0
577
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   364
    for marker in orig(data):
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   365
        if nullid in marker[1]:
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   366
            marker = (marker[0],
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   367
                      tuple(s for s in marker[1] if s != nullid),
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   368
                      marker[2],
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   369
                      marker[3])
675
af9cc1e861a4 add an explicite warning when repo contains invalid obsolescence markers
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 674
diff changeset
   370
            nb += 1
577
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   371
        yield marker
675
af9cc1e861a4 add an explicite warning when repo contains invalid obsolescence markers
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 674
diff changeset
   372
    if nb:
af9cc1e861a4 add an explicite warning when repo contains invalid obsolescence markers
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 674
diff changeset
   373
        e = sys.stderr
af9cc1e861a4 add an explicite warning when repo contains invalid obsolescence markers
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 674
diff changeset
   374
        print >> e, 'repo contains %i invalid obsolescence markers' % nb
577
2cd2ee20d9fa evolve: filter nullid successors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 576
diff changeset
   375
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   376
getrevs = obsolete.getrevs
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   377
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   378
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   379
### Additional Utilities                                          ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   380
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   381
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   382
# This section contains a lot of small utility function and method
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   383
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   384
# - Function to create markers
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   385
# - useful alias pstatus and pdiff (should probably go in evolve)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   386
# - "troubles" method on changectx
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   387
# - function to travel throught the obsolescence graph
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   388
# - function to find useful changeset to stabilize
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   389
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   390
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   391
### Useful alias
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   392
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   393
@eh.uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   394
def _installalias(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   395
    if ui.config('alias', 'pstatus', None) is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   396
        ui.setconfig('alias', 'pstatus', 'status --rev .^')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   397
    if ui.config('alias', 'pdiff', None) is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   398
        ui.setconfig('alias', 'pdiff', 'diff --rev .^')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   399
    if ui.config('alias', 'olog', None) is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   400
        ui.setconfig('alias', 'olog', "log -r 'precursors(.)' --hidden")
497
43e1b2cab789 evolve: add the odiff alias
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 492
diff changeset
   401
    if ui.config('alias', 'odiff', None) is None:
625
e291e5271694 prepare for Full scale filtering !!!
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 622
diff changeset
   402
        ui.setconfig('alias', 'odiff', "diff --hidden --rev 'limit(precursors(.),1)' --rev .")
696
121e2d265e85 alias: add a grab alias
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 695
diff changeset
   403
    if ui.config('alias', 'grab', None) is None:
752
bfdfdf731f8a grab: update the alias for 2.8 compatibility
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 751
diff changeset
   404
        ui.setconfig('alias', 'grab', "! $HG rebase --dest . --rev $@ && $HG up tip")
696
121e2d265e85 alias: add a grab alias
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 695
diff changeset
   405
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   406
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   407
### Troubled revset symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   408
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   409
@eh.revset('troubled')
594
7f89b31fcb26 merge bumped rename
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 592 593
diff changeset
   410
def revsettroubled(repo, subset, x):
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   411
    """``troubled()``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   412
    Changesets with troubles.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   413
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   414
    _ = revset.getargs(x, 0, 0, 'troubled takes no arguments')
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   415
    return repo.revs('%ld and (unstable() + bumped() + divergent())',
511
ddeb71df916d evolve: localrepo.revs() already returns a list
Patrick Mezard <patrick@mezard.eu>
parents: 510
diff changeset
   416
                     subset)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   417
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   418
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   419
### Obsolescence graph
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   420
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   421
# XXX SOME MAJOR CLEAN UP TO DO HERE XXX
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   422
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   423
def _precursors(repo, s):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   424
    """Precursor of a changeset"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   425
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   426
    nm = repo.changelog.nodemap
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   427
    markerbysubj = repo.obsstore.precursors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   428
    for r in s:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   429
        for p in markerbysubj.get(repo[r].node(), ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   430
            pr = nm.get(p[0])
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   431
            if pr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   432
                cs.add(pr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   433
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   434
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   435
def _allprecursors(repo, s):  # XXX we need a better naming
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   436
    """transitive precursors of a subset"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   437
    toproceed = [repo[r].node() for r in s]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   438
    seen = set()
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   439
    allsubjects = repo.obsstore.precursors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   440
    while toproceed:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   441
        nc = toproceed.pop()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   442
        for mark in allsubjects.get(nc, ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   443
            np = mark[0]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   444
            if np not in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   445
                seen.add(np)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   446
                toproceed.append(np)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   447
    nm = repo.changelog.nodemap
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   448
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   449
    for p in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   450
        pr = nm.get(p)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   451
        if pr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   452
            cs.add(pr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   453
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   454
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   455
def _successors(repo, s):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   456
    """Successors of a changeset"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   457
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   458
    nm = repo.changelog.nodemap
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   459
    markerbyobj = repo.obsstore.successors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   460
    for r in s:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   461
        for p in markerbyobj.get(repo[r].node(), ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   462
            for sub in p[1]:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   463
                sr = nm.get(sub)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   464
                if sr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   465
                    cs.add(sr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   466
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   467
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   468
def _allsuccessors(repo, s, haltonflags=0):  # XXX we need a better naming
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   469
    """transitive successors of a subset
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   470
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   471
    haltonflags allows to provide flags which prevent the evaluation of a
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   472
    marker.  """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   473
    toproceed = [repo[r].node() for r in s]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   474
    seen = set()
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   475
    allobjects = repo.obsstore.successors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   476
    while toproceed:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   477
        nc = toproceed.pop()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   478
        for mark in allobjects.get(nc, ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   479
            if mark[2] & haltonflags:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   480
                continue
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   481
            for sub in mark[1]:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   482
                if sub == nullid:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   483
                    continue # should not be here!
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   484
                if sub not in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   485
                    seen.add(sub)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   486
                    toproceed.append(sub)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   487
    nm = repo.changelog.nodemap
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   488
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   489
    for s in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   490
        sr = nm.get(s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   491
        if sr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   492
            cs.add(sr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   493
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   494
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   495
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   496
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   497
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   498
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   499
### Extending revset and template                                 ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   500
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   501
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   502
# this section add several useful revset symbol not yet in core.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   503
# they are subject to changes
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   504
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   505
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   506
### XXX I'm not sure this revset is useful
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   507
@eh.revset('suspended')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   508
def revsetsuspended(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   509
    """``suspended()``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   510
    Obsolete changesets with non-obsolete descendants.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   511
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   512
    args = revset.getargs(x, 0, 0, 'suspended takes no arguments')
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   513
    suspended = getrevs(repo, 'suspended')
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   514
    return [r for r in subset if r in suspended]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   515
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   516
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   517
@eh.revset('precursors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   518
def revsetprecursors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   519
    """``precursors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   520
    Immediate precursors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   521
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   522
    s = revset.getset(repo, range(len(repo)), x)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   523
    cs = _precursors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   524
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   525
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   526
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   527
@eh.revset('allprecursors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   528
def revsetallprecursors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   529
    """``allprecursors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   530
    Transitive precursors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   531
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   532
    s = revset.getset(repo, range(len(repo)), x)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   533
    cs = _allprecursors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   534
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   535
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   536
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   537
@eh.revset('successors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   538
def revsetsuccessors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   539
    """``successors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   540
    Immediate successors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   541
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   542
    s = revset.getset(repo, range(len(repo)), x)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   543
    cs = _successors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   544
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   545
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   546
@eh.revset('allsuccessors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   547
def revsetallsuccessors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   548
    """``allsuccessors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   549
    Transitive successors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   550
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   551
    s = revset.getset(repo, range(len(repo)), x)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   552
    cs = _allsuccessors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   553
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   554
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   555
### template keywords
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   556
# XXX it does not handle troubles well :-/
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   557
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   558
@eh.templatekw('obsolete')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   559
def obsoletekw(repo, ctx, templ, **args):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   560
    """:obsolete: String. The obsolescence level of the node, could be
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   561
    ``stable``, ``unstable``, ``suspended`` or ``extinct``.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   562
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   563
    rev = ctx.rev()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   564
    if ctx.obsolete():
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   565
        if ctx.extinct():
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   566
            return 'extinct'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   567
        else:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   568
            return 'suspended'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   569
    elif ctx.unstable():
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   570
        return 'unstable'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   571
    return 'stable'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   572
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   573
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   574
### Various trouble warning                                       ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   575
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   576
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   577
# This section take care of issue warning to the user when troubles appear
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   578
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   579
@eh.wrapcommand("update")
745
99e51aff724b add obsolete parents wrapper to the 'parents' command
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
   580
@eh.wrapcommand("parents")
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   581
@eh.wrapcommand("pull")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   582
def wrapmayobsoletewc(origfn, ui, repo, *args, **opts):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   583
    """Warn that the working directory parent is an obsolete changeset"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   584
    res = origfn(ui, repo, *args, **opts)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   585
    if repo['.'].obsolete():
743
af74a5cdf96b conform to the Mercurial custom of lowercase messages
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 742
diff changeset
   586
        ui.warn(_('working directory parent is obsolete!\n'))
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   587
    return res
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   588
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   589
# XXX this could wrap transaction code
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   590
# XXX (but this is a bit a layer violation)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   591
@eh.wrapcommand("commit")
763
966e2659e989 import: warn about new unstable changesets
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 762
diff changeset
   592
@eh.wrapcommand("import")
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   593
@eh.wrapcommand("push")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   594
@eh.wrapcommand("pull")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   595
@eh.wrapcommand("graft")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   596
@eh.wrapcommand("phase")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   597
@eh.wrapcommand("unbundle")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   598
def warnobserrors(orig, ui, repo, *args, **kwargs):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   599
    """display warning is the command resulted in more instable changeset"""
658
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   600
    # part of the troubled stuff may be filtered (stash ?)
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   601
    # This needs a better implementation but will probably wait for core.
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   602
    filtered = repo.changelog.filteredrevs
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   603
    priorunstables = len(set(getrevs(repo, 'unstable')) - filtered)
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   604
    priorbumpeds = len(set(getrevs(repo, 'bumped')) - filtered)
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   605
    priordivergents = len(set(getrevs(repo, 'divergent')) - filtered)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   606
    ret = orig(ui, repo, *args, **kwargs)
552
f7e54d4a3b90 warning: work around phase limitation when computing warnings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 551
diff changeset
   607
    # workaround phase stupidity
649
d318fbb1cd67 evolve: stop working around phase limitation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 647
diff changeset
   608
    #phases._filterunknown(ui, repo.changelog, repo._phasecache.phaseroots)
658
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   609
    filtered = repo.changelog.filteredrevs
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   610
    newunstables = len(set(getrevs(repo, 'unstable')) - filtered) - priorunstables
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   611
    newbumpeds = len(set(getrevs(repo, 'bumped')) - filtered) - priorbumpeds
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   612
    newdivergents = len(set(getrevs(repo, 'divergent')) - filtered) - priordivergents
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   613
    if newunstables > 0:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   614
        ui.warn(_('%i new unstable changesets\n') % newunstables)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   615
    if newbumpeds > 0:
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   616
        ui.warn(_('%i new bumped changesets\n') % newbumpeds)
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
   617
    if newdivergents > 0:
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
   618
        ui.warn(_('%i new divergent changesets\n') % newdivergents)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   619
    return ret
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   620
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   621
@eh.reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   622
def _repostabilizesetup(ui, repo):
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   623
    """Add a hint for "hg evolve" when troubles make push fails
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   624
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   625
    if not repo.local():
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   626
        return
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   627
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   628
    class evolvingrepo(repo.__class__):
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   629
        def push(self, remote, *args, **opts):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   630
            """wrapper around pull that pull obsolete relation"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   631
            try:
756
64c6bdfd0518 evolve: use super for calling parent class method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 752
diff changeset
   632
                result = super(evolvingrepo, self).push(remote, *args, **opts)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   633
            except util.Abort, ex:
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   634
                hint = _("use 'hg evolve' to get a stable history "
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   635
                         "or --force to ignore warnings")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   636
                if (len(ex.args) >= 1
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   637
                    and ex.args[0].startswith('push includes ')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   638
                    and ex.hint is None):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   639
                    ex.hint = hint
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   640
                raise
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   641
            return result
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   642
    repo.__class__ = evolvingrepo
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   643
788
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   644
def summaryhook(ui, repo):
513
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   645
    def write(fmt, count):
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   646
        s = fmt % count
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   647
        if count:
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   648
            ui.write(s)
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   649
        else:
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   650
            ui.note(s)
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   651
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   652
    nbunstable = len(getrevs(repo, 'unstable'))
594
7f89b31fcb26 merge bumped rename
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 592 593
diff changeset
   653
    nbbumped = len(getrevs(repo, 'bumped'))
626
896463193675 merge with fix in 2.3
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 621 623
diff changeset
   654
    nbdivergent = len(getrevs(repo, 'divergent'))
513
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   655
    write('unstable: %i changesets\n', nbunstable)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   656
    write('bumped: %i changesets\n', nbbumped)
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
   657
    write('divergent: %i changesets\n', nbdivergent)
788
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   658
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   659
@eh.extsetup
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   660
def obssummarysetup(ui):
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   661
    cmdutil.summaryhooks.add('evolve', summaryhook)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   662
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   663
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   664
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   665
### Core Other extension compat                                   ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   666
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   667
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   668
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   669
@eh.extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   670
def _rebasewrapping(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   671
    # warning about more obsolete
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   672
    try:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   673
        rebase = extensions.find('rebase')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   674
        if rebase:
572
dc107acd0bd2 adapt to core rebase support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 571
diff changeset
   675
            extensions.wrapcommand(rebase.cmdtable, 'rebase', warnobserrors)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   676
    except KeyError:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   677
        pass  # rebase not found
678
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   678
    try:
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   679
        histedit = extensions.find('histedit')
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   680
        if histedit:
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   681
            extensions.wrapcommand(histedit.cmdtable, 'histedit', warnobserrors)
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   682
    except KeyError:
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   683
        pass  # rebase not found
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   684
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   685
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   686
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   687
### Old Evolve extension content                                  ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   688
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   689
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   690
# XXX need clean up and proper sorting in other section
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   691
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   692
### util function
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   693
#############################
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   694
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   695
### changeset rewriting logic
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   696
#############################
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   697
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   698
def rewrite(repo, old, updates, head, newbases, commitopts):
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   699
    """Return (nodeid, created) where nodeid is the identifier of the
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   700
    changeset generated by the rewrite process, and created is True if
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   701
    nodeid was actually created. If created is False, nodeid
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   702
    references a changeset existing before the rewrite call.
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   703
    """
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   704
    if len(old.parents()) > 1: #XXX remove this unecessary limitation.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   705
        raise error.Abort(_('cannot amend merge changesets'))
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   706
    base = old.p1()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   707
    updatebookmarks = _bookmarksupdater(repo, old.node())
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   708
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   709
    wlock = repo.wlock()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   710
    try:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   711
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   712
        # commit a new version of the old changeset, including the update
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   713
        # collect all files which might be affected
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   714
        files = set(old.files())
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   715
        for u in updates:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   716
            files.update(u.files())
219
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   717
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   718
        # Recompute copies (avoid recording a -> b -> a)
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   719
        copied = copies.pathcopies(base, head)
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   720
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   721
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   722
        # prune files which were reverted by the updates
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   723
        def samefile(f):
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   724
            if f in head.manifest():
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   725
                a = head.filectx(f)
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   726
                if f in base.manifest():
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   727
                    b = base.filectx(f)
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   728
                    return (a.data() == b.data()
219
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   729
                            and a.flags() == b.flags())
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   730
                else:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   731
                    return False
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   732
            else:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   733
                return f not in base.manifest()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   734
        files = [f for f in files if not samefile(f)]
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   735
        # commit version of these files as defined by head
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   736
        headmf = head.manifest()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   737
        def filectxfn(repo, ctx, path):
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   738
            if path in headmf:
219
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   739
                fctx = head[path]
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   740
                flags = fctx.flags()
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   741
                mctx = context.memfilectx(fctx.path(), fctx.data(),
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   742
                                          islink='l' in flags,
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   743
                                          isexec='x' in flags,
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   744
                                          copied=copied.get(path))
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
   745
                return mctx
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   746
            raise IOError()
104
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   747
        if commitopts.get('message') and commitopts.get('logfile'):
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   748
            raise util.Abort(_('options --message and --logfile are mutually'
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   749
                               ' exclusive'))
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   750
        if commitopts.get('logfile'):
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   751
            message= open(commitopts['logfile']).read()
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   752
        elif commitopts.get('message'):
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   753
            message = commitopts['message']
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   754
        else:
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   755
            message = old.description()
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   756
142
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
   757
        user = commitopts.get('user') or old.user()
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
   758
        date = commitopts.get('date') or None # old.date()
263
de62daaf2054 amend: drop --branches, pick it from working directory
Patrick Mezard <patrick@mezard.eu>
parents: 260
diff changeset
   759
        extra = dict(commitopts.get('extra', {}))
de62daaf2054 amend: drop --branches, pick it from working directory
Patrick Mezard <patrick@mezard.eu>
parents: 260
diff changeset
   760
        extra['branch'] = head.branch()
118
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   761
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   762
        new = context.memctx(repo,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   763
                             parents=newbases,
104
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   764
                             text=message,
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   765
                             files=files,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   766
                             filectxfn=filectxfn,
142
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
   767
                             user=user,
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
   768
                             date=date,
263
de62daaf2054 amend: drop --branches, pick it from working directory
Patrick Mezard <patrick@mezard.eu>
parents: 260
diff changeset
   769
                             extra=extra)
118
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   770
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   771
        if commitopts.get('edit'):
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   772
            new._text = cmdutil.commitforceeditor(repo, new, [])
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   773
        revcount = len(repo)
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   774
        newid = repo.commitctx(new)
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   775
        new = repo[newid]
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   776
        created = len(repo) != revcount
699
dba3ed9f2c4f amend: prune replacement commit without sucessors
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 696
diff changeset
   777
        updatebookmarks(newid)
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   778
    finally:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   779
        wlock.release()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   780
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   781
    return newid, created
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   782
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   783
class MergeFailure(util.Abort):
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   784
    pass
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   785
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   786
def relocate(repo, orig, dest):
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   787
    """rewrite <rev> on dest"""
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   788
    try:
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   789
        rebase = extensions.find('rebase')
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   790
        # dummy state to trick rebase node
776
7eaad1101242 raise util.Abort instead of assertion when trying to evolve a merge changeset.
Arne Babenhauserheide <arne.babenhauserheide@kit.edu>
parents: 763
diff changeset
   791
        if not orig.p2().rev() == node.nullrev:
7eaad1101242 raise util.Abort instead of assertion when trying to evolve a merge changeset.
Arne Babenhauserheide <arne.babenhauserheide@kit.edu>
parents: 763
diff changeset
   792
            raise util.Abort(
7eaad1101242 raise util.Abort instead of assertion when trying to evolve a merge changeset.
Arne Babenhauserheide <arne.babenhauserheide@kit.edu>
parents: 763
diff changeset
   793
                'no support for evolution merge changesets yet',
7eaad1101242 raise util.Abort instead of assertion when trying to evolve a merge changeset.
Arne Babenhauserheide <arne.babenhauserheide@kit.edu>
parents: 763
diff changeset
   794
                hint="Redo the merge a use `hg prune` to obsolete the old one")
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   795
        destbookmarks = repo.nodebookmarks(dest.node())
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   796
        cmdutil.duplicatecopies(repo, orig.node(), dest.node())
258
8337bb3bb958 Fix amend and relocate who picked phases data after extinct wher made secret
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 255
diff changeset
   797
        nodesrc = orig.node()
8337bb3bb958 Fix amend and relocate who picked phases data after extinct wher made secret
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 255
diff changeset
   798
        destphase = repo[nodesrc].phase()
326
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   799
        try:
674
b3ce838a077e evolve: remove pre 2.3 code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 673
diff changeset
   800
            r = rebase.rebasenode(repo, orig.node(), dest.node(),
b3ce838a077e evolve: remove pre 2.3 code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 673
diff changeset
   801
                                  {node.nullrev: node.nullrev}, False)
550
362e65fc6146 evolve-cmd: fix merge error detection for external tools.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 549
diff changeset
   802
            if r[-1]: #some conflict
362e65fc6146 evolve-cmd: fix merge error detection for external tools.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 549
diff changeset
   803
                raise util.Abort(
362e65fc6146 evolve-cmd: fix merge error detection for external tools.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 549
diff changeset
   804
                        'unresolved merge conflicts (see hg help resolve)')
326
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   805
            nodenew = rebase.concludenode(repo, orig.node(), dest.node(),
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   806
                                          node.nullid)
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   807
        except util.Abort, exc:
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   808
            class LocalMergeFailure(MergeFailure, exc.__class__):
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   809
                pass
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   810
            exc.__class__ = LocalMergeFailure
326
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   811
            raise
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   812
        oldbookmarks = repo.nodebookmarks(nodesrc)
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   813
        if nodenew is not None:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   814
            phases.retractboundary(repo, destphase, [nodenew])
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   815
            createmarkers(repo, [(repo[nodesrc], (repo[nodenew],))])
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   816
            for book in oldbookmarks:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   817
                repo._bookmarks[book] = nodenew
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   818
        else:
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   819
            createmarkers(repo, [(repo[nodesrc], ())])
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   820
            # Behave like rebase, move bookmarks to dest
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   821
            for book in oldbookmarks:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   822
                repo._bookmarks[book] = dest.node()
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   823
        for book in destbookmarks: # restore bookmark that rebase move
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   824
            repo._bookmarks[book] = dest.node()
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   825
        if oldbookmarks or destbookmarks:
612
15299bfd0813 adapt to 7f5dab94e48c in crew
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 604
diff changeset
   826
            repo._bookmarks.write()
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   827
        return nodenew
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   828
    except util.Abort:
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   829
        # Invalidate the previous setparents
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   830
        repo.dirstate.invalidate()
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   831
        raise
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   832
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   833
def _bookmarksupdater(repo, oldid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   834
    """Return a callable update(newid) updating the current bookmark
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   835
    and bookmarks bound to oldid to newid.
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   836
    """
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   837
    bm = bookmarks.readcurrent(repo)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   838
    def updatebookmarks(newid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   839
        dirty = False
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   840
        if bm:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   841
            repo._bookmarks[bm] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   842
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   843
        oldbookmarks = repo.nodebookmarks(oldid)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   844
        if oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   845
            for b in oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   846
                repo._bookmarks[b] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   847
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   848
        if dirty:
612
15299bfd0813 adapt to 7f5dab94e48c in crew
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 604
diff changeset
   849
            repo._bookmarks.write()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   850
    return updatebookmarks
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   851
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   852
### new command
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   853
#############################
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   854
cmdtable = {}
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   855
command = cmdutil.command(cmdtable)
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   856
metadataopts = [
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   857
    ('d', 'date', '',
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   858
     _('record the specified date in metadata'), _('DATE')),
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   859
    ('u', 'user', '',
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   860
     _('record the specified user in metadata'), _('USER')),
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   861
]
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   862
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   863
@command('debugobsstorestat', [], '')
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   864
def cmddebugobsstorestat(ui, repo):
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   865
    """print statistic about obsolescence markers in the repo"""
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   866
    store = repo.obsstore
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   867
    unfi = repo.unfiltered()
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   868
    nm = unfi.changelog.nodemap
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   869
    ui.write('markers total:              %9i\n' % len(store._all))
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   870
    sucscount = [0, 0 , 0, 0]
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   871
    known = 0
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   872
    metatotallenght = 0
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   873
    metakeys = {}
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   874
    for mark in store:
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   875
        if mark[0] in nm:
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   876
            known += 1
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   877
        nbsucs = len(mark[1])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   878
        sucscount[min(nbsucs, 3)] += 1
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   879
        metatotallenght += len(mark[3])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   880
        meta = obsolete.decodemeta(mark[3])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   881
        for key in meta:
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   882
            metakeys.setdefault(key, 0)
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   883
            metakeys[key] += 1
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   884
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   885
    ui.write('    for known precursors:   %9i\n' % known)
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   886
    # successors data
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   887
    ui.write('markers with no successors: %9i\n' % sucscount[0])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   888
    ui.write('              1 successors: %9i\n' % sucscount[1])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   889
    ui.write('              2 successors: %9i\n' % sucscount[2])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   890
    ui.write('    more than 2 successors: %9i\n' % sucscount[3])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   891
    # meta data info
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   892
    ui.write('average meta length:        %9i\n'
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   893
             % (metatotallenght/len(store._all)))
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   894
    ui.write('    available  keys:\n')
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   895
    for key in sorted(metakeys):
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   896
        ui.write('    %15s:        %9i\n' % (key, metakeys[key]))
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
   897
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   898
714
3867f7b1fe6e evolve: remove duplicate alias.
Levi Bard <levi@unity3d.com>
parents: 710
diff changeset
   899
@command('^evolve|stabilize|solve',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   900
    [('n', 'dry-run', False, 'do not perform actions, print what to be done'),
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   901
    ('A', 'any', False, 'evolve any troubled changeset'),
704
2ec7c3673679 evolve: add --all argument.
Levi Bard <levi@unity3d.com>
parents: 703
diff changeset
   902
    ('a', 'all', False, 'evolve all troubled changesets'),
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   903
    ('c', 'continue', False, 'continue an interrupted evolution'), ],
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   904
    _('[OPTIONS]...'))
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   905
def evolve(ui, repo, **opts):
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   906
    """Solve trouble in your repository
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   907
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   908
    - rebase unstable changeset to make it stable again,
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   909
    - create proper diff from bumped changeset,
708
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
   910
    - merge divergent changesets.
750
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   911
    - update to a successor if the working directory parent is
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   912
      obsolete
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   913
708
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
   914
    By default, take the first trouble changeset that looks relevant.
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   915
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   916
    (The logic is still a bit fuzzy)
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   917
708
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
   918
    - For unstable, this means taking the first which could be rebased as a
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
   919
      child of the working directory parent revision or one of its descendants
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
   920
      and rebasing it.
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   921
708
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
   922
    - For divergent, this means taking "." if applicable.
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   923
708
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
   924
    With --any, evolve picks any troubled changeset to solve.
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   925
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   926
    The working directory is updated to the newly created revision.
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   927
    """
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   928
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   929
    contopt = opts['continue']
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   930
    anyopt = opts['any']
704
2ec7c3673679 evolve: add --all argument.
Levi Bard <levi@unity3d.com>
parents: 703
diff changeset
   931
    allopt = opts['all']
703
a246b02499d9 evolve: extract evolve --any implementation into a function.
Levi Bard <levi@unity3d.com>
parents: 663
diff changeset
   932
    dryrunopt = opts['dry_run']
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   933
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   934
    if contopt:
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   935
        if anyopt:
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   936
            raise util.Abort('can not specify both "--any" and "--continue"')
704
2ec7c3673679 evolve: add --all argument.
Levi Bard <levi@unity3d.com>
parents: 703
diff changeset
   937
        if allopt:
2ec7c3673679 evolve: add --all argument.
Levi Bard <levi@unity3d.com>
parents: 703
diff changeset
   938
            raise util.Abort('can not specify both "--all" and "--continue"')
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   939
        graftcmd = commands.table['graft'][0]
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   940
        return graftcmd(ui, repo, old_obsolete=True, **{'continue': True})
703
a246b02499d9 evolve: extract evolve --any implementation into a function.
Levi Bard <levi@unity3d.com>
parents: 663
diff changeset
   941
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
   942
    tr = _picknexttroubled(ui, repo, anyopt or allopt)
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   943
    if tr is None:
750
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   944
        if repo['.'].obsolete():
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   945
            displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   946
            successors = set()
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   947
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   948
            for successorsset in obsolete.successorssets(repo, repo['.'].node()):
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   949
                for nodeid in successorsset:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   950
                    successors.add(repo[nodeid])
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   951
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   952
            if not successors:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   953
                ui.warn(_('parent is obsolete without successors; ' +
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   954
                          'likely killed\n'))
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   955
                return 2
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   956
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   957
            elif len(successors) > 1:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   958
                ui.warn(_('parent is obsolete with multiple successors:\n'))
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   959
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   960
                for ctx in sorted(successors, key=lambda ctx: ctx.rev()):
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   961
                    displayer.show(ctx)
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   962
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   963
                return 2
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   964
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   965
            else:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   966
                ctx = successors.pop()
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   967
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   968
                ui.status(_('update:'))
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   969
                if not ui.quiet:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   970
                    displayer.show(ctx)
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   971
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   972
                if dryrunopt:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   973
                    print 'hg update %s' % ctx.rev()
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   974
                    return 0
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   975
                else:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   976
                    return hg.update(repo, ctx.rev())
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
   977
511
ddeb71df916d evolve: localrepo.revs() already returns a list
Patrick Mezard <patrick@mezard.eu>
parents: 510
diff changeset
   978
        troubled = repo.revs('troubled()')
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   979
        if troubled:
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   980
            ui.write_err(_('nothing to evolve here\n'))
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   981
            ui.status(_('(%i troubled changesets, do you want --any ?)\n')
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   982
                      % len(troubled))
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   983
            return 2
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   984
        else:
722
4e7e7a7d8500 evolve: remove trailing spaces
AndréSintzoff <andre.sintzoff@gmail.com>
parents: 716
diff changeset
   985
            ui.write_err(_('no troubled changesets\n'))
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   986
            return 1
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
   987
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   988
    def progresscb():
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   989
        if allopt:
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   990
            ui.progress('evolve', seen, unit='changesets', total=count)
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   991
    seen = 1
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   992
    count = allopt and _counttroubled(ui, repo) or 1
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   993
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
   994
    while tr is not None:
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   995
        progresscb()
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   996
        result = _evolveany(ui, repo, tr, dryrunopt, progresscb=progresscb)
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   997
        progresscb()
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
   998
        seen += 1
707
f914e315b717 evolve: remove magic return values from utility functions
Levi Bard <levi@unity3d.com>
parents: 706
diff changeset
   999
        if not allopt:
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
  1000
            return result
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1001
        progresscb()
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
  1002
        tr = _picknexttroubled(ui, repo, anyopt or allopt)
722
4e7e7a7d8500 evolve: remove trailing spaces
AndréSintzoff <andre.sintzoff@gmail.com>
parents: 716
diff changeset
  1003
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1004
    if allopt:
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1005
        ui.progress('evolve', None)
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
  1006
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1007
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1008
def _evolveany(ui, repo, tr, dryrunopt, progresscb):
651
609faf10d307 evolve: ensure evolve command run unfiltered
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 649
diff changeset
  1009
    repo = repo.unfiltered()
609faf10d307 evolve: ensure evolve command run unfiltered
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 649
diff changeset
  1010
    tr = repo[tr.rev()]
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1011
    cmdutil.bailifchanged(repo)
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1012
    troubles = tr.troubles()
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1013
    if 'unstable' in troubles:
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1014
        return _solveunstable(ui, repo, tr, dryrunopt, progresscb)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1015
    elif 'bumped' in troubles:
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1016
        return _solvebumped(ui, repo, tr, dryrunopt, progresscb)
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1017
    elif 'divergent' in troubles:
625
e291e5271694 prepare for Full scale filtering !!!
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 622
diff changeset
  1018
        repo = repo.unfiltered()
e291e5271694 prepare for Full scale filtering !!!
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 622
diff changeset
  1019
        tr = repo[tr.rev()]
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1020
        return _solvedivergent(ui, repo, tr, dryrunopt, progresscb)
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1021
    else:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1022
        assert False  # WHAT? unknown troubles
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
  1023
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1024
def _counttroubled(ui, repo):
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1025
    """Count the amount of troubled changesets"""
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1026
    troubled = set()
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1027
    troubled.update(getrevs(repo, 'unstable'))
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1028
    troubled.update(getrevs(repo, 'bumped'))
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1029
    troubled.update(getrevs(repo, 'divergent'))
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1030
    return len(troubled)
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1031
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1032
def _picknexttroubled(ui, repo, pickany=False, progresscb=None):
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1033
    """Pick a the next trouble changeset to solve"""
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1034
    if progresscb: progresscb()
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1035
    tr = _stabilizableunstable(repo, repo['.'])
484
20e2f2dd71f1 stabilize: conflicting changeset are considered if "."
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 482
diff changeset
  1036
    if tr is None:
20e2f2dd71f1 stabilize: conflicting changeset are considered if "."
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 482
diff changeset
  1037
        wdp = repo['.']
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1038
        if 'divergent' in wdp.troubles():
484
20e2f2dd71f1 stabilize: conflicting changeset are considered if "."
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 482
diff changeset
  1039
            tr = wdp
512
8b25e9cf76fd evolve: avoid 'any' argument name in _picknexttroubled()
Patrick Mezard <patrick@mezard.eu>
parents: 511
diff changeset
  1040
    if tr is None and pickany:
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1041
        troubled = list(repo.set('unstable()'))
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1042
        if not troubled:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1043
            troubled = list(repo.set('bumped()'))
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1044
        if not troubled:
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1045
            troubled = list(repo.set('divergent()'))
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1046
        if troubled:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1047
            tr = troubled[0]
484
20e2f2dd71f1 stabilize: conflicting changeset are considered if "."
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 482
diff changeset
  1048
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1049
    return tr
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1050
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1051
def _stabilizableunstable(repo, pctx):
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1052
    """Return a changectx for an unstable changeset which can be
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1053
    stabilized on top of pctx or one of its descendants. None if none
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1054
    can be found.
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1055
    """
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1056
    def selfanddescendants(repo, pctx):
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1057
        yield pctx
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1058
        for prec in repo.set('allprecursors(%d)', pctx):
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1059
            yield prec
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1060
        for ctx in pctx.descendants():
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1061
            yield ctx
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1062
            for prec in repo.set('allprecursors(%d)', ctx):
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1063
                yield prec
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1064
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1065
    # Look for an unstable which can be stabilized as a child of
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1066
    # node. The unstable must be a child of one of node predecessors.
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1067
    for ctx in selfanddescendants(repo, pctx):
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1068
        for child in ctx.children():
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1069
            if child.unstable():
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1070
                return child
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1071
    return None
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1072
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1073
def _solveunstable(ui, repo, orig, dryrun=False, progresscb=None):
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1074
    """Stabilize a unstable changeset"""
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
  1075
    obs = orig.parents()[0]
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1076
    if not obs.obsolete():
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1077
        print obs.rev(), orig.parents()
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1078
        print orig.rev()
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
  1079
        obs = orig.parents()[1]
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1080
    assert obs.obsolete()
630
722b52c75f02 compat: adapt to upstreaming of divergent logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 622
diff changeset
  1081
    newer = obsolete.successorssets(repo, obs.node())
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1082
    # search of a parent which is not killed
588
89c8550019d0 mercurial: replace all `newerversion` call by `successorsset` call
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 587
diff changeset
  1083
    while not newer or newer == [()]:
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1084
        ui.debug("stabilize target %s is plain dead,"
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1085
                 " trying to stabilize on its parent")
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1086
        obs = obs.parents()[0]
630
722b52c75f02 compat: adapt to upstreaming of divergent logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 622
diff changeset
  1087
        newer = obsolete.successorssets(repo, obs.node())
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1088
    if len(newer) > 1:
707
f914e315b717 evolve: remove magic return values from utility functions
Levi Bard <levi@unity3d.com>
parents: 706
diff changeset
  1089
        raise util.Abort(_("conflict rewriting. can't choose destination\n"))
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1090
    targets = newer[0]
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1091
    assert targets
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1092
    if len(targets) > 1:
707
f914e315b717 evolve: remove magic return values from utility functions
Levi Bard <levi@unity3d.com>
parents: 706
diff changeset
  1093
        raise util.Abort(_("does not handle split parents yet\n"))
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1094
        return 2
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1095
    target = targets[0]
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1096
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1097
    target = repo[target]
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1098
    repo.ui.status(_('move:'))
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
  1099
    if not ui.quiet:
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
  1100
        displayer.show(orig)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1101
    repo.ui.status(_('atop:'))
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
  1102
    if not ui.quiet:
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
  1103
        displayer.show(target)
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1104
    if progresscb: progresscb()
546
415540dee2bd fix missing --dest evolve output in dryrun
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 540
diff changeset
  1105
    todo = 'hg rebase -r %s -d %s\n' % (orig, target)
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1106
    if dryrun:
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
  1107
        repo.ui.write(todo)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1108
    else:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1109
        repo.ui.note(todo)
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1110
        if progresscb: progresscb()
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1111
        lock = repo.lock()
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1112
        try:
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
  1113
            relocate(repo, orig, target)
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
  1114
        except MergeFailure:
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1115
            repo.opener.write('graftstate', orig.hex() + '\n')
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1116
            repo.ui.write_err(_('evolve failed!\n'))
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1117
            repo.ui.write_err(_('fix conflict and run "hg evolve --continue"\n'))
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
  1118
            raise
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1119
        finally:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1120
            lock.release()
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
  1121
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1122
def _solvebumped(ui, repo, bumped, dryrun=False, progresscb=None):
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1123
    """Stabilize a bumped changeset"""
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1124
    # For now we deny bumped merge
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1125
    if len(bumped.parents()) > 1:
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1126
        raise util.Abort('late comer stabilization is confused by bumped'
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1127
                         ' %s being a merge' % bumped)
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1128
    prec = repo.set('last(allprecursors(%d) and public())', bumped).next()
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1129
    # For now we deny target merge
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1130
    if len(prec.parents()) > 1:
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1131
        raise util.Abort('late comer evolution is confused by precursors'
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1132
                         ' %s being a merge' % prec)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1133
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1134
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1135
    repo.ui.status(_('recreate:'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1136
    if not ui.quiet:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1137
        displayer.show(bumped)
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1138
    repo.ui.status(_('atop:'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1139
    if not ui.quiet:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1140
        displayer.show(prec)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1141
    if dryrun:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1142
        todo = 'hg rebase --rev %s --dest %s;\n' % (bumped, prec.p1())
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1143
        repo.ui.write(todo)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1144
        repo.ui.write('hg update %s;\n' % prec)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1145
        repo.ui.write('hg revert --all --rev %s;\n' % bumped)
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1146
        repo.ui.write('hg commit --msg "bumped update to %s"')
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1147
        return 0
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1148
    if progresscb: progresscb()
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1149
    wlock = repo.wlock()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1150
    try:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1151
        newid = tmpctx = None
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1152
        tmpctx = bumped
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1153
        lock = repo.lock()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1154
        try:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1155
            bmupdate = _bookmarksupdater(repo, bumped.node())
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1156
            # Basic check for common parent. Far too complicated and fragile
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1157
            tr = repo.transaction('bumped-stabilize')
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1158
            try:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1159
                if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1160
                    # Need to rebase the changeset at the right place
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1161
                    repo.ui.status(_('rebasing to destination parent: %s\n') % prec.p1())
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1162
                    try:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1163
                        tmpid = relocate(repo, bumped, prec.p1())
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1164
                        if tmpid is not None:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1165
                            tmpctx = repo[tmpid]
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1166
                            createmarkers(repo, [(bumped, (tmpctx,))])
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1167
                    except MergeFailure:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1168
                        repo.opener.write('graftstate', bumped.hex() + '\n')
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1169
                        repo.ui.write_err(_('evolution failed!\n'))
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1170
                        repo.ui.write_err(_('fix conflict and run "hg evolve --continue"\n'))
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1171
                        raise
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1172
                # Create the new commit context
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1173
                repo.ui.status(_('computing new diff\n'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1174
                files = set()
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1175
                copied = copies.pathcopies(prec, bumped)
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1176
                precmanifest = prec.manifest()
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1177
                for key, val in bumped.manifest().iteritems():
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1178
                    if precmanifest.pop(key, None) != val:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1179
                        files.add(key)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1180
                files.update(precmanifest)  # add missing files
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1181
                # commit it
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1182
                if files: # something to commit!
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1183
                    def filectxfn(repo, ctx, path):
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1184
                        if path in bumped:
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1185
                            fctx = bumped[path]
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1186
                            flags = fctx.flags()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1187
                            mctx = context.memfilectx(fctx.path(), fctx.data(),
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1188
                                                      islink='l' in flags,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1189
                                                      isexec='x' in flags,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1190
                                                      copied=copied.get(path))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1191
                            return mctx
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1192
                        raise IOError()
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1193
                    text = 'bumped update to %s:\n\n' % prec
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1194
                    text += bumped.description()
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1195
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1196
                    new = context.memctx(repo,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1197
                                         parents=[prec.node(), node.nullid],
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1198
                                         text=text,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1199
                                         files=files,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1200
                                         filectxfn=filectxfn,
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1201
                                         user=bumped.user(),
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1202
                                         date=bumped.date(),
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1203
                                         extra=bumped.extra())
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1204
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1205
                    newid = repo.commitctx(new)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1206
                if newid is None:
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1207
                    createmarkers(repo, [(tmpctx, ())])
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1208
                    newid = prec.node()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1209
                else:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1210
                    phases.retractboundary(repo, bumped.phase(), [newid])
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1211
                    createmarkers(repo, [(tmpctx, (repo[newid],))],
802
80e078959129 evolve: use flag value from core for bumped fix
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 789
diff changeset
  1212
                                           flag=obsolete.bumpedfix)
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1213
                bmupdate(newid)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1214
                tr.close()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1215
                repo.ui.status(_('commited as %s\n') % node.short(newid))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1216
            finally:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1217
                tr.release()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1218
        finally:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1219
            lock.release()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1220
        # reroute the working copy parent to the new changeset
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1221
        repo.dirstate.setparents(newid, node.nullid)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1222
    finally:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1223
        wlock.release()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1224
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1225
def _solvedivergent(ui, repo, divergent, dryrun=False, progresscb=None):
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1226
    base, others = divergentdata(divergent)
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1227
    if len(others) > 1:
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1228
        othersstr = "[%s]" % (','.join([str(i) for i in others]))
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1229
        hint = ("changeset %d is divergent with a changeset that got splitted "
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1230
                "| into multiple ones:\n[%s]\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1231
                "| This is not handled by automatic evolution yet\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1232
                "| You have to fallback to manual handling with commands as:\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1233
                "| - hg touch -D\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1234
                "| - hg prune\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1235
                "| \n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1236
                "| You should contact your local evolution Guru for help.\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1237
                % (divergent, othersstr))
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1238
        raise util.Abort("We do not handle divergence with split yet",
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1239
                         hint='')
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1240
    other = others[0]
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1241
    if divergent.phase() <= phases.public:
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1242
        raise util.Abort("We can't resolve this conflict from the public side",
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1243
                         hint="%s is public, try from %s" % (divergent, other))
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1244
    if len(other.parents()) > 1:
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1245
        raise util.Abort("divergent changeset can't be a merge (yet)",
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1246
                          hint="You have to fallback to solving this by hand...\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1247
                               "| This probably mean to redo the merge and use "
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1248
                               "| `hg prune` to kill older version.")
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1249
    if other.p1() not in divergent.parents():
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1250
        raise util.Abort("parents are not common (not handled yet)",
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1251
                         hint="| %(d)s, %(o)s are not based on the same changeset."
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1252
                              "| With the current state of its implementation, "
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1253
                              "| evolve does not work in that case.\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1254
                              "| rebase one of them next to the other and run "
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1255
                              "| this command again.\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1256
                              "| - either: hg rebase -dest 'p1(%(d)s)' -r %(o)s"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1257
                              "| - or:     hg rebase -dest 'p1(%(d)s)' -r %(o)s"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1258
                              % {'d': divergent, 'o': other})
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1259
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1260
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1261
    ui.status(_('merge:'))
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1262
    if not ui.quiet:
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1263
        displayer.show(divergent)
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1264
    ui.status(_('with: '))
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1265
    if not ui.quiet:
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1266
        displayer.show(other)
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1267
    ui.status(_('base: '))
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1268
    if not ui.quiet:
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1269
        displayer.show(base)
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1270
    if dryrun:
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1271
        ui.write('hg update -c %s &&\n' % divergent)
533
87c41ef95ebf test conflicting conflicting (sic) resolution
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 523
diff changeset
  1272
        ui.write('hg merge %s &&\n' % other)
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1273
        ui.write('hg commit -m "auto merge resolving conflict between '
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1274
                 '%s and %s"&&\n' % (divergent, other))
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1275
        ui.write('hg up -C %s &&\n' % base)
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1276
        ui.write('hg revert --all --rev tip &&\n')
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1277
        ui.write('hg commit -m "`hg log -r %s --template={desc}`";\n'
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1278
                 % divergent)
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1279
        return
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1280
    wlock = lock = None
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1281
    try:
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1282
        wlock = repo.wlock()
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1283
        lock = repo.lock()
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1284
        if divergent not in repo[None].parents():
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1285
            repo.ui.status(_('updating to "local" conflict\n'))
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1286
            hg.update(repo, divergent.rev())
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1287
        repo.ui.note(_('merging divergent changeset\n'))
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1288
        if progresscb: progresscb()
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1289
        stats = merge.update(repo,
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1290
                             other.node(),
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1291
                             branchmerge=True,
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1292
                             force=False,
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1293
                             partial=None,
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1294
                             ancestor=base.node(),
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1295
                             mergeancestor=True)
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1296
        hg._showstats(repo, stats)
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1297
        if stats[3]:
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1298
            repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1299
                             "or 'hg update -C .' to abandon\n"))
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1300
        if stats[3] > 0:
534
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1301
            raise util.Abort('Merge conflict between several amendments, and this is not yet automated',
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1302
                hint="""/!\ You can try:
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1303
/!\ * manual merge + resolve => new cset X
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1304
/!\ * hg up to the parent of the amended changeset (which are named W and Z)
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1305
/!\ * hg revert --all -r X
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1306
/!\ * hg ci -m "same message as the amended changeset" => new cset Y
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1307
/!\ * hg kill -n Y W Z
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1308
""")
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1309
        if progresscb: progresscb()
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1310
        tr = repo.transaction('stabilize-divergent')
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1311
        try:
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1312
            repo.dirstate.setparents(divergent.node(), node.nullid)
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1313
            oldlen = len(repo)
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1314
            amend(ui, repo, message='', logfile='')
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1315
            if oldlen == len(repo):
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1316
                new = divergent
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1317
                # no changes
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1318
            else:
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1319
                new = repo['.']
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1320
            createmarkers(repo, [(other, (new,))])
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1321
            phases.retractboundary(repo, other.phase(), [new.node()])
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1322
            tr.close()
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1323
        finally:
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1324
            tr.release()
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1325
    finally:
516
18854dbc92e7 evolve: simplify locking in _solveconflicting()
Patrick Mezard <patrick@mezard.eu>
parents: 515
diff changeset
  1326
        lockmod.release(lock, wlock)
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1327
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1328
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1329
def divergentdata(ctx):
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1330
    """return base, other part of a conflict
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1331
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1332
    This only return the first one.
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1333
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1334
    XXX this woobly function won't survive XXX
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1335
    """
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1336
    for base in ctx._repo.set('reverse(precursors(%d))', ctx):
630
722b52c75f02 compat: adapt to upstreaming of divergent logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 622
diff changeset
  1337
        newer = obsolete.successorssets(ctx._repo, base.node())
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1338
        # drop filter and solution including the original ctx
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1339
        newer = [n for n in newer if n and ctx.node() not in n]
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1340
        if newer:
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1341
            return base, tuple(ctx._repo[o] for o in newer[0])
749
f728edc7fcd1 evolve: abort on unknown divergent changeset base
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 745
diff changeset
  1342
    raise util.Abort('base of divergent changeset not found',
f728edc7fcd1 evolve: abort on unknown divergent changeset base
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 745
diff changeset
  1343
                     hint='this case is not yet handled')
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1344
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1345
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1346
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1347
shorttemplate = '[{rev}] {desc|firstline}\n'
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1348
751
a5474648a9d2 gdown/gup: add next/previous alias
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 750
diff changeset
  1349
@command('^gdown|previous',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1350
         [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1351
         '')
751
a5474648a9d2 gdown/gup: add next/previous alias
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 750
diff changeset
  1352
def cmdprevious(ui, repo):
724
fa049c1d9445 evolve: fix typo
André Sintzoff <andre.sintzoff@gmail.com>
parents: 723
diff changeset
  1353
    """update to parent and display summary lines"""
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1354
    wkctx = repo[None]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1355
    wparents = wkctx.parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1356
    if len(wparents) != 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1357
        raise util.Abort('merge in progress')
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1358
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1359
    parents = wparents[0].parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1360
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1361
    if len(parents) == 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1362
        p = parents[0]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1363
        hg.update(repo, p.rev())
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1364
        displayer.show(p)
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
  1365
        return 0
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1366
    else:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1367
        for p in parents:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1368
            displayer.show(p)
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1369
        ui.warn(_('multiple parents, explicitly update to one\n'))
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1370
        return 1
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1371
751
a5474648a9d2 gdown/gup: add next/previous alias
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 750
diff changeset
  1372
@command('^gup|next',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1373
         [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1374
         '')
751
a5474648a9d2 gdown/gup: add next/previous alias
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 750
diff changeset
  1375
def cmdnext(ui, repo):
724
fa049c1d9445 evolve: fix typo
André Sintzoff <andre.sintzoff@gmail.com>
parents: 723
diff changeset
  1376
    """update to child and display summary lines"""
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1377
    wkctx = repo[None]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1378
    wparents = wkctx.parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1379
    if len(wparents) != 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1380
        raise util.Abort('merge in progress')
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1381
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1382
    children = [ctx for ctx in wparents[0].children() if not ctx.obsolete()]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1383
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1384
    if not children:
743
af74a5cdf96b conform to the Mercurial custom of lowercase messages
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 742
diff changeset
  1385
        ui.warn(_('no non-obsolete children\n'))
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1386
        return 1
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1387
    if len(children) == 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1388
        c = children[0]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1389
        hg.update(repo, c.rev())
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1390
        displayer.show(c)
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1391
        return 0
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1392
    else:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1393
        for c in children:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1394
            displayer.show(c)
743
af74a5cdf96b conform to the Mercurial custom of lowercase messages
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 742
diff changeset
  1395
        ui.warn(_('multiple non-obsolete children, explicitly update to one\n'))
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1396
        return 1
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1397
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1398
def _reachablefrombookmark(repo, revs, mark):
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1399
    """filter revisions and bookmarks reachable from the given bookmark
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1400
    yoinked from mq.py
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1401
    """
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1402
    marks = repo._bookmarks
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1403
    if mark not in marks:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1404
        raise util.Abort(_("bookmark '%s' not found") % mark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1405
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1406
    # If the requested bookmark is not the only one pointing to a
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1407
    # a revision we have to only delete the bookmark and not strip
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1408
    # anything. revsets cannot detect that case.
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1409
    uniquebm = True
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1410
    for m, n in marks.iteritems():
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1411
        if m != mark and n == repo[mark].node():
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1412
            uniquebm = False
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1413
            break
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1414
    if uniquebm:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1415
        rsrevs = repo.revs("ancestors(bookmark(%s)) - "
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1416
                           "ancestors(head() and not bookmark(%s)) - "
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1417
                           "ancestors(bookmark() and not bookmark(%s)) - "
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1418
                           "obsolete()",
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1419
                           mark, mark, mark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1420
        revs.update(set(rsrevs))
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1421
    return marks,revs
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1422
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1423
def _deletebookmark(ui, marks, mark):
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1424
    del marks[mark]
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1425
    marks.write()
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1426
    ui.write(_("bookmark '%s' deleted\n") % mark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1427
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1428
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1429
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1430
def _getmetadata(**opts):
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1431
    metadata = {}
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1432
    date = opts.get('date')
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1433
    user = opts.get('user')
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1434
    if date and '0 0' != date:
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1435
        metadata['date'] = '%i %i' % util.parsedate(date)
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1436
    if user:
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1437
        metadata['user'] = user
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1438
    return metadata
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1439
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1440
365
9f6a77ec66cb evolve: switch the official name for "kill" to prune
Pierre-Yves.David@ens-lyon.org
parents: 362
diff changeset
  1441
@command('^prune|obsolete|kill',
682
6cbb52a8401b prune: rename --new to --succ
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 681
diff changeset
  1442
    [('n', 'new', [], _("successor changeset (DEPRECATED)")),
6cbb52a8401b prune: rename --new to --succ
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 681
diff changeset
  1443
     ('s', 'succ', [], _("successor changeset")),
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1444
     ('r', 'rev', [], _("revisions to prune")),
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1445
     ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")),
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1446
     ('B', 'bookmark', '', _("remove revs only reachable from given"
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1447
                             " bookmark"))] + metadataopts,
644
8e41d5b78dff support -r option in prune, add a test for this
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 636
diff changeset
  1448
    _('[OPTION] [-r] REV...'))
690
929d7617a13d prune: more command switch idea
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 689
diff changeset
  1449
    # -U  --noupdate option to prevent wc update and or bookmarks update ?
681
eff18fcaaddc prune: improve command function name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 680
diff changeset
  1450
def cmdprune(ui, repo, *revs, **opts):
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1451
    """get rid of changesets by marking them obsolete
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1452
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1453
    Obsolete changesets becomes invisible to all commands.
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1454
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1455
    Non-pruned descendant of pruned changesets becomes "unstable". Use the
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1456
    :hg:`evolve` to handle such situation.
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1457
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1458
    When the working directory parent is pruned the repository is updated to a
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1459
    non obsolete parents.
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1460
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1461
    You can use the ``--succ`` option to informs mercurial that a newer version
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1462
    of the pruned changeset exists.
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1463
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1464
    You can use the ``--biject`` option to specify a 1-1 (bijection) between
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1465
    revisions to prune and successor changesets. This option may be removed in
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1466
    a future release (with the functionality absored automatically).
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1467
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1468
    """
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1469
    revs = set(scmutil.revrange(repo, list(revs) + opts.get('rev')))
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1470
    succs = opts['new'] + opts['succ']
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1471
    bookmark = opts.get('bookmark')
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1472
    metadata = _getmetadata(**opts)
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1473
    biject = opts.get('biject')
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1474
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1475
    if bookmark:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1476
        marks,revs = _reachablefrombookmark(repo, revs, bookmark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1477
        if not revs:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1478
            # no revisions to prune - delete bookmark immediately
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1479
            _deletebookmark(ui, marks, bookmark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1480
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1481
    if not revs:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1482
        raise util.Abort(_('nothing to prune'))
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1483
683
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1484
    wlock = lock = None
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1485
    wlock = repo.wlock()
685
7398f9729821 prune: add test and more robusness
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 684
diff changeset
  1486
    sortedrevs = lambda specs: sorted(set(scmutil.revrange(repo, specs)))
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1487
    try:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  1488
        lock = repo.lock()
691
6e63b4185a5c prune: update inline documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 690
diff changeset
  1489
        # defines pruned changesets
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1490
        precs = []
685
7398f9729821 prune: add test and more robusness
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 684
diff changeset
  1491
        for p in sortedrevs(revs):
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1492
            cp = repo[p]
687
6c1fbef2952e prune: test and improve message of immutable aborting.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 685
diff changeset
  1493
            if not cp.mutable():
6c1fbef2952e prune: test and improve message of immutable aborting.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 685
diff changeset
  1494
                # note: create marker would had raise something anyway
6c1fbef2952e prune: test and improve message of immutable aborting.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 685
diff changeset
  1495
                raise util.Abort('cannot prune immutable changeset: %s' % cp,
6c1fbef2952e prune: test and improve message of immutable aborting.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 685
diff changeset
  1496
                                 hint='see "hg help phases" for details')
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1497
            precs.append(cp)
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1498
        if not precs:
683
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1499
            raise util.Abort('nothing to prune')
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1500
691
6e63b4185a5c prune: update inline documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 690
diff changeset
  1501
        # defines successors changesets
685
7398f9729821 prune: add test and more robusness
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 684
diff changeset
  1502
        sucs = tuple(repo[n] for n in sortedrevs(succs))
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1503
        if not biject and len(sucs) > 1 and len(precs) > 1:
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1504
            msg = "Can't use multiple successors for multiple precursors"
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1505
            raise util.Abort(msg)
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1506
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1507
        if biject and len(sucs) != len(precs):
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1508
            msg = "Can't use %d successors for %d precursors" % (len(sucs), len(precs))
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1509
            raise util.Abort(msg)
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1510
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1511
        relations = [(p, sucs) for p in precs]
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1512
        if biject:
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1513
            relations = [(p, (s,)) for p, s in zip(precs, sucs)]
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1514
691
6e63b4185a5c prune: update inline documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 690
diff changeset
  1515
        # create markers
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1516
        createmarkers(repo, relations, metadata=metadata)
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1517
688
f2c3fd21fa63 prune: add an informative message about the number of pruned changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 687
diff changeset
  1518
        # informs that changeset have been pruned
f2c3fd21fa63 prune: add an informative message about the number of pruned changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 687
diff changeset
  1519
        ui.status(_('%i changesets pruned\n') % len(precs))
683
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1520
        # update to an unkilled parent
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1521
        wdp = repo['.']
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1522
        newnode = wdp
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1523
        while newnode.obsolete():
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1524
            newnode = newnode.parents()[0]
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1525
        if newnode.node() != wdp.node():
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1526
            commands.update(ui, repo, newnode.rev())
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1527
            ui.status(_('working directory now at %s\n') % newnode)
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1528
        # update bookmarks
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1529
        if bookmark:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1530
            _deletebookmark(ui, marks, bookmark)
693
d3c1fe0035d1 prune: handle bookmark
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 691
diff changeset
  1531
        for ctx in repo.unfiltered().set('bookmark() and %ld', precs):
d3c1fe0035d1 prune: handle bookmark
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 691
diff changeset
  1532
            ldest = list(repo.set('max((::%d) - obsolete())', ctx))
d3c1fe0035d1 prune: handle bookmark
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 691
diff changeset
  1533
            if ldest:
d3c1fe0035d1 prune: handle bookmark
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 691
diff changeset
  1534
                dest = ldest[0]
d3c1fe0035d1 prune: handle bookmark
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 691
diff changeset
  1535
                updatebookmarks = _bookmarksupdater(repo, ctx.node())
d3c1fe0035d1 prune: handle bookmark
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 691
diff changeset
  1536
                updatebookmarks(dest.node())
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1537
    finally:
683
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1538
        lockmod.release(lock, wlock)
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1539
673
761b5b266985 evolve: removes amend from the list of advertised function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 672
diff changeset
  1540
@command('amend|refresh',
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1541
    [('A', 'addremove', None,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1542
     _('mark new/missing files as added/removed before committing')),
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1543
    ('e', 'edit', False, _('invoke editor on commit messages')),
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1544
    ('', 'close-branch', None,
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1545
     _('mark a branch as closed, hiding it from the branch list')),
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1546
    ('s', 'secret', None, _('use the secret phase for committing')),
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1547
    ] + walkopts + commitopts + commitopts2,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1548
    _('[OPTION]... [FILE]...'))
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1549
def amend(ui, repo, *pats, **opts):
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1550
    """combine a changeset with updates and replace it with a new one
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1551
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1552
    Commits a new changeset incorporating both the changes to the given files
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1553
    and all the changes from the current parent changeset into the repository.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1554
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1555
    See :hg:`commit` for details about committing changes.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1556
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1557
    If you don't specify -m, the parent's message will be reused.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1558
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1559
    Behind the scenes, Mercurial first commits the update as a regular child
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1560
    of the current parent. Then it creates a new commit on the parent's parents
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1561
    with the updated contents. Then it changes the working copy parent to this
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1562
    new combined changeset. Finally, the old changeset and its update are hidden
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1563
    from :hg:`log` (unless you use --hidden with log).
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1564
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1565
    Returns 0 on success, 1 if nothing changed.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1566
    """
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1567
    opts = opts.copy()
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1568
    edit = opts.pop('edit', False)
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1569
    opts['amend'] = True
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1570
    if not (edit or opts['message']):
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1571
        opts['message'] = repo['.'].description()
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1572
    _alias, commitcmd = cmdutil.findcmd('commit', commands.table)
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1573
    return commitcmd[0](ui, repo, *pats, **opts)
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
  1574
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1575
def _commitfiltered(repo, ctx, match):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1576
    """Recommit ctx with changed files not in match. Return the new
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1577
    node identifier, or None if nothing changed.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1578
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1579
    base = ctx.p1()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1580
    m, a, r = repo.status(base, ctx)[:3]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1581
    allfiles = set(m + a + r)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1582
    files = set(f for f in allfiles if not match(f))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1583
    if files == allfiles:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1584
        return None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1585
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1586
    # Filter copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1587
    copied = copies.pathcopies(base, ctx)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1588
    copied = dict((src, dst) for src, dst in copied.iteritems()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1589
                  if dst in files)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1590
    def filectxfn(repo, memctx, path):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1591
        if path not in ctx:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1592
            raise IOError()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1593
        fctx = ctx[path]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1594
        flags = fctx.flags()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1595
        mctx = context.memfilectx(fctx.path(), fctx.data(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1596
                                  islink='l' in flags,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1597
                                  isexec='x' in flags,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1598
                                  copied=copied.get(path))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1599
        return mctx
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1600
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1601
    new = context.memctx(repo,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1602
                         parents=[base.node(), node.nullid],
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1603
                         text=ctx.description(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1604
                         files=files,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1605
                         filectxfn=filectxfn,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1606
                         user=ctx.user(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1607
                         date=ctx.date(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1608
                         extra=ctx.extra())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1609
    # commitctx always create a new revision, no need to check
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1610
    newid = repo.commitctx(new)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1611
    return newid
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1612
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1613
def _uncommitdirstate(repo, oldctx, match):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1614
    """Fix the dirstate after switching the working directory from
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1615
    oldctx to a copy of oldctx not containing changed files matched by
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1616
    match.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1617
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1618
    ctx = repo['.']
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1619
    ds = repo.dirstate
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1620
    copies = dict(ds.copies())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1621
    m, a, r = repo.status(oldctx.p1(), oldctx, match=match)[:3]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1622
    for f in m:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1623
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1624
            # modified + removed -> removed
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1625
            continue
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1626
        ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1627
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1628
    for f in a:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1629
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1630
            # added + removed -> unknown
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1631
            ds.drop(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1632
        elif ds[f] != 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1633
            ds.add(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1634
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1635
    for f in r:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1636
        if ds[f] == 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1637
            # removed + added -> normal
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1638
            ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1639
        elif ds[f] != 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1640
            ds.remove(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1641
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1642
    # Merge old parent and old working dir copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1643
    oldcopies = {}
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1644
    for f in (m + a):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1645
        src = oldctx[f].renamed()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1646
        if src:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1647
            oldcopies[f] = src[0]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1648
    oldcopies.update(copies)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1649
    copies = dict((dst, oldcopies.get(src, src))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1650
                  for dst, src in oldcopies.iteritems())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1651
    # Adjust the dirstate copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1652
    for dst, src in copies.iteritems():
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1653
        if (src not in ctx or dst in ctx or ds[dst] != 'a'):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1654
            src = None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1655
        ds.copy(src, dst)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1656
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1657
@command('^uncommit',
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
  1658
    [('a', 'all', None, _('uncommit all changes when no arguments given')),
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
  1659
     ] + commands.walkopts,
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1660
    _('[OPTION]... [NAME]'))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1661
def uncommit(ui, repo, *pats, **opts):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1662
    """move changes from parent revision to working directory
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1663
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1664
    Changes to selected files in parent revision appear again as
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1665
    uncommitted changed in the working directory. A new revision
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1666
    without selected changes is created, becomes the new parent and
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1667
    obsoletes the previous one.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1668
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1669
    The --include option specify pattern to uncommit
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1670
    The --exclude option specify pattern to keep in the commit
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1671
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1672
    Return 0 if changed files are uncommitted.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1673
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1674
    lock = repo.lock()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1675
    try:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1676
        wlock = repo.wlock()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1677
        try:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1678
            wctx = repo[None]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1679
            if len(wctx.parents()) <= 0:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1680
                raise util.Abort(_("cannot uncommit null changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1681
            if len(wctx.parents()) > 1:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1682
                raise util.Abort(_("cannot uncommit while merging"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1683
            old = repo['.']
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1684
            if old.phase() == phases.public:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1685
                raise util.Abort(_("cannot rewrite immutable changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1686
            if len(old.parents()) > 1:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1687
                raise util.Abort(_("cannot uncommit merge changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1688
            oldphase = old.phase()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
  1689
            updatebookmarks = _bookmarksupdater(repo, old.node())
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1690
            # Recommit the filtered changeset
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1691
            newid = None
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
  1692
            if (pats or opts.get('include') or opts.get('exclude')
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
  1693
                or opts.get('all')):
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1694
                match = scmutil.match(old, pats, opts)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1695
                newid = _commitfiltered(repo, old, match)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1696
            if newid is None:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1697
                raise util.Abort(_('nothing to uncommit'))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1698
            # Move local changes on filtered changeset
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1699
            createmarkers(repo, [(old, (repo[newid],))])
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1700
            phases.retractboundary(repo, oldphase, [newid])
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1701
            repo.dirstate.setparents(newid, node.nullid)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1702
            _uncommitdirstate(repo, old, match)
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
  1703
            updatebookmarks(newid)
318
da7509e7b50c evolve: warn when uncommit leave an empty changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 315
diff changeset
  1704
            if not repo[newid].files():
da7509e7b50c evolve: warn when uncommit leave an empty changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 315
diff changeset
  1705
                ui.warn(_("new changeset is empty\n"))
da7509e7b50c evolve: warn when uncommit leave an empty changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 315
diff changeset
  1706
                ui.status(_('(use "hg kill ." to remove it)\n'))
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1707
        finally:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1708
            wlock.release()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1709
    finally:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1710
        lock.release()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1711
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1712
@eh.wrapcommand('commit')
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
  1713
def commitwrapper(orig, ui, repo, *arg, **kwargs):
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1714
    if kwargs.get('amend', False):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1715
        lock = None
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1716
    else:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1717
        lock = repo.lock()
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1718
    try:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1719
        obsoleted = kwargs.get('obsolete', [])
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1720
        if obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1721
            obsoleted = repo.set('%lr', obsoleted)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1722
        result = orig(ui, repo, *arg, **kwargs)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1723
        if not result: # commit successed
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1724
            new = repo['-1']
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1725
            oldbookmarks = []
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  1726
            markers = []
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1727
            for old in obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1728
                oldbookmarks.extend(repo.nodebookmarks(old.node()))
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  1729
                markers.append((old, (new,)))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  1730
            if markers:
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1731
                createmarkers(repo, markers)
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1732
            for book in oldbookmarks:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1733
                repo._bookmarks[book] = new.node()
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1734
            if oldbookmarks:
612
15299bfd0813 adapt to 7f5dab94e48c in crew
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 604
diff changeset
  1735
                repo._bookmarks.write()
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1736
        return result
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1737
    finally:
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1738
        if lock is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1739
            lock.release()
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
  1740
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1741
@command('^touch',
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  1742
    [('r', 'rev', [], 'revision to update'),
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  1743
     ('D', 'duplicate', False,
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  1744
      'do not mark the new revision as successor of the old one')],
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1745
    # allow to choose the seed ?
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1746
    _('[-r] revs'))
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1747
def touch(ui, repo, *revs, **opts):
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1748
    """Create successors with exact same property but hash
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1749
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1750
    This is used to "resurrect" changesets
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1751
    """
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  1752
    duplicate = opts['duplicate']
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1753
    revs = list(revs)
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1754
    revs.extend(opts['rev'])
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1755
    if not revs:
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1756
        revs = ['.']
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1757
    revs = scmutil.revrange(repo, revs)
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1758
    if not revs:
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1759
        ui.write_err('no revision to touch\n')
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1760
        return 1
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  1761
    if not duplicate and repo.revs('public() and %ld', revs):
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1762
        raise util.Abort("can't touch public revision")
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1763
    wlock = lock = None
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1764
    try:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1765
        wlock = repo.wlock()
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1766
        lock = repo.lock()
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1767
        tr = repo.transaction('touch')
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1768
        revs.sort() # ensure parent are run first
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1769
        newmapping = {}
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1770
        try:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1771
            for r in revs:
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1772
                ctx = repo[r]
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1773
                extra = ctx.extra().copy()
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1774
                extra['__touch-noise__'] = random.randint(0, 0xffffffff)
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1775
                # search for touched parent
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1776
                p1 = ctx.p1().node()
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1777
                p2 = ctx.p2().node()
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1778
                p1 = newmapping.get(p1, p1)
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1779
                p2 = newmapping.get(p2, p2)
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1780
                new, _ = rewrite(repo, ctx, [], ctx,
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1781
                                 [p1, p2],
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1782
                                 commitopts={'extra': extra})
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1783
                # store touched version to help potential children
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1784
                newmapping[ctx.node()] = new
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  1785
                if not duplicate:
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  1786
                    createmarkers(repo, [(ctx, (repo[new],))])
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1787
                phases.retractboundary(repo, ctx.phase(), [new])
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1788
                if ctx in repo[None].parents():
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1789
                    repo.dirstate.setparents(new, node.nullid)
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1790
            tr.close()
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1791
        finally:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1792
            tr.release()
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1793
    finally:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  1794
        lockmod.release(lock, wlock)
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1795
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1796
@command('^fold',
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1797
    [('r', 'rev', [], _("explicitly specify the full set of revision to fold")),
619
f50f8da7a077 add a -e option to fold
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 611
diff changeset
  1798
    ],
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1799
    # allow to choose the seed ?
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1800
    _('rev'))
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1801
def fold(ui, repo, *revs, **opts):
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1802
    """Fold multiple revisions into a single one
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1803
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1804
    Revision from your current working directory to the specified one are fold
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1805
    as a new one replacing the other
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1806
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1807
    you can alternatively use --rev to explicitly specify revision to be fold
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1808
    ignoring the current working directory parent.
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1809
    """
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1810
    revs = list(revs)
561
897f6da2314e fold: handle the lack of revision to fold
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 554
diff changeset
  1811
    if revs:
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1812
        if opts.get('rev', ()):
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1813
            raise util.Abort("cannot specify both --rev and a target revision")
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1814
        targets = scmutil.revrange(repo, revs)
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1815
        revs = repo.revs('(%ld::.) or (.::%ld)', targets, targets)
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1816
    elif 'rev' in opts:
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1817
        revs = scmutil.revrange(repo, opts['rev'])
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1818
    else:
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  1819
        revs = ()
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1820
    if not revs:
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1821
        ui.write_err('no revision to fold\n')
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1822
        return 1
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1823
    roots = repo.revs('roots(%ld)', revs)
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1824
    if len(roots) > 1:
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1825
        raise util.Abort("set has multiple roots")
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1826
    root = repo[roots[0]]
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1827
    if root.phase() <= phases.public:
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1828
        raise util.Abort("can't fold public revisions")
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1829
    heads = repo.revs('heads(%ld)', revs)
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1830
    if len(heads) > 1:
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1831
        raise util.Abort("set has multiple heads")
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1832
    head = repo[heads[0]]
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1833
    wlock = lock = None
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1834
    try:
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1835
        wlock = repo.wlock()
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1836
        lock = repo.lock()
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1837
        tr = repo.transaction('touch')
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1838
        try:
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1839
            allctx = [repo[r] for r in revs]
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1840
            targetphase = max(c.phase() for c in allctx)
620
232536f5c987 use comments to combine commit messages in fold
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 619
diff changeset
  1841
            msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
232536f5c987 use comments to combine commit messages in fold
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 619
diff changeset
  1842
            msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
232536f5c987 use comments to combine commit messages in fold
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 619
diff changeset
  1843
                     (c.rev(), c.description()) for c in allctx]
232536f5c987 use comments to combine commit messages in fold
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 619
diff changeset
  1844
            commitopts = {'message': "\n".join(msgs)}
619
f50f8da7a077 add a -e option to fold
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 611
diff changeset
  1845
            commitopts['edit'] = True
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1846
            newid, _ = rewrite(repo, root, allctx, head,
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1847
                             [root.p1().node(), root.p2().node()],
619
f50f8da7a077 add a -e option to fold
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 611
diff changeset
  1848
                             commitopts=commitopts)
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1849
            phases.retractboundary(repo, targetphase, [newid])
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1850
            createmarkers(repo, [(ctx, (repo[newid],))
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1851
                                 for ctx in allctx])
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1852
            tr.close()
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1853
        finally:
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1854
            tr.release()
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1855
        ui.status('%i changesets folded\n' % len(revs))
632
cb0807646f5a fold: work around potential bug with filtering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 631
diff changeset
  1856
        if repo['.'].rev() in revs:
549
b047e9417d96 Properly update after fold
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 548
diff changeset
  1857
            hg.update(repo, newid)
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1858
    finally:
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  1859
        lockmod.release(lock, wlock)
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  1860
587
8152fedbac65 evolve: smarter code for divergent changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 586
diff changeset
  1861
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  1862
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1863
@eh.wrapcommand('graft')
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
  1864
def graftwrapper(orig, ui, repo, *revs, **kwargs):
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  1865
    kwargs = dict(kwargs)
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  1866
    revs = list(revs) + kwargs.get('rev', [])
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  1867
    kwargs['rev'] = []
417
a1fb18ad29a1 evolve: avoid duplication in graft wrapper
Patrick Mezard <patrick@mezard.eu>
parents: 416
diff changeset
  1868
    obsoleted = kwargs.setdefault('obsolete', [])
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  1869
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1870
    lock = repo.lock()
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1871
    try:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1872
        if kwargs.get('old_obsolete'):
418
18a0d96ed559 evolve: graft --continue is optional, test
Patrick Mezard <patrick@mezard.eu>
parents: 417
diff changeset
  1873
            if kwargs.get('continue'):
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1874
                obsoleted.extend(repo.opener.read('graftstate').splitlines())
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1875
            else:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1876
                obsoleted.extend(revs)
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  1877
        # convert obsolete target into revs to avoid alias joke
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  1878
        obsoleted[:] = [str(i) for i in repo.revs('%lr', obsoleted)]
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  1879
        if obsoleted and len(revs) > 1:
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  1880
743
af74a5cdf96b conform to the Mercurial custom of lowercase messages
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 742
diff changeset
  1881
            raise error.Abort(_('cannot graft multiple revisions while '
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  1882
                                'obsoleting (for now).'))
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  1883
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1884
        return commitwrapper(orig, ui, repo,*revs, **kwargs)
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1885
    finally:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  1886
        lock.release()
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
  1887
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1888
@eh.extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1889
def oldevolveextsetup(ui):
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
  1890
    try:
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
  1891
        rebase = extensions.find('rebase')
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
  1892
    except KeyError:
416
22f348c25d25 obsolete/evolve: fix grammar in prerequisite messages
Patrick Mezard <patrick@mezard.eu>
parents: 414
diff changeset
  1893
        raise error.Abort(_('evolution extension requires rebase extension.'))
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
  1894
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1895
    for cmd in ['kill', 'uncommit', 'touch', 'fold']:
356
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
  1896
        entry = extensions.wrapcommand(cmdtable, cmd,
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1897
                                       warnobserrors)
356
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
  1898
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1899
    entry = cmdutil.findcmd('commit', commands.table)[1]
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1900
    entry[1].append(('o', 'obsolete', [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1901
                     _("make commit obsolete this revision")))
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  1902
    entry = cmdutil.findcmd('graft', commands.table)[1]
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1903
    entry[1].append(('o', 'obsolete', [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1904
                     _("make graft obsoletes this revision")))
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1905
    entry[1].append(('O', 'old-obsolete', False,
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1906
                     _("make graft obsoletes its source")))
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
  1907