hgext/evolve.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 20 Aug 2012 12:25:08 +0200
changeset 463 3f91654713dd
parent 455 f46a41006136
child 464 d88c761f97c4
permissions -rw-r--r--
obsolete Move merge failure handling into stabilize code This violate less Layer. For this purpose we crate an easy to recognize Exception Class.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     1
# states.py - introduce the state concept for mercurial changeset
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     2
#
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     3
# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     4
#                Logilab SA        <contact@logilab.fr>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     5
#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     6
#
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     7
# This software may be used and distributed according to the terms of the
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     8
# GNU General Public License version 2 or any later version.
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     9
228
5a17c0d41a00 proof-read documentation and docstrings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 219
diff changeset
    10
'''a set of commands to handle changeset mutation'''
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    11
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    12
from mercurial import cmdutil
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    13
from mercurial import scmutil
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    14
from mercurial import node
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    15
from mercurial import error
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    16
from mercurial import extensions
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    17
from mercurial import commands
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    18
from mercurial import bookmarks
113
3bdabdbb4140 adapt evolution to phase in core.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 108
diff changeset
    19
from mercurial import phases
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    20
from mercurial import context
219
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    21
from mercurial import copies
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
    22
from mercurial import util
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    23
from mercurial.i18n import _
455
f46a41006136 obsolete: simplify rebase wrapping code and change relation creation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 446
diff changeset
    24
from mercurial.commands import walkopts, commitopts, commitopts2
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
    25
from mercurial import hg
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    26
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    27
### util function
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    28
#############################
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
    29
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    30
def noderange(repo, revsets):
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    31
    """The same as revrange but return node"""
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    32
    return map(repo.changelog.node,
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    33
               scmutil.revrange(repo, revsets))
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    34
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    35
### changeset rewriting logic
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    36
#############################
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    37
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    38
def rewrite(repo, old, updates, head, newbases, commitopts):
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
    39
    """Return (nodeid, created) where nodeid is the identifier of the
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
    40
    changeset generated by the rewrite process, and created is True if
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
    41
    nodeid was actually created. If created is False, nodeid
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
    42
    references a changeset existing before the rewrite call.
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
    43
    """
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    44
    if len(old.parents()) > 1: #XXX remove this unecessary limitation.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    45
        raise error.Abort(_('cannot amend merge changesets'))
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    46
    base = old.p1()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
    47
    updatebookmarks = _bookmarksupdater(repo, old.node())
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    48
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    49
    wlock = repo.wlock()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    50
    try:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    51
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    52
        # commit a new version of the old changeset, including the update
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    53
        # collect all files which might be affected
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    54
        files = set(old.files())
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    55
        for u in updates:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    56
            files.update(u.files())
219
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    57
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    58
        # Recompute copies (avoid recording a -> b -> a)
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    59
        copied = copies.pathcopies(base, head)
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    60
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    61
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    62
        # prune files which were reverted by the updates
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    63
        def samefile(f):
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    64
            if f in head.manifest():
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    65
                a = head.filectx(f)
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    66
                if f in base.manifest():
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    67
                    b = base.filectx(f)
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    68
                    return (a.data() == b.data()
219
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    69
                            and a.flags() == b.flags())
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    70
                else:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    71
                    return False
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    72
            else:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    73
                return f not in base.manifest()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    74
        files = [f for f in files if not samefile(f)]
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    75
        # commit version of these files as defined by head
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    76
        headmf = head.manifest()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    77
        def filectxfn(repo, ctx, path):
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    78
            if path in headmf:
219
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    79
                fctx = head[path]
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    80
                flags = fctx.flags()
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    81
                mctx = context.memfilectx(fctx.path(), fctx.data(),
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    82
                                          islink='l' in flags,
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    83
                                          isexec='x' in flags,
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    84
                                          copied=copied.get(path))
cfdab01ca8a0 evolve-amend: properly handle amending file renames and additions.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 211
diff changeset
    85
                return mctx
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
    86
            raise IOError()
