hgext/evolve.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 20 Aug 2012 19:12:20 +0200
changeset 470 a2dfe82f27a0
parent 469 abeb17a9e313
child 477 fded4d945f87
permissions -rw-r--r--
obsolete: use flag to detect that a obsolescence marker fix a latecomer Otherwise latecomer fix will be latecomer too.
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)
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   179
        return nodenew
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   180
    except util.Abort:
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   181
        # 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
   182
        repo.dirstate.invalidate()
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   183
        raise
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   184
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   185
def _stabilizableunstable(repo, pctx):
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   186
    """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
   187
    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
   188
    can be found.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   189
    """
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   190
    def selfanddescendants(repo, pctx):
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   191
        yield pctx
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   192
        for ctx in pctx.descendants():
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   193
            yield ctx
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   194
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   195
    # 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
   196
    # 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
   197
    for ctx in selfanddescendants(repo, pctx):
446
9d47474d2582 obsolete: remove legacy revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 444
diff changeset
   198
        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
   199
                                  ctx.rev()))
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   200
        if unstables:
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   201
            return unstables[0]
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   202
    return None
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   203
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   204
def _bookmarksupdater(repo, oldid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   205
    """Return a callable update(newid) updating the current bookmark
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   206
    and bookmarks bound to oldid to newid.
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   207
    """
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   208
    bm = bookmarks.readcurrent(repo)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   209
    def updatebookmarks(newid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   210
        dirty = False
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   211
        if bm:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   212
            repo._bookmarks[bm] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   213
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   214
        oldbookmarks = repo.nodebookmarks(oldid)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   215
        if oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   216
            for b in oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   217
                repo._bookmarks[b] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   218
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   219
        if dirty:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   220
            bookmarks.write(repo)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   221
    return updatebookmarks
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   222
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   223
### new command
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   224
#############################
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   225
cmdtable = {}
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   226
command = cmdutil.command(cmdtable)
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   227
362
88cee22c89f1 evolve: add the solve alias to obsolete
Pierre-Yves.David@ens-lyon.org
parents: 356
diff changeset
   228
@command('^stabilize|evolve|solve',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   229
    [('n', 'dry-run', False, 'do not perform actions, print what to be done'),
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   230
    ('A', 'any', False, 'stabilize any unstable changeset'),
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   231
    ('c', 'continue', False, 'continue an interrupted stabilized'), ],
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   232
    _('[OPTIONS]...'))
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   233
def stabilize(ui, repo, **opts):
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   234
    """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
   235
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   236
    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
   237
    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
   238
    of its descendants and rebase it.
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
    With --any, stabilize any unstable changeset.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   241
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   242
    The working directory is updated to the rebased revision.
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   243
    """
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   244
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   245
    contopt = opts['continue']
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   246
    anyopt = opts['any']
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   247
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   248
    if contopt:
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   249
        if anyopt:
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   250
            raise util.Abort('can not specify both "--any" and "--continue"')
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   251
        graftcmd = commands.table['graft'][0]
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   252
        return graftcmd(ui, repo, old_obsolete=True, **{'continue': True})
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   253
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   254
    troubled = list(repo.revs('troubled()'))
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   255
    tr = _picknexttroubled(ui, repo, anyopt)
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   256
    if tr is None:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   257
        if troubled:
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   258
            ui.write_err(_('nothing to stabilize here\n'))
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   259
            ui.status(_('(%i troubled changesets, do you want --any ?)\n')
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   260
                      % len(troubled))
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   261
            return 2
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   262
        else:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   263
            ui.write_err(_('no troubled changeset\n'))
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
   264
            return 1
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   265
    troubles = tr.troubles()
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   266
    if 'unstable' in troubles:
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   267
        return _solveunstable(ui, repo, tr, opts['dry_run'])
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   268
    elif 'latecomer' in troubles:
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   269
        return _solvelatecomer(ui, repo, tr, opts['dry_run'])
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   270
    elif 'conflicting' in troubles:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   271
        ui.write_err(_('conflicting not handled yet\n'))
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   272
        return 4
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   273
    else:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   274
        assert False  # WHAT? unknown troubles
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
   275
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   276
def _picknexttroubled(ui, repo, any=False):
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   277
    """Pick a the next trouble changeset to solve"""
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   278
    tr = _stabilizableunstable(repo, repo['.'])
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   279
    if tr is None and any:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   280
        troubled = list(repo.set('unstable()'))
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   281
        if not troubled:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   282
            troubled = list(repo.set('latecomer()'))
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   283
        if not troubled:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   284
            troubled = list(repo.set('conflicting()'))
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   285
        if troubled:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   286
            tr = troubled[0]
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   287
    return tr
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   288
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   289
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   290
def _solveunstable(ui, repo, orig, dryrun=False):
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   291
    """Stabilize a unstable changeset"""
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   292
    obsolete = extensions.find('obsolete')
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
   293
    obs = orig.parents()[0]
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   294
    if not obs.obsolete():
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
   295
        obs = orig.parents()[1]
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
   296
    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
   297
    newer = obsolete.newerversion(repo, obs.node())
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
   298
    # search of a parent which is not killed
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
   299
    while newer == [()]:
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
   300
        ui.debug("stabilize target %s is plain dead,"
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
   301
                 " trying to stabilize on it's parent")
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
   302
        obs = obs.parents()[0]
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
   303
        newer = obsolete.newerversion(repo, obs.node())
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   304
    if len(newer) > 1:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   305
        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
   306
        return 2
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   307
    targets = newer[0]
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
   308
    assert targets
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   309
    if len(targets) > 1:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   310
        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
   311
        return 2
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   312
    target = targets[0]
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   313
    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
   314
    target = repo[target]
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   315
    repo.ui.status(_('move:'))
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   316
    if not ui.quiet:
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
   317
        displayer.show(orig)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   318
    repo.ui.status(_('atop:'))
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   319
    if not ui.quiet:
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   320
        displayer.show(target)
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   321
    todo = 'hg rebase -Dr %s -d %s\n' % (orig, target)
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
   322
    if dryrun:
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
   323
        repo.ui.write(todo)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   324
    else:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   325
        repo.ui.note(todo)
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   326
        lock = repo.lock()
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   327
        try:
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
   328
            relocate(repo, orig, target)
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   329
        except MergeFailure:
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   330
            repo.opener.write('graftstate', orig.hex() + '\n')
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   331
            repo.ui.write_err(_('stabilize failed!\n'))
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
   332
            repo.ui.write_err(_('fix conflict and run "hg stabilize --continue"\n'))
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   333
            raise
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   334
        finally:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   335
            lock.release()
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   336
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   337
def _solvelatecomer(ui, repo, latecomer, dryrun=False):
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   338
    """Stabilize a latecomer changeset"""
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   339
    # For now we deny latecomer merge
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   340
    if len(latecomer.parents()) > 1:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   341
        raise util.Abort('late comer stabilization is confused by latecomer'
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   342
                         ' %s being a merge' % latecomer)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   343
    prec = repo.set('last(allprecursors(%d) and public())', latecomer).next()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   344
    # For now we deny target merge
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   345
    if len(prec.parents()) > 1:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   346
        raise util.Abort('late comer stabilization is confused by precursors'
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   347
                         ' %s being a merge' % prec)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   348
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   349
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   350
    repo.ui.status(_('recreate:'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   351
    if not ui.quiet:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   352
        displayer.show(latecomer)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   353
    repo.ui.status(_('atop:'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   354
    if not ui.quiet:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   355
        displayer.show(prec)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   356
    obsolete = extensions.find('obsolete')
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   357
    if dryrun:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   358
        todo = 'hg rebase --rev %s --detach %s;\n' % (latecomer, prec.p1())
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   359
        repo.ui.write(todo)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   360
        repo.ui.write('hg update %s;\n' % prec)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   361
        repo.ui.write('hg revert --all --rev %s;\n' % latecomer)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   362
        repo.ui.write('hg commit --msg "latecomer update to %s"')
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   363
        return 0
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   364
    wlock = repo.wlock()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   365
    try:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   366
        newid = tmpctx = None
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   367
        tmpctx = latecomer
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   368
        lock = repo.lock()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   369
        try:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   370
            bmupdate = _bookmarksupdater(repo, latecomer.node())
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   371
            # Basic check for common parent. Far too complicated and fragile
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   372
            tr = repo.transaction('latecomer-stabilize')
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   373
            try:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   374
                if not list(repo.set('parents(%d) and parents(%d)', latecomer, prec)):
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   375
                    # Need to rebase the changeset at the right place
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   376
                    repo.ui.status(_('rebasing to destination parent: %s\n') % prec.p1())
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   377
                    try:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   378
                        tmpid = relocate(repo, latecomer, prec.p1())
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   379
                        if tmpid is not None:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   380
                            tmpctx = repo[tmpid]
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   381
                            obsolete.createmarkers(repo, [(latecomer, (tmpctx,))])
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   382
                    except MergeFailure:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   383
                        repo.opener.write('graftstate', latecomer.hex() + '\n')
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   384
                        repo.ui.write_err(_('stabilize failed!\n'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   385
                        repo.ui.write_err(_('fix conflict and run "hg stabilize --continue"\n'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   386
                        raise
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   387
                # Create the new commit context
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   388
                repo.ui.status(_('computing new diff\n'))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   389
                files = set()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   390
                copied = copies.pathcopies(prec, latecomer)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   391
                precmanifest = prec.manifest()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   392
                for key, val in latecomer.manifest().iteritems():
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   393
                    if precmanifest.pop(key, None) != val:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   394
                        files.add(key)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   395
                files.update(precmanifest)  # add missing files
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   396
                # commit it
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   397
                if files: # something to commit!
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   398
                    def filectxfn(repo, ctx, path):
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   399
                        if path in latecomer:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   400
                            fctx = latecomer[path]
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   401
                            flags = fctx.flags()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   402
                            mctx = context.memfilectx(fctx.path(), fctx.data(),
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   403
                                                      islink='l' in flags,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   404
                                                      isexec='x' in flags,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   405
                                                      copied=copied.get(path))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   406
                            return mctx
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   407
                        raise IOError()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   408
                    text = 'latecomer update to %s:\n\n' % prec
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   409
                    text += latecomer.description()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   410
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   411
                    new = context.memctx(repo,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   412
                                         parents=[prec.node(), node.nullid],
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   413
                                         text=text,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   414
                                         files=files,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   415
                                         filectxfn=filectxfn,
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   416
                                         user=latecomer.user(),
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   417
                                         date=latecomer.date(),
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   418
                                         extra=latecomer.extra())
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   419
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   420
                    newid = repo.commitctx(new)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   421
                if newid is None:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   422
                    obsolete.createmarkers(repo, [(tmpctx, ())])
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   423
                    newid = prec.node()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   424
                else:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   425
                    phases.retractboundary(repo, latecomer.phase(), [newid])
470
a2dfe82f27a0 obsolete: use flag to detect that a obsolescence marker fix a latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 469
diff changeset
   426
                    obsolete.createmarkers(repo, [(tmpctx, (repo[newid],))],
a2dfe82f27a0 obsolete: use flag to detect that a obsolescence marker fix a latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 469
diff changeset
   427
                                           flag=obsolete.latediff)
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   428
                bmupdate(newid)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   429
                tr.close()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   430
                repo.ui.status(_('commited as %s\n') % node.short(newid))
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   431
            finally:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   432
                tr.release()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   433
        finally:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   434
            lock.release()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   435
        # reroute the working copy parent to the new changeset
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   436
        repo.dirstate.setparents(newid, node.nullid)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   437
    finally:
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   438
        wlock.release()
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   439
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
   440
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
   441
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
   442
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
   443
@command('^gdown',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   444
         [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   445
         '')
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
   446
def cmdgdown(ui, repo):
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   447
    """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
   448
    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
   449
    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
   450
    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
   451
        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
   452
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
   453
    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
   454
    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
   455
    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
   456
        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
   457
        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
   458
        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
   459
        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
   460
    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
   461
        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
   462
            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
   463
        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
   464
        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
   465
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
   466
@command('^gup',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   467
         [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   468
         '')
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
   469
def cmdup(ui, repo):
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   470
    """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
   471
    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
   472
    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
   473
    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
   474
        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
   475
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
   476
    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
   477
    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
   478
    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
   479
        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
   480
        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
   481
    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
   482
        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
   483
        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
   484
        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
   485
        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
   486
    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
   487
        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
   488
            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
   489
        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
   490
        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
   491
365
9f6a77ec66cb evolve: switch the official name for "kill" to prune
Pierre-Yves.David@ens-lyon.org
parents: 362
diff changeset
   492
@command('^prune|obsolete|kill',
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   493
    [('n', 'new', [], _("successor changeset"))],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   494
    _('[OPTION] REV...'))
130
b70fadbccc2a evolution: add a --new argument for kill
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 127
diff changeset
   495
def kill(ui, repo, *revs, **opts):
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   496
    """mark a changeset as obsolete
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   497
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   498
    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
   499
    working directory parent are killed.
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   500
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   501
    XXX bookmark support
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   502
    XXX handle merge
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   503
    XXX check immutable first
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   504
    """
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   505
    wlock = repo.wlock()
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   506
    try:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   507
        lock = repo.lock()
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   508
        try:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   509
            new = set(noderange(repo, opts['new']))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   510
            targetnodes = set(noderange(repo, revs))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   511
            if new:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   512
                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
   513
            else:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   514
                sucs = ()
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   515
            markers = []
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   516
            for n in targetnodes:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   517
                markers.append((repo[n], sucs))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   518
            obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   519
            obsolete.createmarkers(repo, markers)
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   520
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   521
            # update to an unkilled parent
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   522
            wdp = repo['.']
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   523
            newnode = wdp
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   524
            while newnode.obsolete():
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   525
                newnode = newnode.parents()[0]
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   526
            if newnode.node() != wdp.node():
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   527
                commands.update(ui, repo, newnode.rev())
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   528
                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
   529
        finally:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   530
            lock.release()
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   531
    finally:
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   532
        wlock.release()
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   533
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   534
@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
   535
    [('A', 'addremove', None,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   536
     _('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
   537
    ('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
   538
    ('c', 'change', '', _('specifies the changesets to amend'), _('REV')),
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   539
    ('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
   540
    ] + walkopts + commitopts + commitopts2,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   541
    _('[OPTION]... [FILE]...'))
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   542
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
   543
    """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
   544
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   545
    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
   546
    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
   547
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   548
    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
   549
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   550
    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
   551
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   552
    If you specify --change, amend additionally considers all
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   553
    changesets between the indicated changeset and the working copy
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   554
    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
   555
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   556
    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
   557
    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
   558
    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
   559
    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
   560
    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
   561
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   562
    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
   563
    """
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   564
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   565
    # determine updates to subsume
295
a5894bb97909 evolve: remove --change . == --change .^ crazyness
Patrick Mezard <patrick@mezard.eu>
parents: 294
diff changeset
   566
    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
   567
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   568
    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
   569
    try:
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   570
        wlock = repo.wlock()
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   571
        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
   572
            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
   573
            try:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   574
                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
   575
                    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
   576
                                     % old)
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   577
                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
   578
                # 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
   579
                # 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
   580
                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
   581
                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
   582
                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
   583
                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
   584
                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
   585
                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
   586
                    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
   587
                                       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
   588
                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
   589
                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
   590
                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
   591
                    # 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
   592
                    tempid = None
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   593
410
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   594
                # 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
   595
                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
   596
                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
   597
                        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
   598
                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
   599
                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
   600
                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
   601
                    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
   602
                        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
   603
                            break
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   604
                    else:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   605
                        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
   606
                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
   607
410
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   608
                # 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
   609
                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
   610
                    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
   611
                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
   612
                                         [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
   613
                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
   614
                    # 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
   615
                    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
   616
                    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
   617
                else:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   618
                    # 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
   619
                    # 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
   620
                    # 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
   621
                    if tempid is not None:
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   622
                        obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   623
                        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
   624
                    # 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
   625
                    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
   626
                    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
   627
                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
   628
            finally:
598ff1df3b92 amend: wrap the whole process in a single transaction.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 365
diff changeset
   629
                tr.release()
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   630
        finally:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   631
            wlock.release()
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   632
    finally:
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   633
        lock.release()
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   634
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   635
def _commitfiltered(repo, ctx, match):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   636
    """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
   637
    node identifier, or None if nothing changed.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   638
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   639
    base = ctx.p1()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   640
    m, a, r = repo.status(base, ctx)[:3]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   641
    allfiles = set(m + a + r)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   642
    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
   643
    if files == allfiles:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   644
        return None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   645
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   646
    # Filter copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   647
    copied = copies.pathcopies(base, ctx)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   648
    copied = dict((src, dst) for src, dst in copied.iteritems()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   649
                  if dst in files)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   650
    def filectxfn(repo, memctx, path):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   651
        if path not in ctx:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   652
            raise IOError()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   653
        fctx = ctx[path]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   654
        flags = fctx.flags()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   655
        mctx = context.memfilectx(fctx.path(), fctx.data(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   656
                                  islink='l' in flags,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   657
                                  isexec='x' in flags,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   658
                                  copied=copied.get(path))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   659
        return mctx
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   660
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   661
    new = context.memctx(repo,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   662
                         parents=[base.node(), node.nullid],
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   663
                         text=ctx.description(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   664
                         files=files,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   665
                         filectxfn=filectxfn,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   666
                         user=ctx.user(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   667
                         date=ctx.date(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   668
                         extra=ctx.extra())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   669
    # commitctx always create a new revision, no need to check
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   670
    newid = repo.commitctx(new)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   671
    return newid
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   672
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   673
def _uncommitdirstate(repo, oldctx, match):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   674
    """Fix the dirstate after switching the working directory from
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   675
    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
   676
    match.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   677
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   678
    ctx = repo['.']
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   679
    ds = repo.dirstate
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   680
    copies = dict(ds.copies())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   681
    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
   682
    for f in m:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   683
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   684
            # modified + removed -> removed
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   685
            continue
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   686
        ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   687
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   688
    for f in a:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   689
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   690
            # added + removed -> unknown
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   691
            ds.drop(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   692
        elif ds[f] != 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   693
            ds.add(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   694
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   695
    for f in r:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   696
        if ds[f] == 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   697
            # removed + added -> normal
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   698
            ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   699
        elif ds[f] != 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   700
            ds.remove(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   701
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   702
    # Merge old parent and old working dir copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   703
    oldcopies = {}
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   704
    for f in (m + a):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   705
        src = oldctx[f].renamed()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   706
        if src:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   707
            oldcopies[f] = src[0]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   708
    oldcopies.update(copies)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   709
    copies = dict((dst, oldcopies.get(src, src))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   710
                  for dst, src in oldcopies.iteritems())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   711
    # Adjust the dirstate copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   712
    for dst, src in copies.iteritems():
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   713
        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
   714
            src = None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   715
        ds.copy(src, dst)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   716
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   717
@command('^uncommit',
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   718
    [('a', 'all', None, _('uncommit all changes when no arguments given')),
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   719
     ] + commands.walkopts,
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   720
    _('[OPTION]... [NAME]'))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   721
def uncommit(ui, repo, *pats, **opts):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   722
    """move changes from parent revision to working directory
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   723
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   724
    Changes to selected files in parent revision appear again as
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   725
    uncommitted changed in the working directory. A new revision
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   726
    without selected changes is created, becomes the new parent and
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   727
    obsoletes the previous one.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   728
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   729
    The --include option specify pattern to uncommit
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   730
    The --exclude option specify pattern to keep in the commit
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   731
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   732
    Return 0 if changed files are uncommitted.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   733
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   734
    lock = repo.lock()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   735
    try:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   736
        wlock = repo.wlock()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   737
        try:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   738
            wctx = repo[None]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   739
            if len(wctx.parents()) <= 0:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   740
                raise util.Abort(_("cannot uncommit null changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   741
            if len(wctx.parents()) > 1:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   742
                raise util.Abort(_("cannot uncommit while merging"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   743
            old = repo['.']
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   744
            if old.phase() == phases.public:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   745
                raise util.Abort(_("cannot rewrite immutable changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   746
            if len(old.parents()) > 1:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   747
                raise util.Abort(_("cannot uncommit merge changeset"))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   748
            oldphase = old.phase()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   749
            updatebookmarks = _bookmarksupdater(repo, old.node())
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   750
            # Recommit the filtered changeset
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   751
            newid = None
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   752
            if (pats or opts.get('include') or opts.get('exclude')
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
   753
                or opts.get('all')):
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   754
                match = scmutil.match(old, pats, opts)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   755
                newid = _commitfiltered(repo, old, match)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   756
            if newid is None:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   757
                raise util.Abort(_('nothing to uncommit'))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   758
            # Move local changes on filtered changeset
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   759
            obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   760
            obsolete.createmarkers(repo, [(old, (repo[newid],))])
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   761
            phases.retractboundary(repo, oldphase, [newid])
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   762
            repo.dirstate.setparents(newid, node.nullid)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   763
            _uncommitdirstate(repo, old, match)
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   764
            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
   765
            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
   766
                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
   767
                ui.status(_('(use "hg kill ." to remove it)\n'))
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   768
        finally:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   769
            wlock.release()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   770
    finally:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   771
        lock.release()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
   772
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   773
def commitwrapper(orig, ui, repo, *arg, **kwargs):
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   774
    lock = repo.lock()
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   775
    try:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   776
        obsoleted = kwargs.get('obsolete', [])
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   777
        if obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   778
            obsoleted = repo.set('%lr', obsoleted)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   779
        result = orig(ui, repo, *arg, **kwargs)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   780
        if not result: # commit successed
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   781
            new = repo['-1']
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   782
            oldbookmarks = []
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   783
            obsolete = extensions.find('obsolete')
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   784
            markers = []
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   785
            for old in obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   786
                oldbookmarks.extend(repo.nodebookmarks(old.node()))
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   787
                markers.append((old, (new,)))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   788
            if markers:
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
   789
                obsolete.createmarkers(repo, markers)
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   790
            for book in oldbookmarks:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   791
                repo._bookmarks[book] = new.node()
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   792
            if oldbookmarks:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   793
                bookmarks.write(repo)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   794
        return result
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   795
    finally:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
   796
        lock.release()
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   797
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
   798
def graftwrapper(orig, ui, repo, *revs, **kwargs):
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   799
    kwargs = dict(kwargs)
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   800
    revs = list(revs) + kwargs.get('rev', [])
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   801
    kwargs['rev'] = []
417
a1fb18ad29a1 evolve: avoid duplication in graft wrapper
Patrick Mezard <patrick@mezard.eu>
parents: 416
diff changeset
   802
    obsoleted = kwargs.setdefault('obsolete', [])
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
   803
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   804
    lock = repo.lock()
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   805
    try:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   806
        if kwargs.get('old_obsolete'):
418
18a0d96ed559 evolve: graft --continue is optional, test
Patrick Mezard <patrick@mezard.eu>
parents: 417
diff changeset
   807
            if kwargs.get('continue'):
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   808
                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
   809
            else:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   810
                obsoleted.extend(revs)
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   811
        # 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
   812
        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
   813
        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
   814
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   815
            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
   816
                                'obsoleting (for now).'))
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
   817
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   818
        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
   819
    finally:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
   820
        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
   821
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   822
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
   823
    try:
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   824
        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
   825
    except KeyError:
416
22f348c25d25 obsolete/evolve: fix grammar in prerequisite messages
Patrick Mezard <patrick@mezard.eu>
parents: 414
diff changeset
   826
        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
   827
    try:
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
   828
        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
   829
    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
   830
        rebase = None
416
22f348c25d25 obsolete/evolve: fix grammar in prerequisite messages
Patrick Mezard <patrick@mezard.eu>
parents: 414
diff changeset
   831
        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
   832
356
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
   833
    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
   834
        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
   835
                                       obsolete.warnobserrors)
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
   836
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
   837
    entry = extensions.wrapcommand(commands.table, 'commit', commitwrapper)
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   838
    entry[1].append(('o', 'obsolete', [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   839
                     _("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
   840
    entry = extensions.wrapcommand(commands.table, 'graft', graftwrapper)
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   841
    entry[1].append(('o', 'obsolete', [],
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   842
                     _("make graft obsoletes this revision")))
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   843
    entry[1].append(('O', 'old-obsolete', False,
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   844
                     _("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
   845