hgext3rd/evolve/cmdrewrite.py
author Pulkit Goyal <7895pulkit@gmail.com>
Sun, 18 Mar 2018 23:48:06 +0530
changeset 3660 f018656ca3bf
parent 3616 f6d629514607
child 3661 61fdd25542a6
permissions -rw-r--r--
amend: add a new flag `--patch` to `hg amend` This patch adds a new flag `--patch` to `hg amend` which pops up an editor with the patch of working directory parent which you can change, and when you exit the editor the patch with changes is applied to current working directory with old changeset being obsoleted in favour of new one created by the applied patch. If supplied filenames, only those filenames are present in the popped editor and rest files stay the same way in the commit as they were. The extension of the file which opens up in editor is '.diff', we cannot have it as '.patch' as there will be develwarns related to that. We need to change to patch core and undo some change to achieve this. The implementation does not use any core API rather it has picked chunks from API which are required. One main reason to not use core import API is that we have to change wdir parent before using patch.patch() which I will like to avoid to make sure we handle merge cases too. While writing this patch I have spend lot of time try to use internal API's to work for this but none of them served the purpose well. If I have time in future and work on similar problem again, I am going to write better high-level API's which uses patchstore to achieve this. A new test file test-amend-patch.t which contains a lot of testing of the feature.
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,
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
    25
    merge,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    26
    node,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    27
    obsolete,
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
    28
    patch,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    29
    phases,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
    30
    scmutil,
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    31
    util,
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
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    34
from mercurial.i18n import _
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
3660
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
    36
from mercurial.utils import dateutil
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
    37
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    38
from . import (
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
    39
    compat,
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
    40
    state,
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    41
    exthelper,
2756
f4dd6e6d4c73 rewriteutil: create a rewriteutil module to host utility function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2752
diff changeset
    42
    rewriteutil,
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
    43
    utility,
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
)
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
eh = exthelper.exthelper()
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    47
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    48
walkopts = commands.walkopts
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    49
commitopts = commands.commitopts
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
commitopts2 = commands.commitopts2
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    51
mergetoolopts = commands.mergetoolopts
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
    52
stringio = util.stringio
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    53
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    54
# option added by evolve
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    55
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
    56
def _checknotesize(ui, opts):
3213
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    57
    """ make sure note is of valid format """
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    58
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    59
    note = opts.get('note')
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    60
    if not note:
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    61
        return
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    62
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
    63
    if not compat.isobsnotesupported():
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
    64
        ui.warn(_("current hg version does not support storing"
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
    65
                  " note in obsmarker\n"))
3213
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    66
    if len(note) > 255:
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    67
        raise error.Abort(_("cannot store a note of more than 255 bytes"))
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    68
    if '\n' in note:
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    69
        raise error.Abort(_("note cannot contain a newline"))
7bc587557e4f cmdrewrite: add a utility function to make sure note is of valid format
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2949
diff changeset
    70
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    71
def _resolveoptions(ui, opts):
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    72
    """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
    73
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    74
    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
    75
    -d was supplied.
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    76
    """
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    77
    # 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
    78
    if not opts.get('date') and opts.get('current_date'):