104
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    87
        if commitopts.get('message') and commitopts.get('logfile'):
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    88
            raise util.Abort(_('options --message and --logfile are mutually'
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    89
                               ' exclusive'))
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    90
        if commitopts.get('logfile'):
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    91
            message= open(commitopts['logfile']).read()
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    92
        elif commitopts.get('message'):
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    93
            message = commitopts['message']
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    94
        else:
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    95
            message = old.description()
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
    96
142
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
    97
        user = commitopts.get('user') or old.user()
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
    98
        date = commitopts.get('date') or None # old.date()
263
de62daaf2054 amend: drop --branches, pick it from working directory
Patrick Mezard <patrick@mezard.eu>
parents: 260
diff changeset
    99
        extra = dict(commitopts.get('extra', {}))
de62daaf2054 amend: drop --branches, pick it from working directory
Patrick Mezard <patrick@mezard.eu>
parents: 260
diff changeset
   100
        extra['branch'] = head.branch()
118
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   101
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   102
        new = context.memctx(repo,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   103
                             parents=newbases,
104
6c3c7a18f079 propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 103
diff changeset
   104
                             text=message,
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   105
                             files=files,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   106
                             filectxfn=filectxfn,
142
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
   107
                             user=user,
c2f7a8530e51 overwrite user not date
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 141
diff changeset
   108
                             date=date,
263
de62daaf2054 amend: drop --branches, pick it from working directory
Patrick Mezard <patrick@mezard.eu>
parents: 260
diff changeset
   109
                             extra=extra)
118
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   110
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   111
        if commitopts.get('edit'):
06fe05256a79 edit option \o/
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 117
diff changeset
   112
            new._text = cmdutil.commitforceeditor(repo, new, [])
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   113
        revcount = len(repo)
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   114
        newid = repo.commitctx(new)
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   115
        new = repo[newid]
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   116
        created = len(repo) != revcount
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   117
        if created:
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   118
            updatebookmarks(newid)
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   119
            # add evolution metadata
443
3f8c11865ed2 obsolete: remove usage of addcollapsedobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 420
diff changeset
   120
            markers = [(u, (new,)) for u in updates]
3f8c11865ed2 obsolete: remove usage of addcollapsedobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 420
diff changeset
   121
            markers.append((old, (new,)))
3f8c11865ed2 obsolete: remove usage of addcollapsedobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 420
diff changeset
   122
            obsolete = extensions.find('obsolete')
3f8c11865ed2 obsolete: remove usage of addcollapsedobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 420
diff changeset
   123
            obsolete.createmarkers(repo, markers)
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   124
        else:
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   125
            # newid is an existing revision. It could make sense to
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   126
            # replace revisions with existing ones but probably not by
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   127
            # default.
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   128
            pass
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   129
    finally:
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   130
        wlock.release()
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   131
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   132
    return newid, created
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   133
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   134
class MergeFailure(util.Abort):
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   135
    pass
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   136
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   137
def relocate(repo, orig, dest):
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   138
    """rewrite <rev> on dest"""
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   139
    try:
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   140
        rebase = extensions.find('rebase')
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   141
        # dummy state to trick rebase node
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   142
        assert orig.p2().rev() == node.nullrev, 'no support yet'
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   143
        destbookmarks = repo.nodebookmarks(dest.node())
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   144
        cmdutil.duplicatecopies(repo, orig.node(), dest.node())
258
8337bb3bb958 Fix amend and relocate who picked phases data after extinct wher made secret
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 255
diff changeset
   145
        nodesrc = orig.node()
8337bb3bb958 Fix amend and relocate who picked phases data after extinct wher made secret
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 255
diff changeset
   146
        destphase = repo[nodesrc].phase()
255
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   147
        if rebase.rebasenode.func_code.co_argcount == 5:
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   148
            # rebasenode collapse argument was introduced by
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   149
            # d1afbf03e69a (2.3)
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   150
            rebase.rebasenode(repo, orig.node(), dest.node(),
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   151
                              {node.nullrev: node.nullrev}, False)
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   152
        else:
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   153
            rebase.rebasenode(repo, orig.node(), dest.node(),
9852b3ef7234 evolve: update rebase usage to match 2.3
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 232
diff changeset
   154
                              {node.nullrev: node.nullrev})
