hgext3rd/evolve/cmdrewrite.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 19 Sep 2017 12:52:22 +0200
changeset 2949 9345b2eeeef3
parent 2943 25576132cb30
child 3213 7bc587557e4f
child 3229 63f6f9db9c3a
permissions -rw-r--r--
amend: lift the --interactive constraint on `--extract` The uncommit logic now supports interactive selection.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2772
394b836e475b commands: rewrite the 'evocommands' module to 'cmdrewrite'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2771
diff changeset
     1
# Module dedicated to host history rewriting commands
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# Copyright 2017 Octobus <contact@octobus.net>
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
#
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
# Status: Stabilization of the API in progress
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
#
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
#   The final set of command should go into core.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
from __future__ import absolute_import
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
    14
import random
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
    15
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
from mercurial import (
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
    17
    bookmarks as bookmarksmod,
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
    cmdutil,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
    commands,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    20
    context,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    21
    copies,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    22
    error,
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
    23
    hg,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    24
    lock as lockmod,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    25
    node,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    26
    obsolete,
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
    27
    patch,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    28
    phases,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    29
    scmutil,
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    30
    util,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    31
)
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    32
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    33
from mercurial.i18n import _
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    34
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
from . import (
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
    36
    compat,
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    37
    exthelper,
2756
f4dd6e6d4c73 rewriteutil: create a rewriteutil module to host utility function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2752
diff changeset
    38
    rewriteutil,
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
    39
    utility,
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    40
)
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    41
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    42
eh = exthelper.exthelper()
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    43
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
walkopts = commands.walkopts
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
commitopts = commands.commitopts
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
commitopts2 = commands.commitopts2
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    47
mergetoolopts = commands.mergetoolopts
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
    48
stringio = util.stringio
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    49
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
# option added by evolve
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    51
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    52
def _resolveoptions(ui, opts):
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    53
    """modify commit options dict to handle related options
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    54
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    55
    For now, all it does is figure out the commit date: respect -D unless
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    56
    -d was supplied.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    57
    """
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    58
    # N.B. this is extremely similar to setupheaderopts() in mq.py
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    59
    if not opts.get('date') and opts.get('current_date'):
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    60
        opts['date'] = '%d %d' % util.makedate()
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    61
    if not opts.get('user') and opts.get('current_user'):
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
        opts['user'] = ui.username()
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    64
commitopts3 = [
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    65
    ('D', 'current-date', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    66
     _('record the current date as commit date')),
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    67
    ('U', 'current-user', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    68
     _('record the current user as committer')),
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    69
]
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    70
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    71
interactiveopt = [['i', 'interactive', None, _('use interactive mode')]]
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    72
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    73
@eh.command(
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    74
    'amend|refresh',
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    75
    [('A', 'addremove', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    76
      _('mark new/missing files as added/removed before committing')),
2730
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
    77
     ('a', 'all', False, _("match all files")),
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    78
     ('e', 'edit', False, _('invoke editor on commit messages')),
2730
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
    79
     ('', 'extract', False, _('extract changes from the commit to the working copy')),
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    80
     ('', 'close-branch', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    81
      _('mark a branch as closed, hiding it from the branch list')),
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
     ('s', 'secret', None, _('use the secret phase for committing')),
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
    ] + walkopts + commitopts + commitopts2 + commitopts3 + interactiveopt,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    84
    _('[OPTION]... [FILE]...'))
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
def amend(ui, repo, *pats, **opts):
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    86
    """combine a changeset with updates and replace it with a new one
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    87
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    88
    Commits a new changeset incorporating both the changes to the given files
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    89
    and all the changes from the current parent changeset into the repository.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    90
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    91
    See :hg:`commit` for details about committing changes.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    92
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    93
    If you don't specify -m, the parent's message will be reused.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    94
2730
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
    95
    If --extra is specified, the behavior of `hg amend` is reversed: Changes
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
    96
    to selected files in the checked out revision appear again as uncommitted
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
    97
    changed in the working directory.
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
    98
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    99
    Returns 0 on success, 1 if nothing changed.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   100
    """
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   101
    opts = opts.copy()
2730
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   102
    if opts.get('extract'):
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   103
        return uncommit(ui, repo, *pats, **opts)
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   104
    else:
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   105
        if opts.pop('all', False):
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   106
            # add an include for all
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   107
            include = list(opts.get('include'))
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   108
            include.append('re:.*')
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   109
        edit = opts.pop('edit', False)
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   110
        log = opts.get('logfile')
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   111
        opts['amend'] = True
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   112
        if not (edit or opts['message'] or log):
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   113
            opts['message'] = repo['.'].description()
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   114
        _resolveoptions(ui, opts)
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   115
        _alias, commitcmd = cmdutil.findcmd('commit', commands.table)
2787
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   116
        try:
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   117
            wlock = repo.wlock()
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   118
            lock = repo.lock()
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   119
            rewriteutil.precheck(repo, [repo['.'].rev()], action='amend')
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   120
            return commitcmd[0](ui, repo, *pats, **opts)
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   121
        finally:
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   122
            lockmod.release(lock, wlock)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   123
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   124
def _touchedbetween(repo, source, dest, match=None):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   125
    touched = set()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   126
    for files in repo.status(source, dest, match=match)[:3]:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   127
        touched.update(files)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   128
    return touched
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   129
2728
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   130
def _commitfiltered(repo, ctx, match, target=None, message=None, user=None,
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   131
                    date=None):
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   132
    """Recommit ctx with changed files not in match. Return the new
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   133
    node identifier, or None if nothing changed.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   134
    """
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   135
    base = ctx.p1()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   136
    if target is None:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   137
        target = base
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   138
    # ctx
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   139
    initialfiles = _touchedbetween(repo, base, ctx)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   140
    if base == target:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   141
        affected = set(f for f in initialfiles if match(f))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   142
        newcontent = set()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   143
    else:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   144
        affected = _touchedbetween(repo, target, ctx, match=match)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   145
        newcontent = _touchedbetween(repo, target, base, match=match)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   146
    # The commit touchs all existing files
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   147
    # + all file that needs a new content
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   148
    # - the file affected bny uncommit with the same content than base.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   149
    files = (initialfiles - affected) | newcontent
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   150
    if not newcontent and files == initialfiles:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   151
        return None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   152
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   153
    # Filter copies
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   154
    copied = copies.pathcopies(target, ctx)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   155
    copied = dict((dst, src) for dst, src in copied.iteritems()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   156
                  if dst in files)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   157
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   158
    def filectxfn(repo, memctx, path, contentctx=ctx, redirect=newcontent):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   159
        if path in redirect:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   160
            return filectxfn(repo, memctx, path, contentctx=target, redirect=())
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   161
        if path not in contentctx:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   162
            return None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   163
        fctx = contentctx[path]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   164
        flags = fctx.flags()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   165
        mctx = context.memfilectx(repo, fctx.path(), fctx.data(),
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   166
                                  islink='l' in flags,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   167
                                  isexec='x' in flags,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   168
                                  copied=copied.get(path))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   169
        return mctx
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   170
2727
f7d44441dfd3 uncommit: add support for --message and --logfile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2726
diff changeset
   171
    if message is None:
