hgext/shelve.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sat, 02 Aug 2014 21:46:26 +0900
changeset 22005 dabf8fb8a91e
parent 21852 37a5decc6924
child 22040 122fa73657c6
permissions -rw-r--r--
shelve: pass 'editform' argument to 'cmdutil.getcommiteditor' This patch passes 'editform' argument according to the format below: EXTENSION[.COMMAND][.ROUTE] - EXTENSION: name of extension - COMMAND: name of command, if there are two or more commands in EXTENSION - ROUTE: name of route, if there are two or more routes in COMMAND In this patch: - 'shelve' is used as COMMAND - ROUTE is omitted
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     1
# shelve.py - save/restore working directory state
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     2
#
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     3
# Copyright 2013 Facebook, Inc.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     4
#
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     7
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     8
"""save and restore changes to the working directory
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
     9
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    10
The "hg shelve" command saves changes made to the working directory
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    11
and reverts those changes, resetting the working directory to a clean
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    12
state.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    13
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    14
Later on, the "hg unshelve" command restores the changes saved by "hg
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    15
shelve". Changes can be restored even after updating to a different
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    16
parent, in which case Mercurial's merge machinery will resolve any
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    17
conflicts if necessary.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    18
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    19
You can have more than one shelved change outstanding at a time; each
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    20
shelved change has a distinct name. For details, see the help for "hg
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    21
shelve".
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    22
"""
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    23
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    24
from mercurial.i18n import _
20407
955547eb2e20 shelve: publicancestors do not have to visit nullrev
Mads Kiilerich <madski@unity3d.com>
parents: 20149
diff changeset
    25
from mercurial.node import nullid, nullrev, bin, hex
20409
0b7a9940a397 shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents: 20408
diff changeset
    26
from mercurial import changegroup, cmdutil, scmutil, phases, commands
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    27
from mercurial import error, hg, mdiff, merge, patch, repair, util
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20983
diff changeset
    28
from mercurial import templatefilters, changegroup, exchange
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    29
from mercurial import lock as lockmod
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
    30