326
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   155
        try:
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   156
            nodenew = rebase.concludenode(repo, orig.node(), dest.node(),
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   157
                                          node.nullid)
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   158
        except util.Abort, exc:
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   159
            class LocalMergeFailure(MergeFailure, exc.__class__):
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   160
                pass
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   161
            exc.__class__ = LocalMergeFailure
326
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   162
            raise
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   163
        oldbookmarks = repo.nodebookmarks(nodesrc)
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   164
        obsolete = extensions.find('obsolete')
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   165
        if nodenew is not None:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   166
            phases.retractboundary(repo, destphase, [nodenew])
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   167
            obsolete.createmarkers(repo, [(repo[nodesrc], (repo[nodenew],))])
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   168
            for book in oldbookmarks:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   169
                repo._bookmarks[book] = nodenew
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   170
        else:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   171
            obsolete.createmarkers(repo, [(repo[nodesrc], ())])
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   172
            # Behave like rebase, move bookmarks to dest
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   173
            for book in oldbookmarks:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   174
                repo._bookmarks[book] = dest.node()
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   175
        for book in destbookmarks: # restore bookmark that rebase move
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   176
            repo._bookmarks[book] = dest.node()
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   177
        if oldbookmarks or destbookmarks:
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   178
            bookmarks.write(repo)
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   179
    except util.Abort:
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   180
        # Invalidate the previous setparents
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   181
        repo.dirstate.invalidate()
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   182
        raise
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   183
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   184
def stabilizableunstable(repo, pctx):
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   185
    """Return a changectx for an unstable changeset which can be
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   186
    stabilized on top of pctx or one of its descendants. None if none
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   187
    can be found.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   188
    """
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   189
    def selfanddescendants(repo, pctx):
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   190
        yield pctx
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   191
        for ctx in pctx.descendants():
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   192
            yield ctx
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   193
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   194
    # Look for an unstable which can be stabilized as a child of
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   195
    # node. The unstable must be a child of one of node predecessors.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   196
    for ctx in selfanddescendants(repo, pctx):