f7d44441dfd3 uncommit: add support for --message and --logfile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2726
diff changeset
   172
        message = ctx.description()
2728
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   173
    if not user:
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   174
        user = ctx.user()
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   175
    if not date:
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   176
        date = ctx.date()
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   177
    new = context.memctx(repo,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   178
                         parents=[base.node(), node.nullid],
2727
f7d44441dfd3 uncommit: add support for --message and --logfile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2726
diff changeset
   179
                         text=message,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   180
                         files=files,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   181
                         filectxfn=filectxfn,
2728
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   182
                         user=user,
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   183
                         date=date,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   184
                         extra=ctx.extra())
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   185
    # commitctx always create a new revision, no need to check
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   186
    newid = repo.commitctx(new)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   187
    return newid
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   188
2943
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   189
def _uncommitdirstate(repo, oldctx, match, interactive):
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   190
    """Fix the dirstate after switching the working directory from
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   191
    oldctx to a copy of oldctx not containing changed files matched by
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   192
    match.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   193
    """
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   194
    ctx = repo['.']
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   195
    ds = repo.dirstate
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   196
    copies = dict(ds.copies())
2943
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   197
    if interactive:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   198
        # In interactive cases, we will find the status between oldctx and ctx
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   199
        # and considering only the files which are changed between oldctx and
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   200
        # ctx, and the status of what changed between oldctx and ctx will help
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   201
        # us in defining the exact behavior
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   202
        m, a, r = repo.status(oldctx, ctx, match=match)[:3]
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   203
        for f in m:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   204
            # These are files which are modified between oldctx and ctx which
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   205
            # contains two cases: 1) Were modified in oldctx and some
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   206
            # modifications are uncommitted
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   207
            # 2) Were added in oldctx but some part is uncommitted (this cannot
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   208
            # contain the case when added files are uncommitted completely as
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   209
            # that will result in status as removed not modified.)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   210
            # Also any modifications to a removed file will result the status as
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   211
            # added, so we have only two cases. So in either of the cases, the
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   212
            # resulting status can be modified or clean.
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   213
            if ds[f] == 'r':
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   214
                # But the file is removed in the working directory, leaving that
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   215
                # as removed
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   216
                continue
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   217
            ds.normallookup(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   218
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   219
        for f in a:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   220
            # These are the files which are added between oldctx and ctx(new
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   221
            # one), which means the files which were removed in oldctx
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   222
            # but uncommitted completely while making the ctx
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   223
            # This file should be marked as removed if the working directory
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   224
            # does not adds it back. If it's adds it back, we do a normallookup.
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   225
            # The file can't be removed in working directory, because it was
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   226
            # removed in oldctx
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   227
            if ds[f] == 'a':
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   228
                ds.normallookup(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   229
                continue
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   230
            ds.remove(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   231
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   232
        for f in r:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   233
            # These are files which are removed between oldctx and ctx, which
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   234
            # means the files which were added in oldctx and were completely
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   235
            # uncommitted in ctx. If a added file is partially uncommitted, that
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   236
            # would have resulted in modified status, not removed.
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   237
            # So a file added in a commit, and uncommitting that addition must
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   238
            # result in file being stated as unknown.
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   239
            if ds[f] == 'r':
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   240
                # The working directory say it's removed, so lets make the file
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   241
                # unknown
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   242
                ds.drop(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   243
                continue
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   244
            ds.add(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   245
    else:
2942
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   246
        m, a, r = repo.status(oldctx.p1(), oldctx, match=match)[:3]
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   247
        for f in m:
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   248
            if ds[f] == 'r':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   249
                # modified + removed -> removed
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   250
                continue
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   251
            ds.normallookup(f)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   252
2942
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   253
        for f in a:
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   254
            if ds[f] == 'r':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   255
                # added + removed -> unknown
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   256
                ds.drop(f)
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   257
            elif ds[f] != 'a':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   258
                ds.add(f)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   259
2942
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   260
        for f in r:
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   261
            if ds[f] == 'a':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   262
                # removed + added -> normal
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   263
                ds.normallookup(f)
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   264
            elif ds[f] != 'r':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   265
                ds.remove(f)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   266
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   267
    # Merge old parent and old working dir copies
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   268
    oldcopies = {}
2943
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   269
    if interactive:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   270
        # Interactive had different meaning of the variables so restoring the
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   271
        # original meaning to use them
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   272
        m, a, r = repo.status(oldctx.p1(), oldctx, match=match)[:3]
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   273
    for f in (m + a):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   274
        src = oldctx[f].renamed()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   275
        if src:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   276
            oldcopies[f] = src[0]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   277
    oldcopies.update(copies)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   278
    copies = dict((dst, oldcopies.get(src, src))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   279
                  for dst, src in oldcopies.iteritems())
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   280
    # Adjust the dirstate copies
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   281
    for dst, src in copies.iteritems():
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   282
        if (src not in ctx or dst in ctx or ds[dst] != 'a'):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   283
            src = None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   284
        ds.copy(src, dst)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   285
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   286
@eh.command(
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   287
    '^uncommit',
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   288
    [('a', 'all', None, _('uncommit all changes when no arguments given')),
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   289
     ('i', 'interactive', False, _('interactive mode to uncommit (EXPERIMENTAL)')),
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   290
     ('r', 'rev', '', _('revert commit content to REV instead')),
2729
69fe16428b0f uncommit: add support for -U and -D
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2728
diff changeset
   291
     ] + commands.walkopts + commitopts + commitopts2 + commitopts3,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   292
    _('[OPTION]... [NAME]'))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   293
def uncommit(ui, repo, *pats, **opts):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   294
    """move changes from parent revision to working directory
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   295
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   296
    Changes to selected files in the checked out revision appear again as
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   297
    uncommitted changed in the working directory. A new revision
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   298
    without the selected changes is created, becomes the checked out
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   299
    revision, and obsoletes the previous one.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   300
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   301
    The --include option specifies patterns to uncommit.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   302
    The --exclude option specifies patterns to keep in the commit.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   303
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   304
    The --rev argument let you change the commit file to a content of another
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   305
    revision. It still does not change the content of your file in the working
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   306
    directory.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   307
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   308
    .. container:: verbose
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   309
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   310
       The --interactive option lets you select hunks interactively to uncommit.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   311
       You can uncommit parts of file using this option.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   312
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   313
    Return 0 if changed files are uncommitted.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   314
    """
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   315
2729
69fe16428b0f uncommit: add support for -U and -D
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2728
diff changeset
   316
    _resolveoptions(ui, opts) # process commitopts3
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   317
    interactive = opts.get('interactive')
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   318
    wlock = lock = tr = None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   319
    try:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   320
        wlock = repo.wlock()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   321
        lock = repo.lock()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   322
        wctx = repo[None]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   323
        if len(wctx.parents()) <= 0:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   324
            raise error.Abort(_("cannot uncommit null changeset"))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   325
        if len(wctx.parents()) > 1:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   326
            raise error.Abort(_("cannot uncommit while merging"))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   327
        old = repo['.']
2788
554c069cdc85 uncommit: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2787
diff changeset
   328
        rewriteutil.precheck(repo, [repo['.'].rev()], action='uncommit')
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   329
        if len(old.parents()) > 1:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   330
            raise error.Abort(_("cannot uncommit merge changeset"))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   331
        oldphase = old.phase()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   332
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   333
        rev = None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   334
        if opts.get('rev'):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   335
            rev = scmutil.revsingle(repo, opts.get('rev'))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   336
            ctx = repo[None]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   337
            if ctx.p1() == rev or ctx.p2() == rev:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   338
                raise error.Abort(_("cannot uncommit to parent changeset"))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   339
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   340
        onahead = old.rev() in repo.changelog.headrevs()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   341
        disallowunstable = not obsolete.isenabled(repo,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   342
                                                  obsolete.allowunstableopt)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   343
        if disallowunstable and not onahead:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   344
            raise error.Abort(_("cannot uncommit in the middle of a stack"))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   345
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   346
        # Recommit the filtered changeset
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   347
        tr = repo.transaction('uncommit')
2756
f4dd6e6d4c73 rewriteutil: create a rewriteutil module to host utility function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2752
diff changeset
   348
        updatebookmarks = rewriteutil.bookmarksupdater(repo, old.node(), tr)
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   349
        if interactive:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   350
            opts['all'] = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   351
            match = scmutil.match(old, pats, opts)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   352
            newid = _interactiveuncommit(ui, repo, old, match)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   353
        else:
2940
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   354
            newid = None
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   355
            includeorexclude = opts.get('include') or opts.get('exclude')
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   356
            if (pats or includeorexclude or opts.get('all')):
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   357
                match = scmutil.match(old, pats, opts)
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   358
                if not (opts['message'] or opts['logfile']):
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   359
                    opts['message'] = old.description()
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   360
                message = cmdutil.logmessage(ui, opts)
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   361
                newid = _commitfiltered(repo, old, match, target=rev,
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   362
                                        message=message, user=opts.get('user'),
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   363
                                        date=opts.get('date'))
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   364
            if newid is None:
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   365
                raise error.Abort(_('nothing to uncommit'),
89b205e5271e uncommit: pre-indent a block in if-True for the next patch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2923
diff changeset
   366
                                  hint=_("use --all to uncommit all files"))
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   367
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   368
        obsolete.createmarkers(repo, [(old, (repo[newid],))])
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   369
        phases.retractboundary(repo, tr, oldphase, [newid])
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   370
        with repo.dirstate.parentchange():
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   371
            repo.dirstate.setparents(newid, node.nullid)
2943
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   372
            _uncommitdirstate(repo, old, match, interactive)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   373
        updatebookmarks(newid)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   374
        if not repo[newid].files():
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   375
            ui.warn(_("new changeset is empty\n"))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   376
            ui.status(_("(use 'hg prune .' to remove it)\n"))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   377
        tr.close()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   378
    finally:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   379
        lockmod.release(tr, lock, wlock)
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   380
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   381
def _interactiveuncommit(ui, repo, old, match):
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   382
    """ The function which contains all the logic for interactively uncommiting
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   383
    a commit. This function makes a temporary commit with the chunks which user
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   384
    selected to uncommit. After that the diff of the parent and that commit is
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   385
    applied to the working directory and committed again which results in the
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   386
    new commit which should be one after uncommitted.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   387
    """
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   388
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   389
    # create a temporary commit with hunks user selected
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   390
    tempnode = _createtempcommit(ui, repo, old, match)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   391
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   392
    diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   393
    diffopts.nodates = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   394
    diffopts.git = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   395
    fp = stringio()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   396
    for chunk, label in patch.diffui(repo, tempnode, old.node(), None,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   397
                                     opts=diffopts):
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   398
            fp.write(chunk)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   399
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   400
    fp.seek(0)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   401
    newnode = _patchtocommit(ui, repo, old, fp)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   402
    # creating obs marker temp -> ()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   403
    obsolete.createmarkers(repo, [(repo[tempnode], ())])
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   404
    return newnode
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   405
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   406
def _createtempcommit(ui, repo, old, match):
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   407
    """ Creates a temporary commit for `uncommit --interative` which contains
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   408
    the hunks which were selected by the user to uncommit.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   409
    """
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   410
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   411
    pold = old.p1()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   412
    # The logic to interactively selecting something copied from
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   413
    # cmdutil.revert()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   414
    diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   415
    diffopts.nodates = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   416
    diffopts.git = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   417
    diff = patch.diff(repo, pold.node(), old.node(), match, opts=diffopts)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   418
    originalchunks = patch.parsepatch(diff)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   419
    # XXX: The interactive selection is buggy and does not let you
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   420
    # uncommit a removed file partially.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   421
    # TODO: wrap the operations in mercurial/patch.py and mercurial/crecord.py
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   422
    # to add uncommit as an operation taking care of BC.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   423
    chunks, opts = cmdutil.recordfilter(repo.ui, originalchunks,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   424
                                        operation='discard')
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   425
    if not chunks:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   426
        raise error.Abort(_("nothing selected to uncommit"))
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   427
    fp = stringio()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   428
    for c in chunks:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   429
            c.write(fp)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   430
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   431
    fp.seek(0)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   432
    oldnode = node.hex(old.node())[:12]
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   433
    message = 'temporary commit for uncommiting %s' % oldnode
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   434
    tempnode = _patchtocommit(ui, repo, old, fp, message, oldnode)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   435
    return tempnode
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   436
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   437
def _patchtocommit(ui, repo, old, fp, message=None, extras=None):
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   438
    """ A function which will apply the patch to the working directory and
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   439
    make a commit whose parents are same as that of old argument. The message
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   440
    argument tells us whether to use the message of the old commit or a
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   441
    different message which is passed. Returns the node of new commit made.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   442
    """
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   443
    pold = old.p1()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   444
    parents = (old.p1().node(), old.p2().node())
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   445
    date = old.date()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   446
    branch = old.branch()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   447
    user = old.user()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   448
    extra = old.extra()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   449
    if extras:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   450
        extra['uncommit_source'] = extras
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   451
    if not message:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   452
        message = old.description()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   453
    store = patch.filestore()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   454
    try:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   455
        files = set()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   456
        try:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   457
            patch.patchrepo(ui, repo, pold, store, fp, 1, '',
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   458
                            files=files, eolmode=None)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   459
        except patch.PatchError as err:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   460
            raise error.Abort(str(err))
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   461
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   462
        finally:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   463
            del fp
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   464
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   465
        memctx = context.memctx(repo, parents, message, files=files,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   466
                                filectxfn=store,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   467
                                user=user,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   468
                                date=date,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   469
                                branch=branch,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   470
                                extra=extra)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   471
        newcm = memctx.commit()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   472
    finally:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   473
        store.close()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   474
    return newcm
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   475
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   476
@eh.command(
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   477
    '^fold|squash',
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   478
    [('r', 'rev', [], _("revision to fold")),
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   479
     ('', 'exact', None, _("only fold specified revisions")),
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   480
     ('', 'from', None, _("fold revisions linearly to working copy parent"))
2768
85e5a56db776 fold: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2766
diff changeset
   481
    ] + commitopts + commitopts2 + commitopts3,
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   482
    _('hg fold [OPTION]... [-r] REV'))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   483
def fold(ui, repo, *revs, **opts):
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   484
    """fold multiple revisions into a single one
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   485
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   486
    With --from, folds all the revisions linearly between the given revisions
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   487
    and the parent of the working directory.
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   488
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   489
    With --exact, folds only the specified revisions while ignoring the
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   490
    parent of the working directory. In this case, the given revisions must
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   491
    form a linear unbroken chain.
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   492
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   493
    .. container:: verbose
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   494
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   495
     Some examples:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   496
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   497
     - Fold the current revision with its parent::
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   498
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   499
         hg fold --from .^
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   500
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   501
     - Fold all draft revisions with working directory parent::
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   502
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   503
         hg fold --from 'draft()'
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   504
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   505
       See :hg:`help phases` for more about draft revisions and
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   506
       :hg:`help revsets` for more about the `draft()` keyword
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   507
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   508
     - Fold revisions between 3 and 6 with the working directory parent::
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   509
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   510
         hg fold --from 3::6
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   511
2923
8c2d3c474fc6 doc: make paragraphs before example code end with "::" for reST syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2790
diff changeset
   512
     - Fold revisions 3 and 4::
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   513
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   514
        hg fold "3 + 4" --exact
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   515
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   516
     - Only fold revisions linearly between foo and @::
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   517
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   518
         hg fold foo::@ --exact
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   519
    """
2768
85e5a56db776 fold: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2766
diff changeset
   520
    _resolveoptions(ui, opts)
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   521
    revs = list(revs)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   522
    revs.extend(opts['rev'])
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   523
    if not revs:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   524
        raise error.Abort(_('no revisions specified'))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   525
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   526
    revs = scmutil.revrange(repo, revs)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   527
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   528
    if opts['from'] and opts['exact']:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   529
        raise error.Abort(_('cannot use both --from and --exact'))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   530
    elif opts['from']:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   531
        # Try to extend given revision starting from the working directory
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   532
        extrevs = repo.revs('(%ld::.) or (.::%ld)', revs, revs)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   533
        discardedrevs = [r for r in revs if r not in extrevs]
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   534
        if discardedrevs:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   535
            msg = _("cannot fold non-linear revisions")
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   536
            hint = _("given revisions are unrelated to parent of working"
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   537
                     " directory")
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   538
            raise error.Abort(msg, hint=hint)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   539
        revs = extrevs
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   540
    elif opts['exact']:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   541
        # Nothing to do; "revs" is already set correctly
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   542
        pass
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   543
    else:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   544
        raise error.Abort(_('must specify either --from or --exact'))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   545
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   546
    if not revs:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   547
        raise error.Abort(_('specified revisions evaluate to an empty set'),
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   548
                          hint=_('use different revision arguments'))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   549
    elif len(revs) == 1:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   550
        ui.write_err(_('single revision specified, nothing to fold\n'))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   551
        return 1
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   552
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   553
    wlock = lock = None
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   554
    try:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   555
        wlock = repo.wlock()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   556
        lock = repo.lock()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   557
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   558
        root, head = rewriteutil.foldcheck(repo, revs)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   559
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   560
        tr = repo.transaction('fold')
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   561
        try:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   562
            commitopts = opts.copy()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   563
            allctx = [repo[r] for r in revs]
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   564
            targetphase = max(c.phase() for c in allctx)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   565
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   566
            if commitopts.get('message') or commitopts.get('logfile'):
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   567
                commitopts['edit'] = False
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   568
            else:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   569
                msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   570
                msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   571
                         (c.rev(), c.description()) for c in allctx]
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   572
                commitopts['message'] = "\n".join(msgs)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   573
                commitopts['edit'] = True
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   574
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   575
            newid, unusedvariable = rewriteutil.rewrite(repo, root, allctx,
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   576
                                                        head,
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   577
                                                        [root.p1().node(),
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   578
                                                         root.p2().node()],
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   579
                                                        commitopts=commitopts)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   580
            phases.retractboundary(repo, tr, targetphase, [newid])
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   581
            obsolete.createmarkers(repo, [(ctx, (repo[newid],))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   582
                                   for ctx in allctx])
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   583
            tr.close()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   584
        finally:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   585
            tr.release()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   586
        ui.status('%i changesets folded\n' % len(revs))
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   587
        if repo['.'].rev() in revs:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   588
            hg.update(repo, newid)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   589
    finally:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   590
        lockmod.release(lock, wlock)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   591
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   592
@eh.command(
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   593
    '^metaedit',
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   594
    [('r', 'rev', [], _("revision to edit")),
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   595
     ('', 'fold', None, _("also fold specified revisions into one")),
2769
b96349ae3e2a metaedit: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2768
diff changeset
   596
    ] + commitopts + commitopts2 + commitopts3,
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   597
    _('hg metaedit [OPTION]... [-r] [REV]'))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   598
def metaedit(ui, repo, *revs, **opts):
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   599
    """edit commit information
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   600
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   601
    Edits the commit information for the specified revisions. By default, edits
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   602
    commit information for the working directory parent.
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   603
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   604
    With --fold, also folds multiple revisions into one if necessary. In this
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   605
    case, the given revisions must form a linear unbroken chain.
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   606
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   607
    .. container:: verbose
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   608
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   609
     Some examples:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   610
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   611
     - Edit the commit message for the working directory parent::
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   612
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   613
         hg metaedit
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   614
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   615
     - Change the username for the working directory parent::
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   616
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   617
         hg metaedit --user 'New User <new-email@example.com>'
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   618
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   619
     - Combine all draft revisions that are ancestors of foo but not of @ into
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   620
       one::
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   621
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   622
         hg metaedit --fold 'draft() and only(foo,@)'
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   623
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   624
       See :hg:`help phases` for more about draft revisions, and
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   625
       :hg:`help revsets` for more about the `draft()` and `only()` keywords.
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   626
    """
2769
b96349ae3e2a metaedit: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2768
diff changeset
   627
    _resolveoptions(ui, opts)
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   628
    revs = list(revs)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   629
    revs.extend(opts['rev'])
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   630
    if not revs:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   631
        if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   632
            raise error.Abort(_('revisions must be specified with --fold'))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   633
        revs = ['.']
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   634
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   635
    wlock = lock = None
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   636
    try:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   637
        wlock = repo.wlock()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   638
        lock = repo.lock()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   639
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   640
        revs = scmutil.revrange(repo, revs)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   641
        if not opts['fold'] and len(revs) > 1:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   642
            # TODO: handle multiple revisions. This is somewhat tricky because
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   643
            # if we want to edit a series of commits:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   644
            #
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   645
            #   a ---- b ---- c
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   646
            #
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   647
            # we need to rewrite a first, then directly rewrite b on top of the
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   648
            # new a, then rewrite c on top of the new b. So we need to handle
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   649
            # revisions in topological order.
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   650
            raise error.Abort(_('editing multiple revisions without --fold is '
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   651
                                'not currently supported'))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   652
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   653
        if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   654
            root, head = rewriteutil.foldcheck(repo, revs)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   655
        else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   656
            if repo.revs("%ld and public()", revs):
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   657
                raise error.Abort(_('cannot edit commit information for public '
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   658
                                    'revisions'))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   659
            newunstable = rewriteutil.disallowednewunstable(repo, revs)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   660
            if newunstable:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   661
                msg = _('cannot edit commit information in the middle'
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   662
                        ' of a stack')
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   663
                hint = _('%s will become unstable and new unstable changes'
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   664
                         ' are not allowed')
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   665
                hint %= repo[newunstable.first()]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   666
                raise error.Abort(msg, hint=hint)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   667
            root = head = repo[revs.first()]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   668
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   669
        wctx = repo[None]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   670
        p1 = wctx.p1()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   671
        tr = repo.transaction('metaedit')
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   672
        newp1 = None
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   673
        try:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   674
            commitopts = opts.copy()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   675
            allctx = [repo[r] for r in revs]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   676
            targetphase = max(c.phase() for c in allctx)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   677
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   678
            if commitopts.get('message') or commitopts.get('logfile'):
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   679
                commitopts['edit'] = False
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   680
            else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   681
                if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   682
                    msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   683
                    msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   684
                             (c.rev(), c.description()) for c in allctx]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   685
                else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   686
                    msgs = [head.description()]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   687
                commitopts['message'] = "\n".join(msgs)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   688
                commitopts['edit'] = True
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   689
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   690
            # TODO: if the author and message are the same, don't create a new
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   691
            # hash. Right now we create a new hash because the date can be
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   692
            # different.
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   693
            newid, created = rewriteutil.rewrite(repo, root, allctx, head,
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   694
                                                 [root.p1().node(),
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   695
                                                  root.p2().node()],
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   696
                                                 commitopts=commitopts)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   697
            if created:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   698
                if p1.rev() in revs:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   699
                    newp1 = newid
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   700
                phases.retractboundary(repo, tr, targetphase, [newid])
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   701
                obsolete.createmarkers(repo, [(ctx, (repo[newid],))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   702
                                              for ctx in allctx])
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   703
            else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   704
                ui.status(_("nothing changed\n"))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   705
            tr.close()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   706
        finally:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   707
            tr.release()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   708
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   709
        if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   710
            ui.status('%i changesets folded\n' % len(revs))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   711
        if newp1 is not None:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   712
            hg.update(repo, newp1)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   713
    finally:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   714
        lockmod.release(lock, wlock)
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   715
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   716
metadataopts = [
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   717
    ('d', 'date', '',
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   718
     _('record the specified date in metadata'), _('DATE')),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   719
    ('u', 'user', '',
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   720
     _('record the specified user in metadata'), _('USER')),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   721
]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   722
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   723
def _getmetadata(**opts):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   724
    metadata = {}
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   725
    date = opts.get('date')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   726
    user = opts.get('user')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   727
    if date:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   728
        metadata['date'] = '%i %i' % util.parsedate(date)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   729
    if user:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   730
        metadata['user'] = user
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   731
    return metadata
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   732
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   733
@eh.command(
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   734
    '^prune|obsolete',
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   735
    [('n', 'new', [], _("successor changeset (DEPRECATED)")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   736
     ('s', 'succ', [], _("successor changeset")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   737
     ('r', 'rev', [], _("revisions to prune")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   738
     ('k', 'keep', None, _("does not modify working copy during prune")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   739
     ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   740
     ('', 'fold', False,
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   741
      _("record a fold (multiple precursors, one successors)")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   742
     ('', 'split', False,
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   743
      _("record a split (on precursor, multiple successors)")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   744
     ('B', 'bookmark', [], _("remove revs only reachable from given"
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   745
                             " bookmark"))] + metadataopts,
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   746
    _('[OPTION] [-r] REV...'))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   747
# XXX -U  --noupdate option to prevent wc update and or bookmarks update ?
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   748
def cmdprune(ui, repo, *revs, **opts):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   749
    """hide changesets by marking them obsolete
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   750
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   751
    Pruned changesets are obsolete with no successors. If they also have no
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   752
    descendants, they are hidden (invisible to all commands).
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   753
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   754
    Non-obsolete descendants of pruned changesets become "unstable". Use :hg:`evolve`
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   755
    to handle this situation.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   756
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   757
    When you prune the parent of your working copy, Mercurial updates the working
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   758
    copy to a non-obsolete parent.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   759
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   760
    You can use ``--succ`` to tell Mercurial that a newer version (successor) of the
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   761
    pruned changeset exists. Mercurial records successor revisions in obsolescence
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   762
    markers.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   763
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   764
    You can use the ``--biject`` option to specify a 1-1 mapping (bijection) between
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   765
    revisions to pruned (precursor) and successor changesets. This option may be
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   766
    removed in a future release (with the functionality provided automatically).
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   767
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   768
    If you specify multiple revisions in ``--succ``, you are recording a "split" and
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   769
    must acknowledge it by passing ``--split``. Similarly, when you prune multiple
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   770
    changesets with a single successor, you must pass the ``--fold`` option.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   771
    """
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   772
    revs = scmutil.revrange(repo, list(revs) + opts.get('rev'))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   773
    succs = opts['new'] + opts['succ']
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   774
    bookmarks = set(opts.get('bookmark'))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   775
    metadata = _getmetadata(**opts)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   776
    biject = opts.get('biject')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   777
    fold = opts.get('fold')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   778
    split = opts.get('split')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   779
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   780
    options = [o for o in ('biject', 'fold', 'split') if opts.get(o)]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   781
    if 1 < len(options):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   782
        raise error.Abort(_("can only specify one of %s") % ', '.join(options))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   783
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   784
    if bookmarks:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   785
        reachablefrombookmark = rewriteutil.reachablefrombookmark
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   786
        repomarks, revs = reachablefrombookmark(repo, revs, bookmarks)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   787
        if not revs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   788
            # no revisions to prune - delete bookmark immediately
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   789
            rewriteutil.deletebookmark(repo, repomarks, bookmarks)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   790
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   791
    if not revs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   792
        raise error.Abort(_('nothing to prune'))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   793
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   794
    wlock = lock = tr = None
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   795
    try:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   796
        wlock = repo.wlock()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   797
        lock = repo.lock()
2789
06ee4ec88190 prune: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2788
diff changeset
   798
        rewriteutil.precheck(repo, revs, 'touch')
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   799
        tr = repo.transaction('prune')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   800
        # defines pruned changesets
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   801
        precs = []
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   802
        revs.sort()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   803
        for p in revs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   804
            cp = repo[p]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   805
            precs.append(cp)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   806
        if not precs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   807
            raise error.Abort('nothing to prune')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   808
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   809
        # defines successors changesets
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   810
        sucs = scmutil.revrange(repo, succs)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   811
        sucs.sort()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   812
        sucs = tuple(repo[n] for n in sucs)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   813
        if not biject and len(sucs) > 1 and len(precs) > 1:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   814
            msg = "Can't use multiple successors for multiple precursors"
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   815
            hint = _("use --biject to mark a series as a replacement"
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   816
                     " for another")
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   817
            raise error.Abort(msg, hint=hint)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   818
        elif biject and len(sucs) != len(precs):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   819
            msg = "Can't use %d successors for %d precursors" \
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   820
                % (len(sucs), len(precs))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   821
            raise error.Abort(msg)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   822
        elif (len(precs) == 1 and len(sucs) > 1) and not split:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   823
            msg = "please add --split if you want to do a split"
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   824
            raise error.Abort(msg)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   825
        elif len(sucs) == 1 and len(precs) > 1 and not fold:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   826
            msg = "please add --fold if you want to do a fold"
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   827
            raise error.Abort(msg)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   828
        elif biject:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   829
            relations = [(p, (s,)) for p, s in zip(precs, sucs)]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   830
        else:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   831
            relations = [(p, sucs) for p in precs]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   832
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   833
        wdp = repo['.']
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   834
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   835
        if len(sucs) == 1 and len(precs) == 1 and wdp in precs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   836
            # '.' killed, so update to the successor
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   837
            newnode = sucs[0]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   838
        else:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   839
            # update to an unkilled parent
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   840
            newnode = wdp
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   841
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   842
            while newnode in precs or newnode.obsolete():
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   843
                newnode = newnode.parents()[0]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   844
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   845
        if newnode.node() != wdp.node():
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   846
            if opts.get('keep', False):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   847
                # This is largely the same as the implementation in
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   848
                # strip.stripcmd(). We might want to refactor this somewhere
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   849
                # common at some point.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   850
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   851
                # only reset the dirstate for files that would actually change
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   852
                # between the working context and uctx
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   853
                descendantrevs = repo.revs("%d::." % newnode.rev())
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   854
                changedfiles = []
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   855
                for rev in descendantrevs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   856
                    # blindly reset the files, regardless of what actually
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   857
                    # changed
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   858
                    changedfiles.extend(repo[rev].files())
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   859
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   860
                # reset files that only changed in the dirstate too
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   861
                dirstate = repo.dirstate
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   862
                dirchanges = [f for f in dirstate if dirstate[f] != 'n']
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   863
                changedfiles.extend(dirchanges)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   864
                repo.dirstate.rebuild(newnode.node(), newnode.manifest(),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   865
                                      changedfiles)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   866
                dirstate.write(tr)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   867
            else:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   868
                bookactive = repo._activebookmark
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   869
                # Active bookmark that we don't want to delete (with -B option)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   870
                # we deactivate and move it before the update and reactivate it
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   871
                # after
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   872
                movebookmark = bookactive and not bookmarks
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   873
                if movebookmark:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   874
                    bookmarksmod.deactivate(repo)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   875
                    bmchanges = [(bookactive, newnode.node())]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   876
                    compat.bookmarkapplychanges(repo, tr, bmchanges)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   877
                commands.update(ui, repo, newnode.rev())
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   878
                ui.status(_('working directory now at %s\n')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   879
                          % ui.label(str(newnode), 'evolve.node'))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   880
                if movebookmark:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   881
                    bookmarksmod.activate(repo, bookactive)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   882
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   883
        # update bookmarks
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   884
        if bookmarks:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   885
            rewriteutil.deletebookmark(repo, repomarks, bookmarks)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   886
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   887
        # create markers
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   888
        obsolete.createmarkers(repo, relations, metadata=metadata)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   889
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   890
        # informs that changeset have been pruned
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   891
        ui.status(_('%i changesets pruned\n') % len(precs))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   892
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   893
        for ctx in repo.unfiltered().set('bookmark() and %ld', precs):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   894
            # used to be:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   895
            #
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   896
            #   ldest = list(repo.set('max((::%d) - obsolete())', ctx))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   897
            #   if ldest:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   898
            #      c = ldest[0]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   899
            #
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   900
            # but then revset took a lazy arrow in the knee and became much
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   901
            # slower. The new forms makes as much sense and a much faster.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   902
            for dest in ctx.ancestors():
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   903
                if not dest.obsolete():
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   904
                    bookmarksupdater = rewriteutil.bookmarksupdater
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   905
                    updatebookmarks = bookmarksupdater(repo, ctx.node(), tr)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   906
                    updatebookmarks(dest.node())
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   907
                    break
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   908
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   909
        tr.close()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   910
    finally:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   911
        lockmod.release(tr, lock, wlock)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   912
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   913
@eh.command(
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   914
    '^split',
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   915
    [('r', 'rev', [], _("revision to split")),
2771
6044bd16bfb7 split: add support for the -D and -U option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2770
diff changeset
   916
    ] + commitopts + commitopts2 + commitopts3,
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   917
    _('hg split [OPTION]... [-r] REV'))
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   918
def cmdsplit(ui, repo, *revs, **opts):
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   919
    """split a changeset into smaller changesets
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   920
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   921
    By default, split the current revision by prompting for all its hunks to be
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   922
    redistributed into new changesets.
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   923
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   924
    Use --rev to split a given changeset instead.
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   925
    """
2771
6044bd16bfb7 split: add support for the -D and -U option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2770
diff changeset
   926
    _resolveoptions(ui, opts)
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   927
    tr = wlock = lock = None
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   928
    newcommits = []
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   929
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   930
    revarg = (list(revs) + opts.get('rev')) or ['.']
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   931
    if len(revarg) != 1:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   932
        msg = _("more than one revset is given")
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   933
        hnt = _("use either `hg split <rs>` or `hg split --rev <rs>`, not both")
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   934
        raise error.Abort(msg, hint=hnt)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   935
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   936
    try:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   937
        wlock = repo.wlock()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   938
        lock = repo.lock()
2774
0f167320f90f split: compute revision to split after locking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2773
diff changeset
   939
        rev = scmutil.revsingle(repo, revarg[0])
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   940
        cmdutil.bailifchanged(repo)
2786
ae690d39fc92 split: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2774
diff changeset
   941
        rewriteutil.precheck(repo, [rev], action='split')
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   942
        tr = repo.transaction('split')
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   943
        ctx = repo[rev]
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   944
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   945
        if len(ctx.parents()) > 1:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   946
            raise error.Abort(_("cannot split merge commits"))
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   947
        prev = ctx.p1()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   948
        bmupdate = rewriteutil.bookmarksupdater(repo, ctx.node(), tr)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   949
        bookactive = repo._activebookmark
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   950
        if bookactive is not None:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   951
            repo.ui.status(_("(leaving bookmark %s)\n") % repo._activebookmark)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   952
        bookmarksmod.deactivate(repo)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   953
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   954
        # Prepare the working directory
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   955
        rewriteutil.presplitupdate(repo, ui, prev, ctx)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   956
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   957
        def haschanges():
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   958
            modified, added, removed, deleted = repo.status()[:4]
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   959
            return modified or added or removed or deleted
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   960
        msg = ("HG: This is the original pre-split commit message. "
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   961
               "Edit it as appropriate.\n\n")
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   962
        msg += ctx.description()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   963
        opts['message'] = msg
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   964
        opts['edit'] = True
2770
a9ea16a1f4dc split: fix the --user option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2769
diff changeset
   965
        if not opts['user']:
a9ea16a1f4dc split: fix the --user option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2769
diff changeset
   966
            opts['user'] = ctx.user()
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   967
        while haschanges():
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   968
            pats = ()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   969
            cmdutil.dorecord(ui, repo, commands.commit, 'commit', False,
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   970
                             cmdutil.recordfilter, *pats, **opts)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   971
            # TODO: Does no seem like the best way to do this
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   972
            # We should make dorecord return the newly created commit
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   973
            newcommits.append(repo['.'])
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   974
            if haschanges():
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   975
                if ui.prompt('Done splitting? [yN]', default='n') == 'y':
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   976
                    commands.commit(ui, repo, **opts)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   977
                    newcommits.append(repo['.'])
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   978
                    break
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   979
            else:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   980
                ui.status(_("no more change to split\n"))
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   981
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   982
        if newcommits:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   983
            tip = repo[newcommits[-1]]
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   984
            bmupdate(tip.node())
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   985
            if bookactive is not None:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   986
                bookmarksmod.activate(repo, bookactive)
2773
9e363e8c1c06 split: basic code cleanup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2772
diff changeset
   987
            obsolete.createmarkers(repo, [(repo[rev], newcommits)])
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   988
        tr.close()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   989
    finally:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
   990
        lockmod.release(tr, lock, wlock)
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   991
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   992
@eh.command(
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   993
    '^touch',
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   994
    [('r', 'rev', [], 'revision to update'),
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   995
     ('D', 'duplicate', False,
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   996
      'do not mark the new revision as successor of the old one'),
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   997
     ('A', 'allowdivergence', False,
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   998
      'mark the new revision as successor of the old one potentially creating '
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
   999
      'divergence')],
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1000
    # allow to choose the seed ?
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1001
    _('[-r] revs'))
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1002
def touch(ui, repo, *revs, **opts):
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1003
    """create successors that are identical to their predecessors except
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1004
    for the changeset ID
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1005
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1006
    This is used to "resurrect" changesets
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1007
    """
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1008
    duplicate = opts['duplicate']
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1009
    allowdivergence = opts['allowdivergence']
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1010
    revs = list(revs)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1011
    revs.extend(opts['rev'])
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1012
    if not revs:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1013
        revs = ['.']
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1014
    revs = scmutil.revrange(repo, revs)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1015
    if not revs:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1016
        ui.write_err('no revision to touch\n')
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1017
        return 1
2790
1b7b9acda2a9 touch: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2789
diff changeset
  1018
    if not duplicate:
1b7b9acda2a9 touch: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2789
diff changeset
  1019
        rewriteutil.precheck(repo, revs, touch)
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1020
    tmpl = utility.shorttemplate
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1021
    displayer = cmdutil.show_changeset(ui, repo, {'template': tmpl})
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1022
    wlock = lock = tr = None
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1023
    try:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1024
        wlock = repo.wlock()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1025
        lock = repo.lock()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1026
        tr = repo.transaction('touch')
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1027
        revs.sort() # ensure parent are run first
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1028
        newmapping = {}
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1029
        for r in revs:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1030
            ctx = repo[r]
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1031
            extra = ctx.extra().copy()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1032
            extra['__touch-noise__'] = random.randint(0, 0xffffffff)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1033
            # search for touched parent
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1034
            p1 = ctx.p1().node()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1035
            p2 = ctx.p2().node()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1036
            p1 = newmapping.get(p1, p1)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1037
            p2 = newmapping.get(p2, p2)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1038
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1039
            if not (duplicate or allowdivergence):
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1040
                # The user hasn't yet decided what to do with the revived
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1041
                # cset, let's ask
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1042
                sset = compat.successorssets(repo, ctx.node())
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1043
                nodivergencerisk = (len(sset) == 0 or
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1044
                                    (len(sset) == 1 and
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1045
                                     len(sset[0]) == 1 and
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1046
                                     repo[sset[0][0]].rev() == ctx.rev()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1047
                                    ))
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1048
                if nodivergencerisk:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1049
                    duplicate = False
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1050
                else:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1051
                    displayer.show(ctx)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1052
                    index = ui.promptchoice(
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1053
                        _("reviving this changeset will create divergence"
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1054
                          " unless you make a duplicate.\n(a)llow divergence or"
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1055
                          " (d)uplicate the changeset? $$ &Allowdivergence $$ "
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1056
                          "&Duplicate"), 0)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1057
                    choice = ['allowdivergence', 'duplicate'][index]
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1058
                    if choice == 'allowdivergence':
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1059
                        duplicate = False
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1060
                    else:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1061
                        duplicate = True
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1062
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1063
            extradict = {'extra': extra}
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1064
            new, unusedvariable = rewriteutil.rewrite(repo, ctx, [], ctx,
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1065
                                                      [p1, p2],
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1066
                                                      commitopts=extradict)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1067
            # store touched version to help potential children
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1068
            newmapping[ctx.node()] = new
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1069
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1070
            if not duplicate:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1071
                obsolete.createmarkers(repo, [(ctx, (repo[new],))])
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1072
            phases.retractboundary(repo, tr, ctx.phase(), [new])
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1073
            if ctx in repo[None].parents():
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1074
                with repo.dirstate.parentchange():
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1075
                    repo.dirstate.setparents(new, node.nullid)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1076
        tr.close()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1077
    finally:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1078
        lockmod.release(tr, lock, wlock)