from hgext import rebase
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    31
import errno
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    32
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    33
cmdtable = {}
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    34
command = cmdutil.command(cmdtable)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    35
testedwith = 'internal'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    36
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    37
class shelvedfile(object):
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
    38
    """Helper for the file storing a single shelve
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
    39
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
    40
    Handles common functions on shelve files (.hg/.files/.patch) using
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    41
    the vfs layer"""
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    42
    def __init__(self, repo, name, filetype=None):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    43
        self.repo = repo
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    44
        self.name = name
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    45
        self.vfs = scmutil.vfs(repo.join('shelved'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    46
        if filetype:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    47
            self.fname = name + '.' + filetype
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    48
        else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    49
            self.fname = name
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    50
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    51
    def exists(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    52
        return self.vfs.exists(self.fname)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    53
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    54
    def filename(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    55
        return self.vfs.join(self.fname)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    56
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    57
    def unlink(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    58
        util.unlink(self.filename())
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    59
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    60
    def stat(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    61
        return self.vfs.stat(self.fname)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    62
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    63
    def opener(self, mode='rb'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    64
        try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    65
            return self.vfs(self.fname, mode)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    66
        except IOError, err:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    67
            if err.errno != errno.ENOENT:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    68
                raise
19964
ff38dfbce4f8 shelve: remove useless and incorrect code paths for file access
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19963
diff changeset
    69
            raise util.Abort(_("shelved change '%s' not found") % self.name)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    70
20982
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    71
    def applybundle(self):
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    72
        fp = self.opener()
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    73
        try:
21064
4d9d490d7bbe bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21063
diff changeset
    74
            gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
20982
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    75
            changegroup.addchangegroup(self.repo, gen, 'unshelve',
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    76
                                       'bundle:' + self.vfs.join(self.fname))
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    77
        finally:
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    78
            fp.close()
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
    79
20983
2778616de7ce shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20982
diff changeset
    80
    def writebundle(self, cg):
2778616de7ce shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20982
diff changeset
    81
        changegroup.writebundle(cg, self.fname, 'HG10UN', self.vfs)
2778616de7ce shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20982
diff changeset
    82
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    83
class shelvedstate(object):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
    84
    """Handle persistence during unshelving operations.
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
    85
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
    86
    Handles saving and restoring a shelved state. Ensures that different
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
    87
    versions of a shelved state are possible and handles them appropriately.
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
    88
    """
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    89
    _version = 1
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    90
    _filename = 'shelvedstate'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    91
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    92
    @classmethod
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    93
    def load(cls, repo):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    94
        fp = repo.opener(cls._filename)
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
    95
        try:
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
    96
            version = int(fp.readline().strip())
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    97
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
    98
            if version != cls._version:
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
    99
                raise util.Abort(_('this version of shelve is incompatible '
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   100
                                   'with the version used in this repo'))
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   101
            name = fp.readline().strip()
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   102
            wctx = fp.readline().strip()
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   103
            pendingctx = fp.readline().strip()
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   104
            parents = [bin(h) for h in fp.readline().split()]
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   105
            stripnodes = [bin(h) for h in fp.readline().split()]
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   106
        finally:
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   107
            fp.close()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   108
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   109
        obj = cls()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   110
        obj.name = name
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   111
        obj.wctx = repo[bin(wctx)]
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   112
        obj.pendingctx = repo[bin(pendingctx)]
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   113
        obj.parents = parents
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   114
        obj.stripnodes = stripnodes
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   115
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   116
        return obj
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   117
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   118
    @classmethod
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   119
    def save(cls, repo, name, originalwctx, pendingctx, stripnodes):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   120
        fp = repo.opener(cls._filename, 'wb')
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   121
        fp.write('%i\n' % cls._version)
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   122
        fp.write('%s\n' % name)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   123
        fp.write('%s\n' % hex(originalwctx.node()))
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   124
        fp.write('%s\n' % hex(pendingctx.node()))
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   125
        fp.write('%s\n' % ' '.join([hex(p) for p in repo.dirstate.parents()]))
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   126
        fp.write('%s\n' % ' '.join([hex(n) for n in stripnodes]))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   127
        fp.close()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   128
19908
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
   129
    @classmethod
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
   130
    def clear(cls, repo):
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
   131
        util.unlinkpath(repo.join(cls._filename), ignoremissing=True)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   132
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   133
def createcmd(ui, repo, pats, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   134
    """subcommand that creates a new shelve"""
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   135
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   136
    def publicancestors(ctx):
20408
3392695abd68 shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents: 20407
diff changeset
   137
        """Compute the public ancestors of a commit.
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   138
20408
3392695abd68 shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents: 20407
diff changeset
   139
        Much faster than the revset ancestors(ctx) & draft()"""
20407
955547eb2e20 shelve: publicancestors do not have to visit nullrev
Mads Kiilerich <madski@unity3d.com>
parents: 20149
diff changeset
   140
        seen = set([nullrev])
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   141
        visit = util.deque()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   142
        visit.append(ctx)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   143
        while visit:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   144
            ctx = visit.popleft()
20408
3392695abd68 shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents: 20407
diff changeset
   145
            yield ctx.node()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   146
            for parent in ctx.parents():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   147
                rev = parent.rev()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   148
                if rev not in seen:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   149
                    seen.add(rev)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   150
                    if parent.mutable():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   151
                        visit.append(parent)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   152
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   153
    wctx = repo[None]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   154
    parents = wctx.parents()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   155
    if len(parents) > 1:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   156
        raise util.Abort(_('cannot shelve while merging'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   157
    parent = parents[0]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   158
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   159
    # we never need the user, so we use a generic user for all shelve operations
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   160
    user = 'shelve@localhost'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   161
    label = repo._bookmarkcurrent or parent.branch() or 'default'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   162
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   163
    # slashes aren't allowed in filenames, therefore we rename it
20937
c0bf8bea10dd shelve: remove unused variable caught by pyflakes
Sean Farley <sean.michael.farley@gmail.com>
parents: 20149
diff changeset
   164
    label = label.replace('/', '_')
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   165
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   166
    def gennames():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   167
        yield label
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   168
        for i in xrange(1, 100):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   169
            yield '%s-%02d' % (label, i)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   170
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   171
    shelvedfiles = []
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   172
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   173
    def commitfunc(ui, repo, message, match, opts):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   174
        # check modified, added, removed, deleted only
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   175
        for flist in repo.status(match=match)[:4]:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   176
            shelvedfiles.extend(flist)
19885
6cc696179869 shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents: 19881
diff changeset
   177
        hasmq = util.safehasattr(repo, 'mq')
6cc696179869 shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents: 19881
diff changeset
   178
        if hasmq:
6cc696179869 shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents: 19881
diff changeset
   179
            saved, repo.mq.checkapplied = repo.mq.checkapplied, False
19856
28b1b7b9b4a9 shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents: 19855
diff changeset
   180
        try:
22005
dabf8fb8a91e shelve: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21852
diff changeset
   181
            editor = cmdutil.getcommiteditor(editform='shelve.shelve', **opts)
21852
37a5decc6924 shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21851
diff changeset
   182
            return repo.commit(message, user, opts.get('date'), match,
22005
dabf8fb8a91e shelve: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21852
diff changeset
   183
                               editor=editor)
19856
28b1b7b9b4a9 shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents: 19855
diff changeset
   184
        finally:
19885
6cc696179869 shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents: 19881
diff changeset
   185
            if hasmq:
6cc696179869 shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents: 19881
diff changeset
   186
                repo.mq.checkapplied = saved
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   187
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   188
    if parent.node() != nullid:
20411
66359d8b8d7e shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents: 20410
diff changeset
   189
        desc = "changes to '%s'" % parent.description().split('\n', 1)[0]
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   190
    else:
20411
66359d8b8d7e shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents: 20410
diff changeset
   191
        desc = '(changes in empty repository)'
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   192
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   193
    if not opts['message']:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   194
        opts['message'] = desc
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   195
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   196
    name = opts['name']
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   197
19874
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   198
    wlock = lock = tr = bms = None
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   199
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   200
        wlock = repo.wlock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   201
        lock = repo.lock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   202
19874
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   203
        bms = repo._bookmarks.copy()
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 19943
diff changeset
   204
        # use an uncommitted transaction to generate the bundle to avoid
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   205
        # pull races. ensure we don't print the abort message to stderr.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   206
        tr = repo.transaction('commit', report=lambda x: None)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   207
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   208
        if name:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   209
            if shelvedfile(repo, name, 'hg').exists():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   210
                raise util.Abort(_("a shelved change named '%s' already exists")
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   211
                                 % name)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   212
        else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   213
            for n in gennames():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   214
                if not shelvedfile(repo, n, 'hg').exists():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   215
                    name = n
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   216
                    break
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   217
            else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   218
                raise util.Abort(_("too many shelved changes named '%s'") %
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   219
                                 label)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   220
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   221
        # ensure we are not creating a subdirectory or a hidden file
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   222
        if '/' in name or '\\' in name:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   223
            raise util.Abort(_('shelved change names may not contain slashes'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   224
        if name.startswith('.'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   225
            raise util.Abort(_("shelved change names may not start with '.'"))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   226
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   227
        node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   228
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   229
        if not node:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   230
            stat = repo.status(match=scmutil.match(repo[None], pats, opts))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   231
            if stat[3]:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   232
                ui.status(_("nothing changed (%d missing files, see "
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   233
                            "'hg status')\n") % len(stat[3]))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   234
            else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   235
                ui.status(_("nothing changed\n"))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   236
            return 1
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   237
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   238
        phases.retractboundary(repo, phases.secret, [node])
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   239
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   240
        fp = shelvedfile(repo, name, 'files').opener('wb')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   241
        fp.write('\0'.join(shelvedfiles))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   242
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   243
        bases = list(publicancestors(repo[node]))
20927
24a443948627 localrepo: move the changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20413
diff changeset
   244
        cg = changegroup.changegroupsubset(repo, bases, [node], 'shelve')
20983
2778616de7ce shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20982
diff changeset
   245
        shelvedfile(repo, name, 'hg').writebundle(cg)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   246
        cmdutil.export(repo, [node],
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   247
                       fp=shelvedfile(repo, name, 'patch').opener('wb'),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   248
                       opts=mdiff.diffopts(git=True))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   249
19874
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   250
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   251
        if ui.formatted():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   252
            desc = util.ellipsis(desc, ui.termwidth())
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   253
        ui.status(_('shelved as %s\n') % name)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   254
        hg.update(repo, parent.node())
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   255
    finally:
19874
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   256
        if bms:
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   257
            # restore old bookmarks
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   258
            repo._bookmarks.update(bms)
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   259
            repo._bookmarks.write()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   260
        if tr:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   261
            tr.abort()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   262
        lockmod.release(lock, wlock)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   263
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   264
def cleanupcmd(ui, repo):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   265
    """subcommand that deletes all shelves"""
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   266
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   267
    wlock = None
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   268
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   269
        wlock = repo.wlock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   270
        for (name, _) in repo.vfs.readdir('shelved'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   271
            suffix = name.rsplit('.', 1)[-1]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   272
            if suffix in ('hg', 'files', 'patch'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   273
                shelvedfile(repo, name).unlink()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   274
    finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   275
        lockmod.release(wlock)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   276
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   277
def deletecmd(ui, repo, pats):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   278
    """subcommand that deletes a specific shelve"""
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   279
    if not pats:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   280
        raise util.Abort(_('no shelved changes specified!'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   281
    wlock = None
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   282
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   283
        wlock = repo.wlock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   284
        try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   285
            for name in pats:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   286
                for suffix in 'hg files patch'.split():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   287
                    shelvedfile(repo, name, suffix).unlink()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   288
        except OSError, err:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   289
            if err.errno != errno.ENOENT:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   290
                raise
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   291
            raise util.Abort(_("shelved change '%s' not found") % name)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   292
    finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   293
        lockmod.release(wlock)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   294
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   295
def listshelves(repo):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   296
    """return all shelves in repo as list of (time, filename)"""
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   297
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   298
        names = repo.vfs.readdir('shelved')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   299
    except OSError, err:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   300
        if err.errno != errno.ENOENT:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   301
            raise
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   302
        return []
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   303
    info = []
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   304
    for (name, _) in names:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   305
        pfx, sfx = name.rsplit('.', 1)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   306
        if not pfx or sfx != 'patch':
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   307
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   308
        st = shelvedfile(repo, name).stat()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   309
        info.append((st.st_mtime, shelvedfile(repo, pfx).filename()))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   310
    return sorted(info, reverse=True)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   311
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   312
def listcmd(ui, repo, pats, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   313
    """subcommand that displays the list of shelves"""
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   314
    pats = set(pats)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   315
    width = 80
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   316
    if not ui.plain():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   317
        width = ui.termwidth()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   318
    namelabel = 'shelve.newest'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   319
    for mtime, name in listshelves(repo):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   320
        sname = util.split(name)[1]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   321
        if pats and sname not in pats:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   322
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   323
        ui.write(sname, label=namelabel)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   324
        namelabel = 'shelve.name'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   325
        if ui.quiet:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   326
            ui.write('\n')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   327
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   328
        ui.write(' ' * (16 - len(sname)))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   329
        used = 16
19855
a3b285882724 shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents: 19854
diff changeset
   330
        age = '(%s)' % templatefilters.age(util.makedate(mtime), abbrev=True)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   331
        ui.write(age, label='shelve.age')
19855
a3b285882724 shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents: 19854
diff changeset
   332
        ui.write(' ' * (12 - len(age)))
a3b285882724 shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents: 19854
diff changeset
   333
        used += 12
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   334
        fp = open(name + '.patch', 'rb')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   335
        try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   336
            while True:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   337
                line = fp.readline()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   338
                if not line:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   339
                    break
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   340
                if not line.startswith('#'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   341
                    desc = line.rstrip()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   342
                    if ui.formatted():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   343
                        desc = util.ellipsis(desc, width - used)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   344
                    ui.write(desc)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   345
                    break
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   346
            ui.write('\n')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   347
            if not (opts['patch'] or opts['stat']):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   348
                continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   349
            difflines = fp.readlines()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   350
            if opts['patch']:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   351
                for chunk, label in patch.difflabel(iter, difflines):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   352
                    ui.write(chunk, label=label)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   353
            if opts['stat']:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   354
                for chunk, label in patch.diffstatui(difflines, width=width,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   355
                                                     git=True):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   356
                    ui.write(chunk, label=label)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   357
        finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   358
            fp.close()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   359
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   360
def checkparents(repo, state):
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   361
    """check parent while resuming an unshelve"""
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   362
    if state.parents != repo.dirstate.parents():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   363
        raise util.Abort(_('working directory parents do not match unshelve '
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   364
                           'state'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   365
19943
4de116871044 shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents: 19911
diff changeset
   366
def pathtofiles(repo, files):
4de116871044 shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents: 19911
diff changeset
   367
    cwd = repo.getcwd()
4de116871044 shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents: 19911
diff changeset
   368
    return [repo.pathto(f, cwd) for f in files]
4de116871044 shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents: 19911
diff changeset
   369
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   370
def unshelveabort(ui, repo, state, opts):
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   371
    """subcommand that abort an in-progress unshelve"""
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   372
    wlock = repo.wlock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   373
    lock = None
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   374
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   375
        checkparents(repo, state)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   376
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   377
        util.rename(repo.join('unshelverebasestate'),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   378
                    repo.join('rebasestate'))
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   379
        try:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   380
            rebase.rebase(ui, repo, **{
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   381
                'abort' : True
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   382
            })
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   383
        except Exception:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   384
            util.rename(repo.join('rebasestate'),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   385
                        repo.join('unshelverebasestate'))
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   386
            raise
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   387
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   388
        lock = repo.lock()
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   389
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   390
        mergefiles(ui, repo, state.wctx, state.pendingctx)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   391
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   392
        repair.strip(ui, repo, state.stripnodes, backup='none', topic='shelve')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   393
        shelvedstate.clear(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   394
        ui.warn(_("unshelve of '%s' aborted\n") % state.name)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   395
    finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   396
        lockmod.release(lock, wlock)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   397
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   398
def mergefiles(ui, repo, wctx, shelvectx):
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   399
    """updates to wctx and merges the changes from shelvectx into the
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   400
    dirstate."""
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   401
    oldquiet = ui.quiet
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   402
    try:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   403
        ui.quiet = True
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   404
        hg.update(repo, wctx.node())
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   405
        files = []
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   406
        files.extend(shelvectx.files())
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   407
        files.extend(shelvectx.parents()[0].files())
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   408
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   409
        # revert will overwrite unknown files, so move them out of the way
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   410
        m, a, r, d, u = repo.status(unknown=True)[:5]
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   411
        for file in u:
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   412
            if file in files:
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   413
                util.rename(file, file + ".orig")
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   414
        cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   415
                       *pathtofiles(repo, files),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   416
                       **{'no_backup': True})
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   417
    finally:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   418
        ui.quiet = oldquiet
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   419
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   420
def unshelvecleanup(ui, repo, name, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   421
    """remove related files after an unshelve"""
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   422
    if not opts['keep']:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   423
        for filetype in 'hg files patch'.split():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   424
            shelvedfile(repo, name, filetype).unlink()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   425
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   426
def unshelvecontinue(ui, repo, state, opts):
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   427
    """subcommand to continue an in-progress unshelve"""
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   428
    # We're finishing off a merge. First parent is our original
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   429
    # parent, second is the temporary "fake" commit we're unshelving.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   430
    wlock = repo.wlock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   431
    lock = None
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   432
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   433
        checkparents(repo, state)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   434
        ms = merge.mergestate(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   435
        if [f for f in ms if ms[f] == 'u']:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   436
            raise util.Abort(
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   437
                _("unresolved conflicts, can't continue"),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   438
                hint=_("see 'hg resolve', then 'hg unshelve --continue'"))
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   439
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   440
        lock = repo.lock()
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   441
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   442
        util.rename(repo.join('unshelverebasestate'),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   443
                    repo.join('rebasestate'))
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   444
        try:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   445
            rebase.rebase(ui, repo, **{
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   446
                'continue' : True
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   447
            })
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   448
        except Exception:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   449
            util.rename(repo.join('rebasestate'),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   450
                        repo.join('unshelverebasestate'))
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   451
            raise
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   452
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   453
        shelvectx = repo['tip']
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   454
        if not shelvectx in state.pendingctx.children():
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   455
            # rebase was a no-op, so it produced no child commit
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   456
            shelvectx = state.pendingctx
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   457
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   458
        mergefiles(ui, repo, state.wctx, shelvectx)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   459
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   460
        state.stripnodes.append(shelvectx.node())
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   461
        repair.strip(ui, repo, state.stripnodes, backup='none', topic='shelve')
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   462
        shelvedstate.clear(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   463
        unshelvecleanup(ui, repo, state.name, opts)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   464
        ui.status(_("unshelve of '%s' complete\n") % state.name)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   465
    finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   466
        lockmod.release(lock, wlock)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   467
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   468
@command('unshelve',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   469
         [('a', 'abort', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   470
           _('abort an incomplete unshelve operation')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   471
          ('c', 'continue', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   472
           _('continue an incomplete unshelve operation')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   473
          ('', 'keep', None,
20960
8e5b21ce8ee9 shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents: 20958
diff changeset
   474
           _('keep shelve after unshelving')),
8e5b21ce8ee9 shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents: 20958
diff changeset
   475
          ('', 'date', '',
8e5b21ce8ee9 shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents: 20958
diff changeset
   476
           _('set date for temporary commits (DEPRECATED)'), _('DATE'))],
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   477
         _('hg unshelve [SHELVED]'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   478
def unshelve(ui, repo, *shelved, **opts):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   479
    """restore a shelved change to the working directory
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   480
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   481
    This command accepts an optional name of a shelved change to
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   482
    restore. If none is given, the most recent shelved change is used.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   483
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   484
    If a shelved change is applied successfully, the bundle that
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   485
    contains the shelved changes is deleted afterwards.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   486
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   487
    Since you can restore a shelved change on top of an arbitrary
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   488
    commit, it is possible that unshelving will result in a conflict
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   489
    between your changes and the commits you are unshelving onto. If
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   490
    this occurs, you must resolve the conflict, then use
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   491
    ``--continue`` to complete the unshelve operation. (The bundle
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   492
    will not be deleted until you successfully complete the unshelve.)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   493
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   494
    (Alternatively, you can use ``--abort`` to abandon an unshelve
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   495
    that causes a conflict. This reverts the unshelved changes, and
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   496
    does not delete the bundle.)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   497
    """
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   498
    abortf = opts['abort']
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   499
    continuef = opts['continue']
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   500
    if not abortf and not continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   501
        cmdutil.checkunfinished(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   502
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   503
    if abortf or continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   504
        if abortf and continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   505
            raise util.Abort(_('cannot use both abort and continue'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   506
        if shelved:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   507
            raise util.Abort(_('cannot combine abort/continue with '
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   508
                               'naming a shelved change'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   509
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   510
        try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   511
            state = shelvedstate.load(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   512
        except IOError, err:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   513
            if err.errno != errno.ENOENT:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   514
                raise
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   515
            raise util.Abort(_('no unshelve operation underway'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   516
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   517
        if abortf:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   518
            return unshelveabort(ui, repo, state, opts)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   519
        elif continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   520
            return unshelvecontinue(ui, repo, state, opts)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   521
    elif len(shelved) > 1:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   522
        raise util.Abort(_('can only unshelve one change at a time'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   523
    elif not shelved:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   524
        shelved = listshelves(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   525
        if not shelved:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   526
            raise util.Abort(_('no shelved changes to apply!'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   527
        basename = util.split(shelved[0][1])[1]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   528
        ui.status(_("unshelving change '%s'\n") % basename)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   529
    else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   530
        basename = shelved[0]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   531
19970
065e6f1c9259 shelve: remove unused variable assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19964
diff changeset
   532
    if not shelvedfile(repo, basename, 'files').exists():
065e6f1c9259 shelve: remove unused variable assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19964
diff changeset
   533
        raise util.Abort(_("shelved change '%s' not found") % basename)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   534
20412
e584fc30456b shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents: 20411
diff changeset
   535
    oldquiet = ui.quiet
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   536
    wlock = lock = tr = None
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   537
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   538
        lock = repo.lock()
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   539
        wlock = repo.wlock()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   540
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   541
        tr = repo.transaction('unshelve', report=lambda x: None)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   542
        oldtiprev = len(repo)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   543
20958
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   544
        pctx = repo['.']
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   545
        tmpwctx = pctx
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   546
        # The goal is to have a commit structure like so:
20958
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   547
        # ...-> pctx -> tmpwctx -> shelvectx
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   548
        # where tmpwctx is an optional commit with the user's pending changes
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   549
        # and shelvectx is the unshelved changes. Then we merge it all down
20958
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   550
        # to the original pctx.
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   551
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   552
        # Store pending changes in a commit
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   553
        m, a, r, d = repo.status()[:4]
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   554
        if m or a or r or d:
20413
0ac94c0a3a38 shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents: 20412
diff changeset
   555
            ui.status(_("temporarily committing pending changes "
0ac94c0a3a38 shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents: 20412
diff changeset
   556
                        "(restore with 'hg unshelve --abort')\n"))
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   557
            def commitfunc(ui, repo, message, match, opts):
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   558
                hasmq = util.safehasattr(repo, 'mq')
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   559
                if hasmq:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   560
                    saved, repo.mq.checkapplied = repo.mq.checkapplied, False
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   561
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   562
                try:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   563
                    return repo.commit(message, 'shelve@localhost',
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   564
                                       opts.get('date'), match)
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   565
                finally:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   566
                    if hasmq:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   567
                        repo.mq.checkapplied = saved
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   568
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   569
            tempopts = {}
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   570
            tempopts['message'] = "pending changes temporary commit"
20960
8e5b21ce8ee9 shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents: 20958
diff changeset
   571
            tempopts['date'] = opts.get('date')
20412
e584fc30456b shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents: 20411
diff changeset
   572
            ui.quiet = True
e584fc30456b shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents: 20411
diff changeset
   573
            node = cmdutil.commit(ui, repo, commitfunc, [], tempopts)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   574
            tmpwctx = repo[node]
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   575
20982
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   576
        ui.quiet = True
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   577
        shelvedfile(repo, basename, 'hg').applybundle()
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   578
        nodes = [ctx.node() for ctx in repo.set('%d:', oldtiprev)]
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   579
        phases.retractboundary(repo, phases.secret, nodes)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   580
20412
e584fc30456b shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents: 20411
diff changeset
   581
        ui.quiet = oldquiet
e584fc30456b shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents: 20411
diff changeset
   582
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   583
        shelvectx = repo['tip']
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   584
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   585
        # If the shelve is not immediately on top of the commit
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   586
        # we'll be merging with, rebase it to be on top.
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   587
        if tmpwctx.node() != shelvectx.parents()[0].node():
20413
0ac94c0a3a38 shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents: 20412
diff changeset
   588
            ui.status(_('rebasing shelved changes\n'))
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   589
            try:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   590
                rebase.rebase(ui, repo, **{
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   591
                    'rev' : [shelvectx.rev()],
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   592
                    'dest' : str(tmpwctx.rev()),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   593
                    'keep' : True,
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   594
                })
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   595
            except error.InterventionRequired:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   596
                tr.close()
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   597
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   598
                stripnodes = [repo.changelog.node(rev)
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   599
                              for rev in xrange(oldtiprev, len(repo))]
20958
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   600
                shelvedstate.save(repo, basename, pctx, tmpwctx, stripnodes)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   601
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   602
                util.rename(repo.join('rebasestate'),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   603
                            repo.join('unshelverebasestate'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   604
                raise error.InterventionRequired(
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   605
                    _("unresolved conflicts (see 'hg resolve', then "
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   606
                      "'hg unshelve --continue')"))
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   607
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   608
            # refresh ctx after rebase completes
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   609
            shelvectx = repo['tip']
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   610
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   611
            if not shelvectx in tmpwctx.children():
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   612
                # rebase was a no-op, so it produced no child commit
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   613
                shelvectx = tmpwctx
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   614
20958
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   615
        mergefiles(ui, repo, pctx, shelvectx)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   616
        shelvedstate.clear(repo)
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   617
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   618
        # The transaction aborting will strip all the commits for us,
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   619
        # but it doesn't update the inmemory structures, so addchangegroup
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   620
        # hooks still fire and try to operate on the missing commits.
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   621
        # Clean up manually to prevent this.
20064
99c4b8f79324 shelve: unshelve using an unfiltered repository
David Soria Parra <davidsp@fb.com>
parents: 19970
diff changeset
   622
        repo.unfiltered().changelog.strip(oldtiprev, tr)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   623
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   624
        unshelvecleanup(ui, repo, basename, opts)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   625
    finally:
20412
e584fc30456b shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents: 20411
diff changeset
   626
        ui.quiet = oldquiet
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   627
        if tr:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   628
            tr.release()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   629
        lockmod.release(lock, wlock)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   630
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   631
@command('shelve',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   632
         [('A', 'addremove', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   633
           _('mark new/missing files as added/removed before shelving')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   634
          ('', 'cleanup', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   635
           _('delete all shelved changes')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   636
          ('', 'date', '',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   637
           _('shelve with the specified commit date'), _('DATE')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   638
          ('d', 'delete', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   639
           _('delete the named shelved change(s)')),
21852
37a5decc6924 shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21851
diff changeset
   640
          ('e', 'edit', False,
37a5decc6924 shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21851
diff changeset
   641
           _('invoke editor on commit messages')),
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   642
          ('l', 'list', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   643
           _('list current shelves')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   644
          ('m', 'message', '',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   645
           _('use text as shelve message'), _('TEXT')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   646
          ('n', 'name', '',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   647
           _('use the given name for the shelved commit'), _('NAME')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   648
          ('p', 'patch', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   649
           _('show patch')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   650
          ('', 'stat', None,
20409
0b7a9940a397 shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents: 20408
diff changeset
   651
           _('output diffstat-style summary of changes'))] + commands.walkopts,
20410
fc5354648224 shelve: mention FILE options in help
Mads Kiilerich <madski@unity3d.com>
parents: 20409
diff changeset
   652
         _('hg shelve [OPTION]... [FILE]...'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   653
def shelvecmd(ui, repo, *pats, **opts):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   654
    '''save and set aside changes from the working directory
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   655
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   656
    Shelving takes files that "hg status" reports as not clean, saves
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   657
    the modifications to a bundle (a shelved change), and reverts the
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   658
    files so that their state in the working directory becomes clean.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   659
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   660
    To restore these changes to the working directory, using "hg
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   661
    unshelve"; this will work even if you switch to a different
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   662
    commit.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   663
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   664
    When no files are specified, "hg shelve" saves all not-clean
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   665
    files. If specific files or directories are named, only changes to
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   666
    those files are shelved.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   667
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   668
    Each shelved change has a name that makes it easier to find later.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   669
    The name of a shelved change defaults to being based on the active
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   670
    bookmark, or if there is no active bookmark, the current named
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   671
    branch.  To specify a different name, use ``--name``.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   672
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   673
    To see a list of existing shelved changes, use the ``--list``
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   674
    option. For each shelved change, this will print its name, age,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   675
    and description; use ``--patch`` or ``--stat`` for more details.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   676
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   677
    To delete specific shelved changes, use ``--delete``. To delete
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   678
    all shelved changes, use ``--cleanup``.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   679
    '''
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   680
    cmdutil.checkunfinished(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   681
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   682
    allowables = [
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   683
        ('addremove', 'create'), # 'create' is pseudo action
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   684
        ('cleanup', 'cleanup'),
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   685
#       ('date', 'create'), # ignored for passing '--date "0 0"' in tests
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   686
        ('delete', 'delete'),
21852
37a5decc6924 shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21851
diff changeset
   687
        ('edit', 'create'),
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   688
        ('list', 'list'),
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   689
        ('message', 'create'),
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   690
        ('name', 'create'),
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   691
        ('patch', 'list'),
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   692
        ('stat', 'list'),
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   693
    ]
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   694
    def checkopt(opt):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   695
        if opts[opt]:
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   696
            for i, allowable in allowables:
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   697
                if opts[i] and opt != allowable:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   698
                    raise util.Abort(_("options '--%s' and '--%s' may not be "
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   699
                                       "used together") % (opt, i))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   700
            return True
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   701
    if checkopt('cleanup'):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   702
        if pats:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   703
            raise util.Abort(_("cannot specify names when using '--cleanup'"))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   704
        return cleanupcmd(ui, repo)
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   705
    elif checkopt('delete'):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   706
        return deletecmd(ui, repo, pats)
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   707
    elif checkopt('list'):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   708
        return listcmd(ui, repo, pats, opts)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   709
    else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   710
        for i in ('patch', 'stat'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   711
            if opts[i]:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   712
                raise util.Abort(_("option '--%s' may not be "
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   713
                                   "used when shelving a change") % (i,))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   714
        return createcmd(ui, repo, pats, opts)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   715
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   716
def extsetup(ui):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   717
    cmdutil.unfinishedstates.append(
19963
6f29cc567845 shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19961
diff changeset
   718
        [shelvedstate._filename, False, False,
6f29cc567845 shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19961
diff changeset
   719
         _('unshelve already in progress'),
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   720
         _("use 'hg unshelve --continue' or 'hg unshelve --abort'")])