446
9d47474d2582 obsolete: remove legacy revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 444
diff changeset
   197
        unstables = list(repo.set('unstable() and children(allprecursors(%d))',
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   198
                                  ctx.rev()))
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   199
        if unstables:
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   200
            return unstables[0]
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   201
    return None
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   202
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   203
def _bookmarksupdater(repo, oldid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   204
    """Return a callable update(newid) updating the current bookmark
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   205
    and bookmarks bound to oldid to newid.
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   206
    """
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   207
    bm = bookmarks.readcurrent(repo)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   208
    def updatebookmarks(newid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   209
        dirty = False
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   210
        if bm:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   211
            repo._bookmarks[bm] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   212
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   213
        oldbookmarks = repo.nodebookmarks(oldid)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   214
        if oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   215
            for b in oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   216
                repo._bookmarks[b] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   217
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   218
        if dirty:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   219
            bookmarks.write(repo)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   220
    return updatebookmarks
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   221
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   222
### new command
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   223
#############################
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   224
cmdtable = {}
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   225
command = cmdutil.command(cmdtable)
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   226
362
88cee22c89f1 evolve: add the solve alias to obsolete
Pierre-Yves.David@ens-lyon.org
parents: 356
diff changeset
   227
@command('^stabilize|evolve|solve',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   228
    [('n', 'dry-run', False, 'do not perform actions, print what to be done'),
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   229
    ('A', 'any', False, 'stabilize any unstable changeset'),],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   230
    _('[OPTIONS]...'))
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   231
def stabilize(ui, repo, **opts):
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   232
    """rebase an unstable changeset to make it stable again
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   233
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   234
    By default, take the first unstable changeset which could be
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   235
    rebased as child of the working directory parent revision or one
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   236
    of its descendants and rebase it.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   237
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   238
    With --any, stabilize any unstable changeset.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   239
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   240
    The working directory is updated to the rebased revision.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   241
    """
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   242
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   243
    obsolete = extensions.find('obsolete')
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   244
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   245
    node = None
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   246
    if not opts['any']:
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   247
        node = stabilizableunstable(repo, repo['.'])
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   248
    if node is None:
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   249
        unstables = list(repo.set('unstable()'))
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   250
        if unstables and not opts['any']:
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   251
            ui.write_err(_('nothing to stabilize here\n'))
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   252
            ui.status(_('(%i unstable changesets, do you want --any ?)\n')
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   253
                      % len(unstables))
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   254
            return 2
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   255
        elif not unstables:
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   256
            ui.write_err(_('no unstable changeset\n'))
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   257
            return 1
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   258
        node = unstables[0]
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   259
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   260
    obs = node.parents()[0]
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   261
    if not obs.obsolete():
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   262
        obs = node.parents()[1]
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   263
    assert obs.obsolete()
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   264
    newer = obsolete.newerversion(repo, obs.node())
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   265
    if len(newer) > 1:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   266
        ui.write_err(_("conflict rewriting. can't choose destination\n"))
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   267
        return 2
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   268
    targets = newer[0]
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   269
    if not targets:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   270
        ui.write_err(_("does not handle kill parent yet\n"))
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   271
        return 2
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   272
    if len(targets) > 1:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   273
        ui.write_err(_("does not handle splitted parent yet\n"))
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   274
        return 2
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   275
    target = targets[0]
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   276
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   277
    target = repo[target]
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   278
    repo.ui.status(_('move:'))
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   279
    if not ui.quiet:
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   280
        displayer.show(node)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   281
    repo.ui.status(_('atop:'))
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   282
    if not ui.quiet:
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   283
        displayer.show(target)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   284
    todo= 'hg rebase -Dr %s -d %s\n' % (node, target)
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   285
    if opts['dry_run']:
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   286
        repo.ui.write(todo)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   287
    else:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   288
        repo.ui.note(todo)
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   289
        lock = repo.lock()
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   290
        try:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   291
            relocate(repo, node, target)
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   292
        except MergeFailure:
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   293
            repo.ui.write_err(_('/!\\ stabilize failed                          /!\\\n'))
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   294
            repo.ui.write_err(_('/!\\ Their is no "hg stabilize --continue"     /!\\\n'))
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   295
            repo.ui.write_err(_('/!\\ use "hg up -C . ; hg stabilize --dry-run" /!\\\n'))
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   296
            raise
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   297
        finally:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   298
            lock.release()
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   299
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   300
shorttemplate = '[{rev}] {desc|firstline}\n'
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   301
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   302
@command('^gdown',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   303
         [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   304
         '')
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   305
def cmdgdown(ui, repo):
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   306
    """update to parent an display summary lines"""
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   307
    wkctx = repo[None]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   308
    wparents = wkctx.parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   309
    if len(wparents) != 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   310
        raise util.Abort('merge in progress')
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   311
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   312
    parents = wparents[0].parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   313
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   314
    if len(parents) == 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   315
        p = parents[0]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   316
        hg.update(repo, p.rev())
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   317
        displayer.show(p)
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   318
        return 0
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   319
    else:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   320
        for p in parents:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   321
            displayer.show(p)
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   322
        ui.warn(_('multiple parents, explicitly update to one\n'))
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   323
        return 1
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   324
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   325
@command('^gup',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   326
         [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   327
         '')
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   328
def cmdup(ui, repo):
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   329
    """update to child an display summary lines"""
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   330
    wkctx = repo[None]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   331
    wparents = wkctx.parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   332
    if len(wparents) != 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   333
        raise util.Abort('merge in progress')
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   334
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   335
    children = [ctx for ctx in wparents[0].children() if not ctx.obsolete()]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   336
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   337
    if not children:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   338
        ui.warn(_('No non-obsolete children\n'))
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   339
        return 1
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   340
    if len(children) == 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   341
        c = children[0]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   342
        hg.update(repo, c.rev())
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   343
        displayer.show(c)
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   344
        return 0
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   345
    else:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   346
        for c in children:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   347
            displayer.show(c)
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   348
        ui.warn(_('Multiple non-obsolete children, explicitly update to one\n'))
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
   349
        return 1
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   350
365
9f6a77ec66cb evolve: switch the official name for "kill" to prune
Pierre-Yves.David@ens-lyon.org
parents: 362
diff changeset
   351
@command('^prune|obsolete|kill',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   352
    [('n', 'new', [], _("successor changeset"))],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   353
    _('[OPTION] REV...'))
130
b70fadbccc2a evolution: add a --new argument for kill
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 127
diff changeset
   354
def kill(ui, repo, *revs, **opts):
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   355
    """mark a changeset as obsolete
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   356
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   357
    This update the parent directory to a not-killed parent if the current
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   358
    working directory parent are killed.
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   359
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   360
    XXX bookmark support
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   361
    XXX handle merge
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   362
    XXX check immutable first
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   363
    """
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   364
    wlock = repo.wlock()
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   365
    try:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   366
        lock = repo.lock()
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   367
        try:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   368
            new = set(noderange(repo, opts['new']))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   369
            targetnodes = set(noderange(repo, revs))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   370
            if new:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   371
                sucs = tuple(repo[n] for n in new)
130
b70fadbccc2a evolution: add a --new argument for kill
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 127
diff changeset
   372
            else:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   373
                sucs = ()
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   374
            markers = []
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   375
            for n in targetnodes:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   376
                markers.append((repo[n], sucs))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   377
            obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   378
            obsolete.createmarkers(repo, markers)
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   379
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   380
            # update to an unkilled parent
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   381
            wdp = repo['.']
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   382
            newnode = wdp
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   383
            while newnode.obsolete():
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   384
                newnode = newnode.parents()[0]
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   385
            if newnode.node() != wdp.node():
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   386
                commands.update(ui, repo, newnode.rev())
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   387
                ui.status(_('working directory now at %s\n') % newnode)
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   388
        finally:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   389
            lock.release()
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   390
    finally:
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   391
        wlock.release()
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   392
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   393
@command('^amend|refresh',
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   394
    [('A', 'addremove', None,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   395
     _('mark new/missing files as added/removed before committing')),
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   396
    ('n', 'note', '', _('use text as commit message for this update')),
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   397
    ('c', 'change', '', _('specifies the changesets to amend'), _('REV')),
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   398
    ('e', 'edit', False, _('invoke editor on commit messages')),
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   399
    ] + walkopts + commitopts + commitopts2,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   400
    _('[OPTION]... [FILE]...'))
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   401
def amend(ui, repo, *pats, **opts):
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   402
    """combine a changeset with updates and replace it with a new one
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   403
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   404
    Commits a new changeset incorporating both the changes to the given files
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   405
    and all the changes from the current parent changeset into the repository.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   406
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   407
    See :hg:`commit` for details about committing changes.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   408
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   409
    If you don't specify -m, the parent's message will be reused.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   410
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   411
    If you specify --change, amend additionally considers all
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   412
    changesets between the indicated changeset and the working copy
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   413
    parent as updates to be subsumed.
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   414
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   415
    Behind the scenes, Mercurial first commits the update as a regular child
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   416
    of the current parent. Then it creates a new commit on the parent's parents
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   417
    with the updated contents. Then it changes the working copy parent to this
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   418
    new combined changeset. Finally, the old changeset and its update are hidden
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   419
    from :hg:`log` (unless you use --hidden with log).
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   420
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   421
    Returns 0 on success, 1 if nothing changed.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   422
    """
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   423
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   424
    # determine updates to subsume
295
a5894bb97909 evolve: remove --change . == --change .^ crazyness
Patrick Mezard <patrick@mezard.eu>
parents: 294
diff changeset
   425
    old = scmutil.revsingle(repo, opts.get('change') or '.')
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   426
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   427
    lock = repo.lock()
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   428
    try:
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   429
        wlock = repo.wlock()
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   430
        try:
410
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   431
            tr = repo.transaction('amend')
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   432
            try:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   433
                if old.phase() == phases.public:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   434
                    raise util.Abort(_("can not rewrite immutable changeset %s")
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   435
                                     % old)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   436
                oldphase = old.phase()
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   437
                # commit current changes as update
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   438
                # code copied from commands.commit to avoid noisy messages
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   439
                ciopts = dict(opts)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   440
                ciopts.pop('message', None)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   441
                ciopts.pop('logfile', None)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   442
                ciopts['message'] = opts.get('note') or ('amends %s' % old.hex())
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   443
                e = cmdutil.commiteditor
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   444
                def commitfunc(ui, repo, message, match, opts):
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   445
                    return repo.commit(message, opts.get('user'), opts.get('date'),
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   446
                                       match, editor=e)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   447
                revcount = len(repo)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   448
                tempid = cmdutil.commit(ui, repo, commitfunc, pats, ciopts)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   449
                if len(repo) == revcount:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   450
                    # No revision created
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   451
                    tempid = None
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   452
410
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   453
                # find all changesets to be considered updates
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   454
                head = repo['.']
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   455
                updatenodes = set(repo.changelog.nodesbetween(
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   456
                        roots=[old.node()], heads=[head.node()])[0])
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   457
                updatenodes.remove(old.node())
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   458
                okoptions = ['message', 'logfile', 'edit', 'user']
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   459
                if not updatenodes:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   460
                    for o in okoptions:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   461
                        if opts.get(o):
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   462
                            break
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   463
                    else:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   464
                        raise error.Abort(_('no updates found'))
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   465
                updates = [repo[n] for n in updatenodes]
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   466
410
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   467
                # perform amend
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   468
                if opts.get('edit'):
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   469
                    opts['force_editor'] = True
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   470
                newid, created = rewrite(repo, old, updates, head,
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   471
                                         [old.p1().node(), old.p2().node()], opts)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   472
                if created:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   473
                    # reroute the working copy parent to the new changeset
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   474
                    phases.retractboundary(repo, oldphase, [newid])
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   475
                    repo.dirstate.setparents(newid, node.nullid)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   476
                else:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   477
                    # rewrite() recreated an existing revision, discard
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   478
                    # the intermediate revision if any. No need to update
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   479
                    # phases or parents.
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   480
                    if tempid is not None:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   481
                        obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   482
                        obsolete.createmarkers(repo, [(repo[tempid], ())])
410
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   483
                    # XXX: need another message in collapse case.
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   484
                    tr.close()
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   485
                    raise error.Abort(_('no updates found'))
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   486
                tr.close()
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   487
            finally:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   488
                tr.release()
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   489
        finally:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   490
            wlock.release()
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   491
    finally:
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   492
        lock.release()
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   493
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   494
def _commitfiltered(repo, ctx, match):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   495
    """Recommit ctx with changed files not in match. Return the new
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   496
    node identifier, or None if nothing changed.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   497
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   498
    base = ctx.p1()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   499
    m, a, r = repo.status(base, ctx)[:3]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   500
    allfiles = set(m + a + r)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   501
    files = set(f for f in allfiles if not match(f))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   502
    if files == allfiles:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   503
        return None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   504
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   505
    # Filter copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   506
    copied = copies.pathcopies(base, ctx)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   507
    copied = dict((src, dst) for src, dst in copied.iteritems()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   508
                  if dst in files)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   509
    def filectxfn(repo, memctx, path):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   510
        if path not in ctx:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   511
            raise IOError()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   512
        fctx = ctx[path]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   513
        flags = fctx.flags()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   514
        mctx = context.memfilectx(fctx.path(), fctx.data(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   515
                                  islink='l' in flags,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   516
                                  isexec='x' in flags,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   517
                                  copied=copied.get(path))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   518
        return mctx
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   519
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   520
    new = context.memctx(repo,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   521
                         parents=[base.node(), node.nullid],
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   522
                         text=ctx.description(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   523
                         files=files,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   524
                         filectxfn=filectxfn,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   525
                         user=ctx.user(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   526
                         date=ctx.date(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   527
                         extra=ctx.extra())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   528
    # commitctx always create a new revision, no need to check
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   529
    newid = repo.commitctx(new)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   530
    return newid
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   531
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   532
def _uncommitdirstate(repo, oldctx, match):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   533
    """Fix the dirstate after switching the working directory from
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   534
    oldctx to a copy of oldctx not containing changed files matched by
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   535
    match.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   536
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   537
    ctx = repo['.']
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   538
    ds = repo.dirstate
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   539
    copies = dict(ds.copies())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   540
    m, a, r = repo.status(oldctx.p1(), oldctx, match=match)[:3]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   541
    for f in m:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   542
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   543
            # modified + removed -> removed
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   544
            continue
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   545
        ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   546
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   547
    for f in a:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   548
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   549
            # added + removed -> unknown
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   550
            ds.drop(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   551
        elif ds[f] != 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   552
            ds.add(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   553
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   554
    for f in r:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   555
        if ds[f] == 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   556
            # removed + added -> normal
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   557
            ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   558
        elif ds[f] != 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   559
            ds.remove(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   560
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   561
    # Merge old parent and old working dir copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   562
    oldcopies = {}
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   563
    for f in (m + a):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   564
        src = oldctx[f].renamed()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   565
        if src:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   566
            oldcopies[f] = src[0]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   567
    oldcopies.update(copies)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   568
    copies = dict((dst, oldcopies.get(src, src))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   569
                  for dst, src in oldcopies.iteritems())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   570
    # Adjust the dirstate copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   571
    for dst, src in copies.iteritems():
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   572
        if (src not in ctx or dst in ctx or ds[dst] != 'a'):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   573
            src = None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   574
        ds.copy(src, dst)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   575
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   576
@command('^uncommit',
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   577
    [('a', 'all', None, _('uncommit all changes when no arguments given')),
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   578
     ] + commands.walkopts,
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   579
    _('[OPTION]... [NAME]'))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   580
def uncommit(ui, repo, *pats, **opts):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   581
    """move changes from parent revision to working directory
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   582
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   583
    Changes to selected files in parent revision appear again as
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   584
    uncommitted changed in the working directory. A new revision
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   585
    without selected changes is created, becomes the new parent and
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   586
    obsoletes the previous one.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   587
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   588
    The --include option specify pattern to uncommit
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   589
    The --exclude option specify pattern to keep in the commit
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   590
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   591
    Return 0 if changed files are uncommitted.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   592
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   593
    lock = repo.lock()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   594
    try:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   595
        wlock = repo.wlock()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   596
        try:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   597
            wctx = repo[None]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   598
            if len(wctx.parents()) <= 0:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   599
                raise util.Abort(_("cannot uncommit null changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   600
            if len(wctx.parents()) > 1:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   601
                raise util.Abort(_("cannot uncommit while merging"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   602
            old = repo['.']
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   603
            if old.phase() == phases.public:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   604
                raise util.Abort(_("cannot rewrite immutable changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   605
            if len(old.parents()) > 1:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   606
                raise util.Abort(_("cannot uncommit merge changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   607
            oldphase = old.phase()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   608
            updatebookmarks = _bookmarksupdater(repo, old.node())
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   609
            # Recommit the filtered changeset
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   610
            newid = None
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   611
            if (pats or opts.get('include') or opts.get('exclude')
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   612
                or opts.get('all')):
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   613
                match = scmutil.match(old, pats, opts)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   614
                newid = _commitfiltered(repo, old, match)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   615
            if newid is None:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   616
                raise util.Abort(_('nothing to uncommit'))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   617
            # Move local changes on filtered changeset
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   618
            obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   619
            obsolete.createmarkers(repo, [(old, (repo[newid],))])
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   620
            phases.retractboundary(repo, oldphase, [newid])
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   621
            repo.dirstate.setparents(newid, node.nullid)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   622
            _uncommitdirstate(repo, old, match)
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   623
            updatebookmarks(newid)
318
da7509e7b50c evolve: warn when uncommit leave an empty changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 315
diff changeset
   624
            if not repo[newid].files():
da7509e7b50c evolve: warn when uncommit leave an empty changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 315
diff changeset
   625
                ui.warn(_("new changeset is empty\n"))
da7509e7b50c evolve: warn when uncommit leave an empty changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 315
diff changeset
   626
                ui.status(_('(use "hg kill ." to remove it)\n'))
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   627
        finally:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   628
            wlock.release()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   629
    finally:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   630
        lock.release()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   631
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   632
def commitwrapper(orig, ui, repo, *arg, **kwargs):
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   633
    lock = repo.lock()
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   634
    try:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   635
        obsoleted = kwargs.get('obsolete', [])
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   636
        if obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   637
            obsoleted = repo.set('%lr', obsoleted)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   638
        result = orig(ui, repo, *arg, **kwargs)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   639
        if not result: # commit successed
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   640
            new = repo['-1']
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   641
            oldbookmarks = []
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   642
            obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   643
            markers = []
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   644
            for old in obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   645
                oldbookmarks.extend(repo.nodebookmarks(old.node()))
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   646
                markers.append((old, (new,)))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   647
            if markers:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   648
                obsolete.createmarkers(repo, markers)
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   649
            for book in oldbookmarks:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   650
                repo._bookmarks[book] = new.node()
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   651
            if oldbookmarks:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   652
                bookmarks.write(repo)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   653
        return result
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   654
    finally:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   655
        lock.release()
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   656
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
   657
def graftwrapper(orig, ui, repo, *revs, **kwargs):
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   658
    kwargs = dict(kwargs)
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   659
    revs = list(revs) + kwargs.get('rev', [])
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   660
    kwargs['rev'] = []
417
a1fb18ad29a1 evolve: avoid duplication in graft wrapper
Patrick Mezard <patrick@mezard.eu>
parents: 416
diff changeset
   661
    obsoleted = kwargs.setdefault('obsolete', [])
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   662
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   663
    lock = repo.lock()
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   664
    try:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   665
        if kwargs.get('old_obsolete'):
418
18a0d96ed559 evolve: graft --continue is optional, test
Patrick Mezard <patrick@mezard.eu>
parents: 417
diff changeset
   666
            if kwargs.get('continue'):
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   667
                obsoleted.extend(repo.opener.read('graftstate').splitlines())
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   668
            else:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   669
                obsoleted.extend(revs)
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   670
        # convert obsolete target into revs to avoid alias joke
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   671
        obsoleted[:] = [str(i) for i in repo.revs('%lr', obsoleted)]
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   672
        if obsoleted and len(revs) > 1:
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   673
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   674
            raise error.Abort(_('Can not graft multiple revision while '
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   675
                                'obsoleting (for now).'))
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   676
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   677
        return commitwrapper(orig, ui, repo,*revs, **kwargs)
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   678
    finally:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   679
        lock.release()
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
   680
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   681
def extsetup(ui):
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   682
    try:
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   683
        obsolete = extensions.find('obsolete')
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   684
    except KeyError:
416
22f348c25d25 obsolete/evolve: fix grammar in prerequisite messages
Patrick Mezard <patrick@mezard.eu>
parents: 414
diff changeset
   685
        raise error.Abort(_('evolution extension requires obsolete extension.'))
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   686
    try:
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   687
        rebase = extensions.find('rebase')
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   688
    except KeyError:
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   689
        rebase = None
416
22f348c25d25 obsolete/evolve: fix grammar in prerequisite messages
Patrick Mezard <patrick@mezard.eu>
parents: 414
diff changeset
   690
        raise error.Abort(_('evolution extension requires rebase extension.'))
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   691
356
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
   692
    for cmd in ['amend', 'kill', 'uncommit']:
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
   693
        entry = extensions.wrapcommand(cmdtable, cmd,
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
   694
                                       obsolete.warnobserrors)
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
   695
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   696
    entry = extensions.wrapcommand(commands.table, 'commit', commitwrapper)
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   697
    entry[1].append(('o', 'obsolete', [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   698
                     _("make commit obsolete this revision")))
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
   699
    entry = extensions.wrapcommand(commands.table, 'graft', graftwrapper)
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   700
    entry[1].append(('o', 'obsolete', [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   701
                     _("make graft obsoletes this revision")))
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   702
    entry[1].append(('O', 'old-obsolete', False,
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   703
                     _("make graft obsoletes its source")))
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   704