3514
498f782ccb4b compat: add compat layer for date related functions
Boris Feld <boris.feld@octobus.net>
parents: 3506
diff changeset
    79
        opts['date'] = '%d %d' % compat.makedate()
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    80
    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
    81
        opts['user'] = ui.username()
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
commitopts3 = [
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    84
    ('D', 'current-date', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
     _('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
    86
    ('U', 'current-user', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    87
     _('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
    88
]
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    89
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    90
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
    91
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    92
@eh.command(
3231
996dabc4224b help: promote "amend" to important command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3230
diff changeset
    93
    '^amend|refresh',
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    94
    [('A', 'addremove', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    95
      _('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
    96
     ('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
    97
     ('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
    98
     ('', 'extract', False, _('extract changes from the commit to the working copy')),
3660
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
    99
     ('', 'patch', False, _('make changes to wdir parent by editing patch')),
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   100
     ('', 'close-branch', None,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   101
      _('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
   102
     ('s', 'secret', None, _('use the secret phase for committing')),
3221
9f3521cc4c90 amend: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3220
diff changeset
   103
     ('n', 'note', '', _('store a note on amend')),
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   104
    ] + walkopts + commitopts + commitopts2 + commitopts3 + interactiveopt,
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   105
    _('[OPTION]... [FILE]...'))
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   106
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
   107
    """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
   108
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   109
    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
   110
    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
   111
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   112
    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
   113
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   114
    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
   115
3296
b834cb64f779 amend: fix a typo in amend help text related to the extract option
Boris Feld <boris.feld@octobus.net>
parents: 3283
diff changeset
   116
    If --extract is specified, the behavior of `hg amend` is reversed: Changes
2730
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   117
    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
   118
    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
   119
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   120
    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
   121
    """
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
   122
    _checknotesize(ui, opts)
2724
e6bc6eaa17c5 amend: extract into a 'evolve.evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   123
    opts = opts.copy()
3660
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   124
    if opts.get('patch'):
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   125
        return amendpatch(ui, repo, *pats, **opts)
2730
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   126
    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
   127
        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
   128
    else:
7fbb7a5d359f uncommit: expose the feature with a '--extract' to amend
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2729
diff changeset
   129
        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
   130
            # 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
   131
            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
   132
            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
   133
        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
   134
        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
   135
        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
   136
        _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
   137
        _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
   138
        try:
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   139
            wlock = repo.wlock()
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   140
            lock = repo.lock()
3452
8275ef099135 amend: query the wdir parent after taking lock (issue5266)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3451
diff changeset
   141
            if not (edit or opts['message'] or log):
8275ef099135 amend: query the wdir parent after taking lock (issue5266)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3451
diff changeset
   142
                opts['message'] = repo['.'].description()
2787
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   143
            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
   144
            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
   145
        finally:
ebca049e8ca9 amend: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2786
diff changeset
   146
            lockmod.release(lock, wlock)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   147
3660
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   148
def amendpatch(ui, repo, *pats, **opts):
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   149
    """logic for --patch flag of `hg amend` command."""
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   150
    lock = wlock = tr = None
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   151
    try:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   152
        wlock = repo.wlock()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   153
        lock = repo.lock()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   154
        tr = repo.transaction('amend')
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   155
        cmdutil.bailifchanged(repo)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   156
        # first get the patch
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   157
        old = repo['.']
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   158
        p1 = old.p1()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   159
        rewriteutil.precheck(repo, [old.rev()], 'amend')
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   160
        bookmarkupdater = rewriteutil.bookmarksupdater(repo, old.node(), tr)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   161
        diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   162
        diffopts.nodates = True
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   163
        diffopts.git = True
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   164
        fp = stringio()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   165
        _writectxmetadata(repo, old, fp)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   166
        matcher = scmutil.match(old, pats, opts)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   167
        for chunk, label in patch.diffui(repo, p1.node(), old.node(),
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   168
                                         match=matcher,
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   169
                                         opts=diffopts):
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   170
                fp.write(chunk)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   171
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   172
        fp.seek(0)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   173
        newpatch = ui.edit(fp.getvalue(), old.user(), action="diff")
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   174
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   175
        afp = stringio()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   176
        afp.write(newpatch)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   177
        if pats:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   178
            # write rest of the files in the patch
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   179
            restmatcher = scmutil.match(old, [], opts={'exclude': pats})
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   180
            for chunk, label in patch.diffui(repo, p1.node(), old.node(),
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   181
                                             match=restmatcher,
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   182
                                             opts=diffopts):
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   183
                    afp.write(chunk)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   184
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   185
        afp.seek(0)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   186
        # write the patch to repo and get the newnode
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   187
        newnode = _writepatch(ui, repo, old, afp)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   188
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   189
        if newnode == old.node():
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   190
            raise error.Abort(_("nothing changed"))
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   191
        metadata = {}
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   192
        if opts.get('note'):
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   193
            metadata['note'] = opts['note']
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   194
        compat.createmarkers(repo, [(old, (repo[newnode],))],
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   195
                             metadata=metadata, operation='amend')
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   196
        phases.retractboundary(repo, tr, old.phase(), [newnode])
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   197
        hg.updaterepo(repo, newnode, True)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   198
        bookmarkupdater(newnode)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   199
        tr.close()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   200
    finally:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   201
        tr.release()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   202
        lockmod.release(lock, wlock)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   203
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   204
def _writepatch(ui, repo, old, fp):
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   205
    """utility function to use filestore and patchrepo to apply a patch to the
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   206
    repository with metadata being extracted from the patch"""
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   207
    metadata = patch.extract(ui, fp)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   208
    pold = old.p1()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   209
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   210
    # store the metadata from the patch to variables
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   211
    parents = (metadata.get('p1'), metadata.get('p2'))
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   212
    date = metadata.get('date') or old.date()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   213
    branch = metadata.get('branch') or old.branch()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   214
    user = metadata.get('user') or old.user()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   215
    # XXX: we must extract extras from the patchfile too
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   216
    extra = old.extra()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   217
    message = metadata.get('message') or old.description()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   218
    store = patch.filestore()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   219
    fp.seek(0)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   220
    try:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   221
        files = set()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   222
        try:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   223
            patch.patchrepo(ui, repo, pold, store, fp, 1, '',
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   224
                            files=files, eolmode=None)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   225
        except patch.PatchError as err:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   226
            raise error.Abort(str(err))
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   227
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   228
        finally:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   229
            del fp
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   230
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   231
        memctx = context.memctx(repo, parents, message, files=files,
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   232
                                filectxfn=store,
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   233
                                user=user,
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   234
                                date=date,
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   235
                                branch=branch,
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   236
                                extra=extra)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   237
        newcm = memctx.commit()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   238
    finally:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   239
        store.close()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   240
    return newcm
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   241
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   242
def _writectxmetadata(repo, ctx, fp):
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   243
    nodeval = scmutil.binnode(ctx)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   244
    parents = [p.node() for p in ctx.parents() if p]
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   245
    branch = ctx.branch()
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   246
    if parents:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   247
        prev = parents[0]
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   248
    else:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   249
        prev = node.nullid
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   250
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   251
    fp.write("# HG changeset patch\n")
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   252
    fp.write("# User %s\n" % ctx.user())
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   253
    fp.write("# Date %d %d\n" % ctx.date())
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   254
    fp.write("#      %s\n" % dateutil.datestr(ctx.date()))
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   255
    if branch and branch != 'default':
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   256
        fp.write("# Branch %s\n" % branch)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   257
    fp.write("# Node ID %s\n" % node.hex(nodeval))
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   258
    fp.write("# Parent  %s\n" % node.hex(prev))
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   259
    if len(parents) > 1:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   260
        fp.write("# Parent  %s\n" % node.hex(parents[1]))
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   261
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   262
    for headerid in cmdutil.extraexport:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   263
        header = cmdutil.extraexportmap[headerid](1, ctx)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   264
        if header is not None:
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   265
            fp.write('# %s\n' % header)
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   266
    fp.write(ctx.description().rstrip())
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   267
    fp.write("\n\n")
f018656ca3bf amend: add a new flag `--patch` to `hg amend`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3616
diff changeset
   268
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   269
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
   270
    touched = set()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   271
    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
   272
        touched.update(files)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   273
    return touched
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   274
2728
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   275
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
   276
                    date=None):
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   277
    """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
   278
    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
   279
    """
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   280
    base = ctx.p1()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   281
    if target is None:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   282
        target = base
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   283
    # ctx
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   284
    initialfiles = _touchedbetween(repo, base, ctx)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   285
    if base == target:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   286
        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
   287
        newcontent = set()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   288
    else:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   289
        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
   290
        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
   291
    # 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
   292
    # + 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
   293
    # - 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
   294
    files = (initialfiles - affected) | newcontent
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   295
    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
   296
        return None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   297
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   298
    # Filter copies
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   299
    copied = copies.pathcopies(target, ctx)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   300
    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
   301
                  if dst in files)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   302
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   303
    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
   304
        if path in redirect:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   305
            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
   306
        if path not in contentctx:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   307
            return None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   308
        fctx = contentctx[path]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   309
        flags = fctx.flags()
3298
f4b06f44d274 memfilectx: changectx argument is not mandatory
Boris Feld <boris.feld@octobus.net>
parents: 3296
diff changeset
   310
        mctx = compat.memfilectx(repo, memctx, fctx, flags, copied, path)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   311
        return mctx
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   312
2727
f7d44441dfd3 uncommit: add support for --message and --logfile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2726
diff changeset
   313
    if message is None:
f7d44441dfd3 uncommit: add support for --message and --logfile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2726
diff changeset
   314
        message = ctx.description()
2728
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   315
    if not user:
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   316
        user = ctx.user()
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   317
    if not date:
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   318
        date = ctx.date()
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   319
    new = context.memctx(repo,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   320
                         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
   321
                         text=message,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   322
                         files=files,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   323
                         filectxfn=filectxfn,
2728
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   324
                         user=user,
3c371aa16cb9 uncommit: add support for --user and --date
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2727
diff changeset
   325
                         date=date,
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   326
                         extra=ctx.extra())
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   327
    # 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
   328
    newid = repo.commitctx(new)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   329
    return newid
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   330
2943
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   331
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
   332
    """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
   333
    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
   334
    match.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   335
    """
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   336
    ctx = repo['.']
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   337
    ds = repo.dirstate
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   338
    copies = dict(ds.copies())
2943
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   339
    if interactive:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   340
        # 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
   341
        # 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
   342
        # 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
   343
        # us in defining the exact behavior
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   344
        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
   345
        for f in m:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   346
            # 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
   347
            # 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
   348
            # modifications are uncommitted
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   349
            # 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
   350
            # 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
   351
            # 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
   352
            # 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
   353
            # 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
   354
            # 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
   355
            if ds[f] == 'r':
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   356
                # 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
   357
                # as removed
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   358
                continue
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   359
            ds.normallookup(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   360
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   361
        for f in a:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   362
            # 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
   363
            # 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
   364
            # 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
   365
            # 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
   366
            # 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
   367
            # 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
   368
            # removed in oldctx
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   369
            if ds[f] == 'a':
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   370
                ds.normallookup(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   371
                continue
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   372
            ds.remove(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   373
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   374
        for f in r:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   375
            # 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
   376
            # 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
   377
            # 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
   378
            # 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
   379
            # 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
   380
            # 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
   381
            if ds[f] == 'r':
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   382
                # 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
   383
                # unknown
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   384
                ds.drop(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   385
                continue
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   386
            ds.add(f)
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   387
    else:
2942
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   388
        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
   389
        for f in m:
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   390
            if ds[f] == 'r':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   391
                # modified + removed -> removed
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   392
                continue
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   393
            ds.normallookup(f)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   394
2942
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   395
        for f in a:
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   396
            if ds[f] == 'r':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   397
                # added + removed -> unknown
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   398
                ds.drop(f)
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   399
            elif ds[f] != 'a':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   400
                ds.add(f)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   401
2942
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   402
        for f in r:
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   403
            if ds[f] == 'a':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   404
                # removed + added -> normal
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   405
                ds.normallookup(f)
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   406
            elif ds[f] != 'r':
10194206acc7 uncommit: pre-indent a block in if-True
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2941
diff changeset
   407
                ds.remove(f)
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   408
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   409
    # 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
   410
    oldcopies = {}
2943
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   411
    if interactive:
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   412
        # 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
   413
        # original meaning to use them
25576132cb30 uncommit: fix the dirstate handling in `uncommit -i`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2942
diff changeset
   414
        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
   415
    for f in (m + a):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   416
        src = oldctx[f].renamed()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   417
        if src:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   418
            oldcopies[f] = src[0]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   419
    oldcopies.update(copies)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   420
    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
   421
                  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
   422
    # Adjust the dirstate copies
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   423
    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
   424
        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
   425
            src = None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   426
        ds.copy(src, dst)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   427
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   428
@eh.command(
3229
63f6f9db9c3a help: remove a few commands from `hg` (no args) command list
Kyle Lippincott <spectral@google.com>
parents: 2949
diff changeset
   429
    'uncommit',
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   430
    [('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
   431
     ('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
   432
     ('r', 'rev', '', _('revert commit content to REV instead')),
3389
eacf6149b678 uncommit: add a new flag `--revert` to discard wdir changes after uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3298
diff changeset
   433
     ('', 'revert', False, _('discard working directory changes after uncommit')),
3220
f0f4cc2febac uncommit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3219
diff changeset
   434
     ('n', 'note', '', _('store a note on uncommit')),
2729
69fe16428b0f uncommit: add support for -U and -D
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2728
diff changeset
   435
     ] + 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
   436
    _('[OPTION]... [NAME]'))
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   437
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
   438
    """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
   439
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   440
    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
   441
    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
   442
    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
   443
    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
   444
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   445
    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
   446
    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
   447
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   448
    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
   449
    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
   450
    directory.
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   451
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   452
    .. container:: verbose
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   453
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   454
       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
   455
       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
   456
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   457
    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
   458
    """
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   459
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
   460
    _checknotesize(ui, opts)
2729
69fe16428b0f uncommit: add support for -U and -D
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2728
diff changeset
   461
    _resolveoptions(ui, opts) # process commitopts3
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   462
    interactive = opts.get('interactive')
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   463
    wlock = lock = tr = None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   464
    try:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   465
        wlock = repo.wlock()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   466
        lock = repo.lock()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   467
        wctx = repo[None]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   468
        if len(wctx.parents()) <= 0:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   469
            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
   470
        if len(wctx.parents()) > 1:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   471
            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
   472
        old = repo['.']
2788
554c069cdc85 uncommit: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2787
diff changeset
   473
        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
   474
        if len(old.parents()) > 1:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   475
            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
   476
        oldphase = old.phase()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   477
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   478
        rev = None
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   479
        if opts.get('rev'):
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   480
            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
   481
            ctx = repo[None]
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   482
            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
   483
                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
   484
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   485
        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
   486
        disallowunstable = not obsolete.isenabled(repo,
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   487
                                                  obsolete.allowunstableopt)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   488
        if disallowunstable and not onahead:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   489
            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
   490
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   491
        # Recommit the filtered changeset
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   492
        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
   493
        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
   494
        if interactive:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   495
            opts['all'] = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   496
            match = scmutil.match(old, pats, opts)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   497
            newid = _interactiveuncommit(ui, repo, old, match)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   498
        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
   499
            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
   500
            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
   501
            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
   502
                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
   503
                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
   504
                    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
   505
                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
   506
                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
   507
                                        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
   508
                                        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
   509
            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
   510
                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
   511
                                  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
   512
3220
f0f4cc2febac uncommit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3219
diff changeset
   513
        # metadata to be stored in obsmarker
f0f4cc2febac uncommit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3219
diff changeset
   514
        metadata = {}
f0f4cc2febac uncommit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3219
diff changeset
   515
        if opts.get('note'):
f0f4cc2febac uncommit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3219
diff changeset
   516
            metadata['note'] = opts['note']
f0f4cc2febac uncommit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3219
diff changeset
   517
3563
d4c457c1ae0d uncommit: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3560
diff changeset
   518
        compat.createmarkers(repo, [(old, (repo[newid],))], metadata=metadata,
d4c457c1ae0d uncommit: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3560
diff changeset
   519
                             operation="uncommit")
2725
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   520
        phases.retractboundary(repo, tr, oldphase, [newid])
3389
eacf6149b678 uncommit: add a new flag `--revert` to discard wdir changes after uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3298
diff changeset
   521
        if opts.get('revert'):
eacf6149b678 uncommit: add a new flag `--revert` to discard wdir changes after uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3298
diff changeset
   522
            hg.updaterepo(repo, newid, True)
eacf6149b678 uncommit: add a new flag `--revert` to discard wdir changes after uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3298
diff changeset
   523
        else:
eacf6149b678 uncommit: add a new flag `--revert` to discard wdir changes after uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3298
diff changeset
   524
            with repo.dirstate.parentchange():
eacf6149b678 uncommit: add a new flag `--revert` to discard wdir changes after uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3298
diff changeset
   525
                repo.dirstate.setparents(newid, node.nullid)
eacf6149b678 uncommit: add a new flag `--revert` to discard wdir changes after uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3298
diff changeset
   526
                _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
   527
        updatebookmarks(newid)
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   528
        if not repo[newid].files():
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   529
            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
   530
            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
   531
        tr.close()
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   532
    finally:
4eb90eace7f9 uncommit: move to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2724
diff changeset
   533
        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
   534
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   535
def _interactiveuncommit(ui, repo, old, match):
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   536
    """ 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
   537
    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
   538
    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
   539
    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
   540
    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
   541
    """
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   542
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   543
    # 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
   544
    tempnode = _createtempcommit(ui, repo, old, match)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   545
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   546
    diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   547
    diffopts.nodates = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   548
    diffopts.git = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   549
    fp = stringio()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   550
    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
   551
                                     opts=diffopts):
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   552
            fp.write(chunk)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   553
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   554
    fp.seek(0)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   555
    newnode = _patchtocommit(ui, repo, old, fp)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   556
    # creating obs marker temp -> ()
3563
d4c457c1ae0d uncommit: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3560
diff changeset
   557
    compat.createmarkers(repo, [(repo[tempnode], ())], operation="uncommit")
2941
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   558
    return newnode
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   559
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   560
def _createtempcommit(ui, repo, old, match):
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   561
    """ 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
   562
    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
   563
    """
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   564
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   565
    pold = old.p1()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   566
    # 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
   567
    # cmdutil.revert()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   568
    diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   569
    diffopts.nodates = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   570
    diffopts.git = True
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   571
    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
   572
    originalchunks = patch.parsepatch(diff)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   573
    # 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
   574
    # uncommit a removed file partially.
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   575
    # 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
   576
    # 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
   577
    chunks, opts = cmdutil.recordfilter(repo.ui, originalchunks,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   578
                                        operation='discard')
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   579
    if not chunks:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   580
        raise error.Abort(_("nothing selected to uncommit"))
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   581
    fp = stringio()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   582
    for c in chunks:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   583
            c.write(fp)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   584
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   585
    fp.seek(0)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   586
    oldnode = node.hex(old.node())[:12]
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   587
    message = 'temporary commit for uncommiting %s' % oldnode
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   588
    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
   589
    return tempnode
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   590
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   591
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
   592
    """ 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
   593
    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
   594
    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
   595
    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
   596
    """
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   597
    pold = old.p1()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   598
    parents = (old.p1().node(), old.p2().node())
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   599
    date = old.date()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   600
    branch = old.branch()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   601
    user = old.user()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   602
    extra = old.extra()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   603
    if extras:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   604
        extra['uncommit_source'] = extras
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   605
    if not message:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   606
        message = old.description()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   607
    store = patch.filestore()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   608
    try:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   609
        files = set()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   610
        try:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   611
            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
   612
                            files=files, eolmode=None)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   613
        except patch.PatchError as err:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   614
            raise error.Abort(str(err))
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   615
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   616
        finally:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   617
            del fp
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   618
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   619
        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
   620
                                filectxfn=store,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   621
                                user=user,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   622
                                date=date,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   623
                                branch=branch,
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   624
                                extra=extra)
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   625
        newcm = memctx.commit()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   626
    finally:
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   627
        store.close()
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   628
    return newcm
b0458b9e1b47 uncommit: add an interactive option to uncommit
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2940
diff changeset
   629
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   630
@eh.command(
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   631
    '^fold|squash',
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   632
    [('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
   633
     ('', 'exact', None, _("only fold specified revisions")),
3219
b73bd280b21c fold: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3218
diff changeset
   634
     ('', 'from', None, _("fold revisions linearly to working copy parent")),
b73bd280b21c fold: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3218
diff changeset
   635
     ('n', 'note', '', _('store a note on fold')),
2768
85e5a56db776 fold: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2766
diff changeset
   636
    ] + commitopts + commitopts2 + commitopts3,
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   637
    _('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
   638
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
   639
    """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
   640
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   641
    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
   642
    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
   643
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   644
    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
   645
    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
   646
    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
   647
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   648
    .. container:: verbose
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   649
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   650
     Some examples:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   651
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   652
     - 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
   653
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   654
         hg fold --from .^
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   655
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   656
     - 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
   657
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   658
         hg fold --from 'draft()'
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   659
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   660
       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
   661
       :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
   662
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   663
     - 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
   664
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   665
         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
   666
2923
8c2d3c474fc6 doc: make paragraphs before example code end with "::" for reST syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2790
diff changeset
   667
     - 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
   668
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   669
        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
   670
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   671
     - 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
   672
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   673
         hg fold foo::@ --exact
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   674
    """
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
   675
    _checknotesize(ui, opts)
2768
85e5a56db776 fold: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2766
diff changeset
   676
    _resolveoptions(ui, opts)
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   677
    revs = list(revs)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   678
    revs.extend(opts['rev'])
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   679
    if not revs:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   680
        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
   681
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   682
    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
   683
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   684
    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
   685
        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
   686
    elif opts['from']:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   687
        # 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
   688
        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
   689
        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
   690
        if discardedrevs:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   691
            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
   692
            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
   693
                     " directory")
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   694
            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
   695
        revs = extrevs
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   696
    elif opts['exact']:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   697
        # 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
   698
        pass
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   699
    else:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   700
        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
   701
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   702
    if not revs:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   703
        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
   704
                          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
   705
    elif len(revs) == 1:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   706
        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
   707
        return 1
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   708
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   709
    wlock = lock = None
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   710
    try:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   711
        wlock = repo.wlock()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   712
        lock = repo.lock()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   713
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   714
        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
   715
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   716
        tr = repo.transaction('fold')
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   717
        try:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   718
            commitopts = opts.copy()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   719
            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
   720
            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
   721
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   722
            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
   723
                commitopts['edit'] = False
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   724
            else:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   725
                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
   726
                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
   727
                         (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
   728
                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
   729
                commitopts['edit'] = True
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   730
3219
b73bd280b21c fold: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3218
diff changeset
   731
            metadata = {}
b73bd280b21c fold: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3218
diff changeset
   732
            if opts.get('note'):
b73bd280b21c fold: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3218
diff changeset
   733
                metadata['note'] = opts['note']
b73bd280b21c fold: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3218
diff changeset
   734
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   735
            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
   736
                                                        head,
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   737
                                                        [root.p1().node(),
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   738
                                                         root.p2().node()],
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   739
                                                        commitopts=commitopts)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   740
            phases.retractboundary(repo, tr, targetphase, [newid])
3560
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3527
diff changeset
   741
            compat.createmarkers(repo, [(ctx, (repo[newid],))
3564
589649021ea1 fold: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3563
diff changeset
   742
                                 for ctx in allctx], metadata=metadata,
589649021ea1 fold: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3563
diff changeset
   743
                                 operation="fold")
3451
f062a4719e46 fold: make sure we move bookmarks after folding (issue5772)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
   744
            # move bookmarks from old nodes to the new one
f062a4719e46 fold: make sure we move bookmarks after folding (issue5772)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
   745
            # XXX: we should make rewriteutil.rewrite() handle such cases
f062a4719e46 fold: make sure we move bookmarks after folding (issue5772)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
   746
            for ctx in allctx:
f062a4719e46 fold: make sure we move bookmarks after folding (issue5772)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
   747
                bmupdater = rewriteutil.bookmarksupdater(repo, ctx.node(), tr)
f062a4719e46 fold: make sure we move bookmarks after folding (issue5772)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
   748
                bmupdater(newid)
2761
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   749
            tr.close()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   750
        finally:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   751
            tr.release()
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   752
        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
   753
        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
   754
            hg.update(repo, newid)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   755
    finally:
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   756
        lockmod.release(lock, wlock)
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   757
7450e360c88c commands: move fold to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2760
diff changeset
   758
@eh.command(
3229
63f6f9db9c3a help: remove a few commands from `hg` (no args) command list
Kyle Lippincott <spectral@google.com>
parents: 2949
diff changeset
   759
    'metaedit',
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   760
    [('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
   761
     ('', 'fold', None, _("also fold specified revisions into one")),
3218
772cc931f085 metaedit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3217
diff changeset
   762
     ('n', 'note', '', _('store a note on metaedit')),
2769
b96349ae3e2a metaedit: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2768
diff changeset
   763
    ] + commitopts + commitopts2 + commitopts3,
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   764
    _('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
   765
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
   766
    """edit commit information
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   767
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   768
    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
   769
    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
   770
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   771
    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
   772
    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
   773
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   774
    .. container:: verbose
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   775
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   776
     Some examples:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   777
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   778
     - 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
   779
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   780
         hg metaedit
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   781
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   782
     - 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
   783
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   784
         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
   785
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   786
     - 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
   787
       one::
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   788
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   789
         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
   790
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   791
       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
   792
       :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
   793
    """
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
   794
    _checknotesize(ui, opts)
2769
b96349ae3e2a metaedit: add support for the -D and -U options
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2768
diff changeset
   795
    _resolveoptions(ui, opts)
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   796
    revs = list(revs)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   797
    revs.extend(opts['rev'])
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   798
    if not revs:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   799
        if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   800
            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
   801
        revs = ['.']
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   802
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   803
    wlock = lock = None
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   804
    try:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   805
        wlock = repo.wlock()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   806
        lock = repo.lock()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   807
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   808
        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
   809
        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
   810
            # 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
   811
            # 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
   812
            #
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   813
            #   a ---- b ---- c
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   814
            #
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   815
            # 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
   816
            # 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
   817
            # revisions in topological order.
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   818
            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
   819
                                'not currently supported'))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   820
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   821
        if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   822
            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
   823
        else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   824
            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
   825
                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
   826
                                    'revisions'))
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   827
            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
   828
            if newunstable:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   829
                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
   830
                        ' of a stack')
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   831
                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
   832
                         ' are not allowed')
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   833
                hint %= repo[newunstable.first()]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   834
                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
   835
            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
   836
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   837
        wctx = repo[None]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   838
        p1 = wctx.p1()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   839
        tr = repo.transaction('metaedit')
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   840
        newp1 = None
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   841
        try:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   842
            commitopts = opts.copy()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   843
            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
   844
            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
   845
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   846
            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
   847
                commitopts['edit'] = False
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   848
            else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   849
                if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   850
                    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
   851
                    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
   852
                             (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
   853
                else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   854
                    msgs = [head.description()]
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   855
                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
   856
                commitopts['edit'] = True
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   857
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   858
            # 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
   859
            # 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
   860
            # different.
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   861
            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
   862
                                                 [root.p1().node(),
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   863
                                                  root.p2().node()],
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   864
                                                 commitopts=commitopts)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   865
            if created:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   866
                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
   867
                    newp1 = newid
3218
772cc931f085 metaedit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3217
diff changeset
   868
                # metadata to be stored on obsmarker
772cc931f085 metaedit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3217
diff changeset
   869
                metadata = {}
772cc931f085 metaedit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3217
diff changeset
   870
                if opts.get('note'):
772cc931f085 metaedit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3217
diff changeset
   871
                    metadata['note'] = opts['note']
772cc931f085 metaedit: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3217
diff changeset
   872
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   873
                phases.retractboundary(repo, tr, targetphase, [newid])
3560
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3527
diff changeset
   874
                compat.createmarkers(repo, [(ctx, (repo[newid],))
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3527
diff changeset
   875
                                            for ctx in allctx],
3565
cfe31185ad07 metaedit: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3564
diff changeset
   876
                                     metadata=metadata, operation="metaedit")
2760
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   877
            else:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   878
                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
   879
            tr.close()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   880
        finally:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   881
            tr.release()
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   882
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   883
        if opts['fold']:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   884
            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
   885
        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
   886
            hg.update(repo, newp1)
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   887
    finally:
ddff53ecc00b commands: move metaedit to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2756
diff changeset
   888
        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
   889
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   890
metadataopts = [
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   891
    ('d', 'date', '',
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   892
     _('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
   893
    ('u', 'user', '',
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   894
     _('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
   895
]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   896
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   897
def _getmetadata(**opts):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   898
    metadata = {}
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   899
    date = opts.get('date')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   900
    user = opts.get('user')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   901
    if date:
3514
498f782ccb4b compat: add compat layer for date related functions
Boris Feld <boris.feld@octobus.net>
parents: 3506
diff changeset
   902
        metadata['date'] = '%i %i' % compat.parsedate(date)
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   903
    if user:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   904
        metadata['user'] = user
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   905
    return metadata
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   906
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   907
@eh.command(
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   908
    '^prune|obsolete',
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   909
    [('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
   910
     ('s', 'succ', [], _("successor changeset")),
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   911
     ('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
   912
     ('k', 'keep', None, _("does not modify working copy during prune")),
3217
b6ba296532cb prune: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3216
diff changeset
   913
     ('n', 'note', '', _('store a note on prune')),
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   914
     ('', '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
   915
     ('', 'fold', False,
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   916
      _("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
   917
     ('', 'split', False,
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   918
      _("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
   919
     ('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
   920
                             " bookmark"))] + metadataopts,
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   921
    _('[OPTION] [-r] REV...'))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   922
# 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
   923
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
   924
    """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
   925
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   926
    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
   927
    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
   928
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   929
    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
   930
    to handle this situation.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   931
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   932
    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
   933
    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
   934
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   935
    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
   936
    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
   937
    markers.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   938
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   939
    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
   940
    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
   941
    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
   942
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   943
    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
   944
    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
   945
    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
   946
    """
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
   947
    _checknotesize(ui, opts)
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   948
    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
   949
    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
   950
    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
   951
    metadata = _getmetadata(**opts)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   952
    biject = opts.get('biject')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   953
    fold = opts.get('fold')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   954
    split = opts.get('split')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   955
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   956
    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
   957
    if 1 < len(options):
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   958
        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
   959
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   960
    if bookmarks:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   961
        reachablefrombookmark = rewriteutil.reachablefrombookmark
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   962
        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
   963
        if not revs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   964
            # 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
   965
            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
   966
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   967
    if not revs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   968
        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
   969
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   970
    wlock = lock = tr = None
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   971
    try:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   972
        wlock = repo.wlock()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   973
        lock = repo.lock()
2789
06ee4ec88190 prune: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2788
diff changeset
   974
        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
   975
        tr = repo.transaction('prune')
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   976
        # defines pruned changesets
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   977
        precs = []
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   978
        revs.sort()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   979
        for p in revs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   980
            cp = repo[p]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   981
            precs.append(cp)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   982
        if not precs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   983
            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
   984
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   985
        # defines successors changesets
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   986
        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
   987
        sucs.sort()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   988
        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
   989
        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
   990
            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
   991
            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
   992
                     " for another")
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   993
            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
   994
        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
   995
            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
   996
                % (len(sucs), len(precs))
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   997
            raise error.Abort(msg)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
   998
        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
   999
            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
  1000
            raise error.Abort(msg)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1001
        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
  1002
            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
  1003
            raise error.Abort(msg)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1004
        elif biject:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1005
            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
  1006
        else:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1007
            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
  1008
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1009
        wdp = repo['.']
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1010
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1011
        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
  1012
            # '.' 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
  1013
            newnode = sucs[0]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1014
        else:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1015
            # 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
  1016
            newnode = wdp
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1017
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1018
            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
  1019
                newnode = newnode.parents()[0]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1020
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1021
        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
  1022
            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
  1023
                # 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
  1024
                # 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
  1025
                # common at some point.
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1026
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1027
                # 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
  1028
                # 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
  1029
                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
  1030
                changedfiles = []
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1031
                for rev in descendantrevs:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1032
                    # 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
  1033
                    # changed
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1034
                    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
  1035
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1036
                # 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
  1037
                dirstate = repo.dirstate
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1038
                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
  1039
                changedfiles.extend(dirchanges)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1040
                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
  1041
                                      changedfiles)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1042
                dirstate.write(tr)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1043
            else:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1044
                bookactive = repo._activebookmark
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1045
                # 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
  1046
                # 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
  1047
                # after
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1048
                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
  1049
                if movebookmark:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1050
                    bookmarksmod.deactivate(repo)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1051
                    bmchanges = [(bookactive, newnode.node())]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1052
                    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
  1053
                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
  1054
                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
  1055
                          % 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
  1056
                if movebookmark:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1057
                    bookmarksmod.activate(repo, bookactive)
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1058
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1059
        # update bookmarks
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1060
        if bookmarks:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1061
            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
  1062
3217
b6ba296532cb prune: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3216
diff changeset
  1063
        # store note in metadata
b6ba296532cb prune: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3216
diff changeset
  1064
        if opts.get('note'):
b6ba296532cb prune: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3216
diff changeset
  1065
            metadata['note'] = opts['note']
b6ba296532cb prune: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3216
diff changeset
  1066
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1067
        # create markers
3566
e6bea259c227 prune: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3565
diff changeset
  1068
        compat.createmarkers(repo, relations, metadata=metadata,
e6bea259c227 prune: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3565
diff changeset
  1069
                             operation="prune")
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1070
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1071
        # 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
  1072
        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
  1073
3506
6b4272bbb65d evolve: update code for not implicitly converting ctx to revision
Boris Feld <boris.feld@octobus.net>
parents: 3484
diff changeset
  1074
        precrevs = (precursor.rev() for precursor in precs)
6b4272bbb65d evolve: update code for not implicitly converting ctx to revision
Boris Feld <boris.feld@octobus.net>
parents: 3484
diff changeset
  1075
        for ctx in repo.unfiltered().set('bookmark() and %ld', precrevs):
2766
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1076
            # used to be:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1077
            #
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1078
            #   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
  1079
            #   if ldest:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1080
            #      c = ldest[0]
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1081
            #
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1082
            # 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
  1083
            # 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
  1084
            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
  1085
                if not dest.obsolete():
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1086
                    bookmarksupdater = rewriteutil.bookmarksupdater
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1087
                    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
  1088
                    updatebookmarks(dest.node())
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1089
                    break
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1090
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1091
        tr.close()
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1092
    finally:
83ad13719e26 commands: move 'prune' to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2763
diff changeset
  1093
        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
  1094
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1095
@eh.command(
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1096
    '^split',
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1097
    [('r', 'rev', [], _("revision to split")),
3216
13cb0810ce22 split: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3215
diff changeset
  1098
     ('n', 'note', '', _("store a note on split")),
2771
6044bd16bfb7 split: add support for the -D and -U option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2770
diff changeset
  1099
    ] + commitopts + commitopts2 + commitopts3,
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1100
    _('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
  1101
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
  1102
    """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
  1103
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1104
    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
  1105
    redistributed into new changesets.
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1106
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1107
    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
  1108
    """
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
  1109
    _checknotesize(ui, opts)
2771
6044bd16bfb7 split: add support for the -D and -U option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2770
diff changeset
  1110
    _resolveoptions(ui, opts)
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1111
    tr = wlock = lock = None
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1112
    newcommits = []
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1113
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1114
    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
  1115
    if len(revarg) != 1:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1116
        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
  1117
        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
  1118
        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
  1119
3270
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1120
    # Save the current branch to restore it in the end
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1121
    savedbranch = repo.dirstate.branch()
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1122
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1123
    try:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1124
        wlock = repo.wlock()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1125
        lock = repo.lock()
3506
6b4272bbb65d evolve: update code for not implicitly converting ctx to revision
Boris Feld <boris.feld@octobus.net>
parents: 3484
diff changeset
  1126
        ctx = scmutil.revsingle(repo, revarg[0])
6b4272bbb65d evolve: update code for not implicitly converting ctx to revision
Boris Feld <boris.feld@octobus.net>
parents: 3484
diff changeset
  1127
        rev = ctx.rev()
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1128
        cmdutil.bailifchanged(repo)
2786
ae690d39fc92 split: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2774
diff changeset
  1129
        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
  1130
        tr = repo.transaction('split')
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1131
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1132
        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
  1133
            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
  1134
        prev = ctx.p1()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1135
        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
  1136
        bookactive = repo._activebookmark
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1137
        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
  1138
            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
  1139
        bookmarksmod.deactivate(repo)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1140
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1141
        # Prepare the working directory
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1142
        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
  1143
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1144
        def haschanges():
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1145
            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
  1146
            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
  1147
        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
  1148
               "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
  1149
        msg += ctx.description()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1150
        opts['message'] = msg
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1151
        opts['edit'] = True
2770
a9ea16a1f4dc split: fix the --user option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2769
diff changeset
  1152
        if not opts['user']:
a9ea16a1f4dc split: fix the --user option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2769
diff changeset
  1153
            opts['user'] = ctx.user()
3270
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1154
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1155
        # Set the right branch
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1156
        # XXX-TODO: Find a way to set the branch without altering the dirstate
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1157
        repo.dirstate.setbranch(ctx.branch())
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1158
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1159
        while haschanges():
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1160
            pats = ()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1161
            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
  1162
                             cmdutil.recordfilter, *pats, **opts)
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1163
            # 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
  1164
            # 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
  1165
            newcommits.append(repo['.'])
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1166
            if haschanges():
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1167
                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
  1168
                    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
  1169
                    newcommits.append(repo['.'])
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1170
                    break
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1171
            else:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1172
                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
  1173
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1174
        if newcommits:
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1175
            tip = repo[newcommits[-1]]
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1176
            bmupdate(tip.node())
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1177
            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
  1178
                bookmarksmod.activate(repo, bookactive)
3216
13cb0810ce22 split: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3215
diff changeset
  1179
            metadata = {}
13cb0810ce22 split: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3215
diff changeset
  1180
            if opts.get('note'):
13cb0810ce22 split: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3215
diff changeset
  1181
                metadata['note'] = opts['note']
3560
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3527
diff changeset
  1182
            compat.createmarkers(repo, [(repo[rev], newcommits)],
3567
5ddea3b8d2a4 split: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3566
diff changeset
  1183
                                 metadata=metadata, operation="split")
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1184
        tr.close()
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1185
    finally:
3270
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1186
        # Restore the old branch
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1187
        repo.dirstate.setbranch(savedbranch)
e6150b9b88d9 split: force the branch to fix the split bug
Boris Feld <boris.feld@octobus.net>
parents: 3233
diff changeset
  1188
2762
610581a2fb74 commands: move split to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2761
diff changeset
  1189
        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
  1190
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1191
@eh.command(
3229
63f6f9db9c3a help: remove a few commands from `hg` (no args) command list
Kyle Lippincott <spectral@google.com>
parents: 2949
diff changeset
  1192
    'touch',
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1193
    [('r', 'rev', [], 'revision to update'),
3215
175b524b9a2b touch: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3213
diff changeset
  1194
     ('n', 'note', '', _('store a note on touch')),
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1195
     ('D', 'duplicate', False,
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1196
      '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
  1197
     ('A', 'allowdivergence', False,
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1198
      '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
  1199
      'divergence')],
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1200
    # 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
  1201
    _('[-r] revs'))
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1202
def touch(ui, repo, *revs, **opts):
3233
bd01eb0108f4 touch: shorten touch's docstring to make it fit into a one line
Denis Laxalde <denis@laxalde.org>
parents: 3231
diff changeset
  1203
    """create successors identical to their predecessors but the changeset ID
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1204
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1205
    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
  1206
    """
3283
039c4b8dc3ed obsnote: warn if user try to store a note in obsmarker on an older hg
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3271
diff changeset
  1207
    _checknotesize(ui, opts)
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1208
    duplicate = opts['duplicate']
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1209
    allowdivergence = opts['allowdivergence']
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1210
    revs = list(revs)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1211
    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
  1212
    if not revs:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1213
        revs = ['.']
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1214
    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
  1215
    if not revs:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1216
        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
  1217
        return 1
2790
1b7b9acda2a9 touch: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2789
diff changeset
  1218
    if not duplicate:
1b7b9acda2a9 touch: use precheck to validate revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2789
diff changeset
  1219
        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
  1220
    tmpl = utility.shorttemplate
3483
f03845bfd015 compat: add wrapper for logcmdutil functions
Yuya Nishihara <yuya@tcha.org>
parents: 3452
diff changeset
  1221
    displayer = compat.changesetdisplayer(ui, repo, {'template': tmpl})
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1222
    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
  1223
    try:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1224
        wlock = repo.wlock()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1225
        lock = repo.lock()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1226
        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
  1227
        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
  1228
        newmapping = {}
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1229
        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
  1230
            ctx = repo[r]
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1231
            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
  1232
            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
  1233
            # 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
  1234
            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
  1235
            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
  1236
            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
  1237
            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
  1238
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1239
            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
  1240
                # 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
  1241
                # 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
  1242
                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
  1243
                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
  1244
                                    (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
  1245
                                     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
  1246
                                     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
  1247
                                    ))
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1248
                if nodivergencerisk:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1249
                    duplicate = False
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1250
                else:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1251
                    displayer.show(ctx)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1252
                    index = ui.promptchoice(
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1253
                        _("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
  1254
                          " 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
  1255
                          " (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
  1256
                          "&Duplicate"), 0)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1257
                    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
  1258
                    if choice == 'allowdivergence':
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1259
                        duplicate = False
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1260
                    else:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1261
                        duplicate = True
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1262
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1263
            extradict = {'extra': extra}
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1264
            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
  1265
                                                      [p1, p2],
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1266
                                                      commitopts=extradict)
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1267
            # 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
  1268
            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
  1269
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1270
            if not duplicate:
3215
175b524b9a2b touch: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3213
diff changeset
  1271
                metadata = {}
175b524b9a2b touch: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3213
diff changeset
  1272
                if opts.get('note'):
175b524b9a2b touch: add support for storing a note in obsmarker
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3213
diff changeset
  1273
                    metadata['note'] = opts['note']
3560
f61a23a84dac compat: add wrapper for obsolete.createmarkers() that accepts "operation" arg
Martin von Zweigbergk <martinvonz@google.com>
parents: 3527
diff changeset
  1274
                compat.createmarkers(repo, [(ctx, (repo[new],))],
3568
eca57332ad03 touch: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3567
diff changeset
  1275
                                     metadata=metadata, operation="touch")
2763
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1276
            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
  1277
            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
  1278
                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
  1279
                    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
  1280
        tr.close()
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1281
    finally:
4a5b0c373e65 commands: move the touch to the 'evocommands' module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2762
diff changeset
  1282
        lockmod.release(tr, lock, wlock)
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1283
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1284
@eh.command(
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1285
    'grab',
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1286
    [('r', 'rev', '', 'revision to grab'),
3522
7fa887cb1a6e grab: add short version for continue and abort
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3514
diff changeset
  1287
     ('c', 'continue', False, 'continue interrupted grab'),
7fa887cb1a6e grab: add short version for continue and abort
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3514
diff changeset
  1288
     ('a', 'abort', False, 'abort interrupted grab'),
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1289
    ],
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1290
    _('[-r] rev'))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1291
def grab(ui, repo, *revs, **opts):
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1292
    """grabs a commit, move it on the top of working directory parent and
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1293
    updates to it."""
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1294
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1295
    cont = opts.get('continue')
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1296
    abort = opts.get('abort')
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1297
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1298
    if cont and abort:
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1299
        raise error.Abort(_("cannot specify both --continue and --abort"))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1300
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1301
    revs = list(revs)
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1302
    if opts.get('rev'):
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1303
        revs.append(opts['rev'])
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1304
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1305
    with repo.wlock(), repo.lock(), repo.transaction('grab'):
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1306
        grabstate = state.cmdstate(repo, path='grabstate')
3526
df20ddc79064 grab: move the initialization of pctx variable outside of if-else
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3522
diff changeset
  1307
        pctx = repo['.']
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1308
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1309
        if not cont and not abort:
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1310
            cmdutil.bailifchanged(repo)
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1311
            revs = scmutil.revrange(repo, revs)
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1312
            if len(revs) > 1:
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1313
                raise error.Abort(_("specify just one revision"))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1314
            elif not revs:
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1315
                raise error.Abort(_("empty revision set"))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1316
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1317
            origctx = repo[revs.first()]
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1318
3527
7b4d1bfb6b7d grab: gracefully handle the case when we try to grab parent of wdir
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3526
diff changeset
  1319
            if origctx in pctx.ancestors() or origctx.node() == pctx.node():
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1320
                raise error.Abort(_("cannot grab an ancestor revision"))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1321
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1322
            rewriteutil.precheck(repo, [origctx.rev()], 'grab')
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1323
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1324
            ui.status(_('grabbing %d:%s "%s"\n') %
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1325
                      (origctx.rev(), origctx,
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1326
                       origctx.description().split("\n", 1)[0]))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1327
            stats = merge.graft(repo, origctx, origctx.p1(), ['local',
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1328
                                                              'destination'])
3616
f6d629514607 compat: use updateresult API if available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3569
diff changeset
  1329
            if compat.hasconflict(stats):
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1330
                grabstate.addopts({'orignode': origctx.node(),
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1331
                                   'oldpctx': pctx.node()})
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1332
                grabstate.save()
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1333
                raise error.InterventionRequired(_("unresolved merge conflicts"
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1334
                                                   " (see hg help resolve)"))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1335
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1336
        elif abort:
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1337
            if not grabstate:
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1338
                raise error.Abort(_("no interrupted grab state exists"))
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1339
            grabstate.load()
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1340
            pctxnode = grabstate['oldpctx']
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1341
            ui.status(_("aborting grab, updating to %s\n") %
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1342
                      node.hex(pctxnode)[:12])
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1343
            hg.updaterepo(repo, pctxnode, True)
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1344
            return 0
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1345
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1346
        else:
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1347
            if revs:
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1348
                raise error.Abort(_("cannot specify both --continue and "
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1349
                                    "revision"))
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1350
            if not grabstate:
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1351
                raise error.Abort(_("no interrupted grab state exists"))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1352
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1353
            grabstate.load()
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1354
            orignode = grabstate['orignode']
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1355
            origctx = repo[orignode]
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1356
3475
a03bb02dfaba grab: preserve phase of the grabbed changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
  1357
        overrides = {('phases', 'new-commit'): origctx.phase()}
a03bb02dfaba grab: preserve phase of the grabbed changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
  1358
        with repo.ui.configoverride(overrides, 'grab'):
a03bb02dfaba grab: preserve phase of the grabbed changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
  1359
            newnode = repo.commit(text=origctx.description(),
a03bb02dfaba grab: preserve phase of the grabbed changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
  1360
                                  user=origctx.user(),
a03bb02dfaba grab: preserve phase of the grabbed changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
  1361
                                  date=origctx.date(), extra=origctx.extra())
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1362
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1363
        if grabstate:
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3456
diff changeset
  1364
            grabstate.delete()
3569
236d36b17aa4 grab: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3568
diff changeset
  1365
        newctx = repo[newnode] if newnode else pctx
236d36b17aa4 grab: include "operation" metadata in obsmarkers
Martin von Zweigbergk <martinvonz@google.com>
parents: 3568
diff changeset
  1366
        compat.createmarkers(repo, [(origctx, (newctx,))], operation="grab")
3453
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1367
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1368
        if newnode is None:
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1369
            ui.warn(_("note: grab of %d:%s created no changes to commit\n") %
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1370
                    (origctx.rev(), origctx))
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1371
            return 0
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1372
32ed5b6fadd3 grab: add a command to grab a commit and update to it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3389
diff changeset
  1373
        return 0