hgext/shelve.py
author Kostia Balytskyi <ikostia@fb.com>
Sun, 14 May 2017 14:15:07 -0700
changeset 32284 16d424b97125
parent 31888 1c398f7f4aa4
child 32285 fe3105e6e051
permissions -rw-r--r--
shelve: refactor shelvestate loading This is a preparatory patch which separates file reading from the minimal validation we have (like turning version into int and checking that this version is supported). The purpose of this patch is to be able to read statefile form simplekeyvaluefile, which is implemented in the following patch.
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
"""
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    23
from __future__ import absolute_import
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    24
25113
0ca8410ea345 util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents: 25104
diff changeset
    25
import collections
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    26
import errno
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    27
import itertools
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28862
diff changeset
    28
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28862
diff changeset
    29
from mercurial.i18n import _
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    30
from mercurial import (
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
    31
    bookmarks,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    32
    bundle2,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    33
    bundlerepo,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    34
    changegroup,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    35
    cmdutil,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    36
    commands,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    37
    error,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    38
    exchange,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    39
    hg,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    40
    lock as lockmod,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    41
    mdiff,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    42
    merge,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    43
    node as nodemod,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    44
    patch,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    45
    phases,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    46
    repair,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    47
    scmutil,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    48
    templatefilters,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    49
    util,
31244
636f55b9ba23 vfs: use 'vfs' module directly in 'hgext.shelve'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31096
diff changeset
    50
    vfs as vfsmod,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    51
)
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    52
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    53
from . import (
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    54
    rebase,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    55
)
19854
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
cmdtable = {}
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    58
command = cmdutil.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29536
diff changeset
    59
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25113
diff changeset
    60
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25113
diff changeset
    61
# be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25113
diff changeset
    62
# leave the attribute unspecified.
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29536
diff changeset
    63
testedwith = 'ships-with-hg-core'
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    64
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
    65
backupdir = 'shelve-backup'
28862
39130afcce60 shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents: 28666
diff changeset
    66
shelvedir = 'shelved'
31554
7485e45807e4 shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents: 31543
diff changeset
    67
shelvefileextensions = ['hg', 'patch', 'oshelve']
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
    68
# universal extension is present in all types of shelves
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
    69
patchextension = 'patch'
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
    70
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
    71
# we never need the user, so we use a
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
    72
# generic user for all shelve operations
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
    73
shelveuser = 'shelve@localhost'
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
    74
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    75
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
    76
    """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
    77
22581
c5ece02fb211 shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22202
diff changeset
    78
    Handles common functions on shelve files (.hg/.patch) using
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    79
    the vfs layer"""
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    80
    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
    81
        self.repo = repo
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    82
        self.name = name
31335
3acc7af5859c shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31312
diff changeset
    83
        self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
3acc7af5859c shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31312
diff changeset
    84
        self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
23895
cda18ded2c48 changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents: 23877
diff changeset
    85
        self.ui = self.repo.ui
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    86
        if filetype:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    87
            self.fname = name + '.' + filetype
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    88
        else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    89
            self.fname = name
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    90
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    91
    def exists(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    92
        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
    93
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    94
    def filename(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    95
        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
    96
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    97
    def backupfilename(self):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    98
        def gennames(base):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    99
            yield base
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   100
            base, ext = base.rsplit('.', 1)
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   101
            for i in itertools.count(1):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   102
                yield '%s-%d.%s' % (base, i, ext)
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   103
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   104
        name = self.backupvfs.join(self.fname)
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   105
        for n in gennames(name):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   106
            if not self.backupvfs.exists(n):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   107
                return n
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   108
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   109
    def movetobackup(self):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   110
        if not self.backupvfs.isdir():
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   111
            self.backupvfs.makedir()
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   112
        util.rename(self.filename(), self.backupfilename())
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   113
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   114
    def stat(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   115
        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
   116
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   117
    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
   118
        try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   119
            return self.vfs(self.fname, mode)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25260
diff changeset
   120
        except IOError as err:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   121
            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
   122
                raise
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   123
            raise error.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
   124
20982
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   125
    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
   126
        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
   127
        try:
21064
4d9d490d7bbe bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21063
diff changeset
   128
            gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
26799
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   129
            if not isinstance(gen, bundle2.unbundle20):
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   130
                gen.apply(self.repo, 'unshelve',
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   131
                          'bundle:' + self.vfs.join(self.fname),
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   132
                          targetphase=phases.secret)
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   133
            if isinstance(gen, bundle2.unbundle20):
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   134
                bundle2.applybundle(self.repo, gen,
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   135
                                    self.repo.currenttransaction(),
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   136
                                    source='unshelve',
ae03d4190321 shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26697
diff changeset
   137
                                    url='bundle:' + self.vfs.join(self.fname))
20982
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   138
        finally:
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   139
            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
   140
22898
43816070284e shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents: 22844
diff changeset
   141
    def bundlerepo(self):
43816070284e shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents: 22844
diff changeset
   142
        return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root,
43816070284e shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents: 22844
diff changeset
   143
                                           self.vfs.join(self.fname))
26506
edecf059fda6 shelve: move changegroup generation inside writebundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26505
diff changeset
   144
    def writebundle(self, bases, node):
27931
1289a122cf3f shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27921
diff changeset
   145
        cgversion = changegroup.safeversion(self.repo)
1289a122cf3f shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27921
diff changeset
   146
        if cgversion == '01':
1289a122cf3f shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27921
diff changeset
   147
            btype = 'HG10BZ'
1289a122cf3f shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27921
diff changeset
   148
            compression = None
1289a122cf3f shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27921
diff changeset
   149
        else:
26507
ae29cffa05db shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26506
diff changeset
   150
            btype = 'HG20'
ae29cffa05db shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26506
diff changeset
   151
            compression = 'BZ'
ae29cffa05db shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26506
diff changeset
   152
ae29cffa05db shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26506
diff changeset
   153
        cg = changegroup.changegroupsubset(self.repo, bases, [node], 'shelve',
ae29cffa05db shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26506
diff changeset
   154
                                           version=cgversion)
28666
ae53ecc47414 bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 28573
diff changeset
   155
        bundle2.writebundle(self.ui, cg, self.fname, btype, self.vfs,
26507
ae29cffa05db shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26506
diff changeset
   156
                                compression=compression)
20983
2778616de7ce shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20982
diff changeset
   157
31554
7485e45807e4 shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents: 31543
diff changeset
   158
    def writeobsshelveinfo(self, info):
7485e45807e4 shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents: 31543
diff changeset
   159
        scmutil.simplekeyvaluefile(self.vfs, self.fname).write(info)
7485e45807e4 shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents: 31543
diff changeset
   160
7485e45807e4 shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents: 31543
diff changeset
   161
    def readobsshelveinfo(self):
7485e45807e4 shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents: 31543
diff changeset
   162
        return scmutil.simplekeyvaluefile(self.vfs, self.fname).read()
7485e45807e4 shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents: 31543
diff changeset
   163
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   164
class shelvedstate(object):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   165
    """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
   166
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   167
    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
   168
    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
   169
    """
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   170
    _version = 1
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   171
    _filename = 'shelvedstate'
30522
7b3136bc7bfd shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents: 30457
diff changeset
   172
    _keep = 'keep'
7b3136bc7bfd shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents: 30457
diff changeset
   173
    _nokeep = 'nokeep'
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   174
    # colon is essential to differentiate from a real bookmark name
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   175
    _noactivebook = ':no-active-bookmark'
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   176
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   177
    @classmethod
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   178
    def load(cls, repo):
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   179
        # Order is important, because old shelvestate file uses it
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   180
        # to detemine values of fields (i.g. version is on the first line,
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   181
        # name is on the second and so forth). Please do not change.
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   182
        keys = ['version', 'name', 'originalwctx', 'pendingctx', 'parents',
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   183
                'nodestoremove', 'branchtorestore', 'keep', 'activebook']
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   184
        d = {}
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 22922
diff changeset
   185
        fp = repo.vfs(cls._filename)
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   186
        try:
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   187
            for key in keys:
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   188
                d[key] = fp.readline().strip()
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   189
        finally:
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   190
            fp.close()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   191
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   192
        # some basic syntactic verification and transformation
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   193
        try:
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   194
            d['version'] = int(d['version'])
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   195
            if d['version'] != cls._version:
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   196
                raise error.Abort(_('this version of shelve is incompatible '
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   197
                                    'with the version used in this repo'))
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   198
            d['originalwctx'] = nodemod.bin(d['originalwctx'])
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   199
            d['pendingctx'] = nodemod.bin(d['pendingctx'])
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   200
            d['parents'] = [nodemod.bin(h)
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   201
                            for h in d['parents'].split(' ')]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   202
            d['nodestoremove'] = [nodemod.bin(h)
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   203
                                  for h in d['nodestoremove'].split(' ')]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   204
        except (ValueError, TypeError, KeyError) as err:
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   205
            raise error.CorruptedState(str(err))
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   206
29536
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   207
        try:
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   208
            obj = cls()
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   209
            obj.name = d['name']
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   210
            obj.wctx = repo[d['originalwctx']]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   211
            obj.pendingctx = repo[d['pendingctx']]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   212
            obj.parents = d['parents']
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   213
            obj.nodestoremove = d['nodestoremove']
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   214
            obj.branchtorestore = d.get('branchtorestore', '')
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   215
            obj.keep = d.get('keep') == cls._keep
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   216
            obj.activebookmark = ''
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   217
            if d.get('activebook', '') != cls._noactivebook:
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   218
                obj.activebookmark = d.get('activebook', '')
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   219
        except (error.RepoLookupError, KeyError) as err:
29536
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   220
            raise error.CorruptedState(str(err))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   221
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   222
        return obj
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   223
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   224
    @classmethod
31888
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   225
    def save(cls, repo, name, originalwctx, pendingctx, nodestoremove,
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   226
             branchtorestore, keep=False, activebook=''):
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 22922
diff changeset
   227
        fp = repo.vfs(cls._filename, 'wb')
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   228
        fp.write('%i\n' % cls._version)
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   229
        fp.write('%s\n' % name)
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
   230
        fp.write('%s\n' % nodemod.hex(originalwctx.node()))
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
   231
        fp.write('%s\n' % nodemod.hex(pendingctx.node()))
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
   232
        fp.write('%s\n' %
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
   233
                 ' '.join([nodemod.hex(p) for p in repo.dirstate.parents()]))
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
   234
        fp.write('%s\n' %
31888
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   235
                 ' '.join([nodemod.hex(n) for n in nodestoremove]))
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   236
        fp.write('%s\n' % branchtorestore)
30522
7b3136bc7bfd shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents: 30457
diff changeset
   237
        fp.write('%s\n' % (cls._keep if keep else cls._nokeep))
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   238
        fp.write('%s\n' % (activebook or cls._noactivebook))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   239
        fp.close()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   240
19908
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
   241
    @classmethod
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
   242
    def clear(cls, repo):
31311
f59b6cf663a9 vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents: 31244
diff changeset
   243
        repo.vfs.unlinkpath(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
   244
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   245
def cleanupoldbackups(repo):
31335
3acc7af5859c shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31312
diff changeset
   246
    vfs = vfsmod.vfs(repo.vfs.join(backupdir))
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   247
    maxbackups = repo.ui.configint('shelve', 'maxbackups', 10)
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   248
    hgfiles = [f for f in vfs.listdir()
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   249
               if f.endswith('.' + patchextension)]
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   250
    hgfiles = sorted([(vfs.stat(f).st_mtime, f) for f in hgfiles])
25774
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   251
    if 0 < maxbackups and maxbackups < len(hgfiles):
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   252
        bordermtime = hgfiles[-maxbackups][0]
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   253
    else:
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   254
        bordermtime = None
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   255
    for mtime, f in hgfiles[:len(hgfiles) - maxbackups]:
25774
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   256
        if mtime == bordermtime:
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   257
            # keep it, because timestamp can't decide exact order of backups
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   258
            continue
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   259
        base = f[:-(1 + len(patchextension))]
30378
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   260
        for ext in shelvefileextensions:
31543
d5758760c0f4 shelve: use tryunlink
Ryan McElroy <rmcelroy@fb.com>
parents: 31462
diff changeset
   261
            vfs.tryunlink(base + '.' + ext)
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   262
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   263
def _backupactivebookmark(repo):
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   264
    activebookmark = repo._activebookmark
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   265
    if activebookmark:
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   266
        bookmarks.deactivate(repo)
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   267
    return activebookmark
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   268
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   269
def _restoreactivebookmark(repo, mark):
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   270
    if mark:
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   271
        bookmarks.activate(repo, mark)
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   272
26522
10f14bb22950 shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26520
diff changeset
   273
def _aborttransaction(repo):
10f14bb22950 shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26520
diff changeset
   274
    '''Abort current transaction for shelve/unshelve, but keep dirstate
10f14bb22950 shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26520
diff changeset
   275
    '''
29270
48b38b16a8f8 shelve: use backup functions instead of manually copying dirstate
Mateusz Kwapich <mitrandir@fb.com>
parents: 29205
diff changeset
   276
    tr = repo.currenttransaction()
48b38b16a8f8 shelve: use backup functions instead of manually copying dirstate
Mateusz Kwapich <mitrandir@fb.com>
parents: 29205
diff changeset
   277
    repo.dirstate.savebackup(tr, suffix='.shelve')
48b38b16a8f8 shelve: use backup functions instead of manually copying dirstate
Mateusz Kwapich <mitrandir@fb.com>
parents: 29205
diff changeset
   278
    tr.abort()
48b38b16a8f8 shelve: use backup functions instead of manually copying dirstate
Mateusz Kwapich <mitrandir@fb.com>
parents: 29205
diff changeset
   279
    repo.dirstate.restorebackup(None, suffix='.shelve')
26522
10f14bb22950 shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26520
diff changeset
   280
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   281
def createcmd(ui, repo, pats, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   282
    """subcommand that creates a new shelve"""
27834
476f53058ee8 with: use context manager for wlock in shelve createcmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27775
diff changeset
   283
    with repo.wlock():
27198
7df042d0784f shelve: execute checkunfinished inside wlock scope
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27197
diff changeset
   284
        cmdutil.checkunfinished(repo)
27197
6df3ec5bb813 shelve: widen wlock scope of shelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27092
diff changeset
   285
        return _docreatecmd(ui, repo, pats, opts)
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   286
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   287
def getshelvename(repo, parent, opts):
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   288
    """Decide on the name this shelve is going to have"""
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   289
    def gennames():
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   290
        yield label
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   291
        for i in xrange(1, 100):
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   292
            yield '%s-%02d' % (label, i)
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   293
    name = opts.get('name')
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   294
    label = repo._activebookmark or parent.branch() or 'default'
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   295
    # slashes aren't allowed in filenames, therefore we rename it
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   296
    label = label.replace('/', '_')
30671
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   297
    label = label.replace('\\', '_')
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   298
    # filenames must not start with '.' as it should not be hidden
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   299
    if label.startswith('.'):
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   300
        label = label.replace('.', '_', 1)
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   301
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   302
    if name:
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   303
        if shelvedfile(repo, name, patchextension).exists():
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   304
            e = _("a shelved change named '%s' already exists") % name
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   305
            raise error.Abort(e)
30671
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   306
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   307
        # ensure we are not creating a subdirectory or a hidden file
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   308
        if '/' in name or '\\' in name:
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   309
            raise error.Abort(_('shelved change names can not contain slashes'))
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   310
        if name.startswith('.'):
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   311
            raise error.Abort(_("shelved change names can not start with '.'"))
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   312
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   313
    else:
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   314
        for n in gennames():
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   315
            if not shelvedfile(repo, n, patchextension).exists():
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   316
                name = n
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   317
                break
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   318
        else:
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   319
            raise error.Abort(_("too many shelved changes named '%s'") % label)
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   320
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   321
    return name
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   322
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   323
def mutableancestors(ctx):
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   324
    """return all mutable ancestors for ctx (included)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   325
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   326
    Much faster than the revset ancestors(ctx) & draft()"""
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   327
    seen = set([nodemod.nullrev])
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   328
    visit = collections.deque()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   329
    visit.append(ctx)
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   330
    while visit:
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   331
        ctx = visit.popleft()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   332
        yield ctx.node()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   333
        for parent in ctx.parents():
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   334
            rev = parent.rev()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   335
            if rev not in seen:
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   336
                seen.add(rev)
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   337
                if parent.mutable():
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   338
                    visit.append(parent)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   339
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   340
def getcommitfunc(extra, interactive, editor=False):
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   341
    def commitfunc(ui, repo, message, match, opts):
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   342
        hasmq = util.safehasattr(repo, 'mq')
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   343
        if hasmq:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   344
            saved, repo.mq.checkapplied = repo.mq.checkapplied, False
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   345
        overrides = {('phases', 'new-commit'): phases.secret}
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   346
        try:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   347
            editor_ = False
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   348
            if editor:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   349
                editor_ = cmdutil.getcommiteditor(editform='shelve.shelve',
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   350
                                                  **opts)
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   351
            with repo.ui.configoverride(overrides):
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   352
                return repo.commit(message, shelveuser, opts.get('date'),
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   353
                                   match, editor=editor_, extra=extra)
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   354
        finally:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   355
            if hasmq:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   356
                repo.mq.checkapplied = saved
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   357
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   358
    def interactivecommitfunc(ui, repo, *pats, **opts):
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   359
        match = scmutil.match(repo['.'], pats, {})
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   360
        message = opts['message']
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   361
        return commitfunc(ui, repo, message, match, opts)
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   362
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   363
    return interactivecommitfunc if interactive else commitfunc
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   364
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   365
def _nothingtoshelvemessaging(ui, repo, pats, opts):
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   366
    stat = repo.status(match=scmutil.match(repo[None], pats, opts))
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   367
    if stat.deleted:
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   368
        ui.status(_("nothing changed (%d missing files, see "
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   369
                    "'hg status')\n") % len(stat.deleted))
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   370
    else:
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   371
        ui.status(_("nothing changed\n"))
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   372
30383
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   373
def _shelvecreatedcommit(repo, node, name):
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   374
    bases = list(mutableancestors(repo[node]))
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   375
    shelvedfile(repo, name, 'hg').writebundle(bases, node)
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   376
    cmdutil.export(repo, [node],
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   377
                   fp=shelvedfile(repo, name, patchextension).opener('wb'),
30383
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   378
                   opts=mdiff.diffopts(git=True))
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   379
30384
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   380
def _includeunknownfiles(repo, pats, opts, extra):
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   381
    s = repo.status(match=scmutil.match(repo[None], pats, opts),
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   382
                    unknown=True)
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   383
    if s.unknown:
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   384
        extra['shelve_unknown'] = '\0'.join(s.unknown)
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   385
        repo[None].add(s.unknown)
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   386
30385
b573d7ca31c4 shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30384
diff changeset
   387
def _finishshelve(repo):
b573d7ca31c4 shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30384
diff changeset
   388
    _aborttransaction(repo)
b573d7ca31c4 shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30384
diff changeset
   389
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   390
def _docreatecmd(ui, repo, pats, opts):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   391
    wctx = repo[None]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   392
    parents = wctx.parents()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   393
    if len(parents) > 1:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   394
        raise error.Abort(_('cannot shelve while merging'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   395
    parent = parents[0]
28571
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   396
    origbranch = wctx.branch()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   397
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
   398
    if parent.node() != nodemod.nullid:
27092
156985f2dec0 shelve: use colon instead of quotes in 'changes to' description
Siddharth Agarwal <sid0@fb.com>
parents: 27021
diff changeset
   399
        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
   400
    else:
20411
66359d8b8d7e shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents: 20410
diff changeset
   401
        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
   402
28401
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   403
    if not opts.get('message'):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   404
        opts['message'] = desc
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   405
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   406
    lock = tr = activebookmark = None
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   407
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   408
        lock = repo.lock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   409
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 19943
diff changeset
   410
        # 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
   411
        # 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
   412
        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
   413
24477
325f03de849d shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents: 23895
diff changeset
   414
        interactive = opts.get('interactive', False)
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   415
        includeunknown = (opts.get('unknown', False) and
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   416
                          not opts.get('addremove', False))
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   417
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   418
        name = getshelvename(repo, parent, opts)
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   419
        activebookmark = _backupactivebookmark(repo)
30384
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   420
        extra = {}
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   421
        if includeunknown:
30384
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   422
            _includeunknownfiles(repo, pats, opts, extra)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   423
28572
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   424
        if _iswctxonnewbranch(repo) and not _isbareshelve(pats, opts):
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   425
            # In non-bare shelve we don't store newly created branch
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   426
            # at bundled commit
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   427
            repo.dirstate.setbranch(repo['.'].branch())
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   428
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   429
        commitfunc = getcommitfunc(extra, interactive, editor=True)
24478
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
   430
        if not interactive:
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
   431
            node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
   432
        else:
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   433
            node = cmdutil.dorecord(ui, repo, commitfunc, None,
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   434
                                    False, cmdutil.recordfilter, *pats,
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   435
                                    **opts)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   436
        if not node:
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   437
            _nothingtoshelvemessaging(ui, repo, pats, opts)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   438
            return 1
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   439
30383
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   440
        _shelvecreatedcommit(repo, node, name)
19874
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   441
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   442
        if ui.formatted():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   443
            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
   444
        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
   445
        hg.update(repo, parent.node())
28571
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   446
        if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   447
            repo.dirstate.setbranch(origbranch)
26523
1d23bf6cd90a shelve: restore shelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26522
diff changeset
   448
30385
b573d7ca31c4 shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30384
diff changeset
   449
        _finishshelve(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   450
    finally:
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   451
        _restoreactivebookmark(repo, activebookmark)
27197
6df3ec5bb813 shelve: widen wlock scope of shelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27092
diff changeset
   452
        lockmod.release(tr, lock)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   453
28571
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   454
def _isbareshelve(pats, opts):
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   455
    return (not pats
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   456
            and not opts.get('interactive', False)
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   457
            and not opts.get('include', False)
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   458
            and not opts.get('exclude', False))
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   459
28572
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   460
def _iswctxonnewbranch(repo):
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   461
    return repo[None].branch() != repo['.'].branch()
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   462
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   463
def cleanupcmd(ui, repo):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   464
    """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
   465
27835
c448d7e00bf9 with: use context manager for wlock in shelve cleanupcmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27834
diff changeset
   466
    with repo.wlock():
28862
39130afcce60 shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents: 28666
diff changeset
   467
        for (name, _type) in repo.vfs.readdir(shelvedir):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   468
            suffix = name.rsplit('.', 1)[-1]
30378
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   469
            if suffix in shelvefileextensions:
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   470
                shelvedfile(repo, name).movetobackup()
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   471
            cleanupoldbackups(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   472
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   473
def deletecmd(ui, repo, pats):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   474
    """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
   475
    if not pats:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   476
        raise error.Abort(_('no shelved changes specified!'))
27836
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   477
    with repo.wlock():
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   478
        try:
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   479
            for name in pats:
30378
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   480
                for suffix in shelvefileextensions:
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   481
                    shfile = shelvedfile(repo, name, suffix)
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   482
                    # patch file is necessary, as it should
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   483
                    # be present for any kind of shelve,
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   484
                    # but the .hg file is optional as in future we
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   485
                    # will add obsolete shelve with does not create a
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   486
                    # bundle
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   487
                    if shfile.exists() or suffix == patchextension:
30378
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   488
                        shfile.movetobackup()
27836
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   489
            cleanupoldbackups(repo)
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   490
        except OSError as err:
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   491
            if err.errno != errno.ENOENT:
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   492
                raise
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   493
            raise error.Abort(_("shelved change '%s' not found") % name)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   494
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   495
def listshelves(repo):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   496
    """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
   497
    try:
28862
39130afcce60 shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents: 28666
diff changeset
   498
        names = repo.vfs.readdir(shelvedir)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25260
diff changeset
   499
    except OSError as err:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   500
        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
   501
            raise
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   502
        return []
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   503
    info = []
22199
b3e51675f98e cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents: 22184
diff changeset
   504
    for (name, _type) in names:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   505
        pfx, sfx = name.rsplit('.', 1)
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   506
        if not pfx or sfx != patchextension:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   507
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   508
        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
   509
        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
   510
    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
   511
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   512
def listcmd(ui, repo, pats, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   513
    """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
   514
    pats = set(pats)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   515
    width = 80
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   516
    if not ui.plain():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   517
        width = ui.termwidth()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   518
    namelabel = 'shelve.newest'
31096
356937ea7a02 pager: add support to --patch, --list and --stat options of hg shelve
Pulkit Goyal <7895pulkit@gmail.com>
parents: 31021
diff changeset
   519
    ui.pager('shelve')
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   520
    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
   521
        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
   522
        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
   523
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   524
        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
   525
        namelabel = 'shelve.name'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   526
        if ui.quiet:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   527
            ui.write('\n')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   528
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   529
        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
   530
        used = 16
19855
a3b285882724 shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents: 19854
diff changeset
   531
        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
   532
        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
   533
        ui.write(' ' * (12 - len(age)))
a3b285882724 shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents: 19854
diff changeset
   534
        used += 12
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   535
        with open(name + '.' + patchextension, 'rb') as fp:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   536
            while True:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   537
                line = fp.readline()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   538
                if not line:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   539
                    break
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   540
                if not line.startswith('#'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   541
                    desc = line.rstrip()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   542
                    if ui.formatted():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   543
                        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
   544
                    ui.write(desc)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   545
                    break
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   546
            ui.write('\n')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   547
            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
   548
                continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   549
            difflines = fp.readlines()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   550
            if opts['patch']:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   551
                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
   552
                    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
   553
            if opts['stat']:
30407
e1677cc29da6 patch: remove unused git parameter from patch.diffstat()
Henning Schild <henning@hennsch.de>
parents: 30385
diff changeset
   554
                for chunk, label in patch.diffstatui(difflines, width=width):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   555
                    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
   556
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   557
def patchcmds(ui, repo, pats, opts, subcommand):
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   558
    """subcommand that displays shelves"""
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   559
    if len(pats) == 0:
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   560
        raise error.Abort(_("--%s expects at least one shelf") % subcommand)
25104
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   561
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   562
    for shelfname in pats:
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   563
        if not shelvedfile(repo, shelfname, patchextension).exists():
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   564
            raise error.Abort(_("cannot find shelf %s") % shelfname)
25104
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   565
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   566
    listcmd(ui, repo, pats, opts)
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   567
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   568
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
   569
    """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
   570
    if state.parents != repo.dirstate.parents():
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   571
        raise error.Abort(_('working directory parents do not match unshelve '
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   572
                           'state'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   573
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
   574
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
   575
    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
   576
    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
   577
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   578
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
   579
    """subcommand that abort an in-progress unshelve"""
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   580
    with repo.lock():
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   581
        try:
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   582
            checkparents(repo, state)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   583
31312
7eb53603744b vfs: use repo.vfs.rename
Mads Kiilerich <mads@kiilerich.com>
parents: 31311
diff changeset
   584
            repo.vfs.rename('unshelverebasestate', 'rebasestate')
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   585
            try:
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   586
                rebase.rebase(ui, repo, **{
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   587
                    'abort' : True
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   588
                })
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   589
            except Exception:
31312
7eb53603744b vfs: use repo.vfs.rename
Mads Kiilerich <mads@kiilerich.com>
parents: 31311
diff changeset
   590
                repo.vfs.rename('rebasestate', 'unshelverebasestate')
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   591
                raise
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   592
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   593
            mergefiles(ui, repo, state.wctx, state.pendingctx)
31888
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   594
            repair.strip(ui, repo, state.nodestoremove, backup=False,
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   595
                         topic='shelve')
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   596
        finally:
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   597
            shelvedstate.clear(repo)
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   598
            ui.warn(_("unshelve of '%s' aborted\n") % state.name)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   599
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   600
def mergefiles(ui, repo, wctx, shelvectx):
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   601
    """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
   602
    dirstate."""
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   603
    with ui.configoverride({('ui', 'quiet'): True}):
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   604
        hg.update(repo, wctx.node())
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   605
        files = []
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   606
        files.extend(shelvectx.files())
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   607
        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
   608
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   609
        # revert will overwrite unknown files, so move them out of the way
22922
ebef5fcf7bd0 shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22898
diff changeset
   610
        for file in repo.status(unknown=True).unknown:
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   611
            if file in files:
27651
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 27288
diff changeset
   612
                util.rename(file, scmutil.origpath(ui, repo, file))
22184
fb8065de47b0 unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents: 22057
diff changeset
   613
        ui.pushbuffer(True)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   614
        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
   615
                       *pathtofiles(repo, files),
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   616
                       **{'no_backup': True})
22184
fb8065de47b0 unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents: 22057
diff changeset
   617
        ui.popbuffer()
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   618
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   619
def restorebranch(ui, repo, branchtorestore):
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   620
    if branchtorestore and branchtorestore != repo.dirstate.branch():
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   621
        repo.dirstate.setbranch(branchtorestore)
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   622
        ui.status(_('marked working directory as branch %s\n')
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   623
                  % branchtorestore)
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   624
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   625
def unshelvecleanup(ui, repo, name, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   626
    """remove related files after an unshelve"""
28401
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   627
    if not opts.get('keep'):
30378
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   628
        for filetype in shelvefileextensions:
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   629
            shfile = shelvedfile(repo, name, filetype)
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   630
            if shfile.exists():
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   631
                shfile.movetobackup()
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   632
        cleanupoldbackups(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   633
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   634
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
   635
    """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
   636
    # 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
   637
    # parent, second is the temporary "fake" commit we're unshelving.
27838
60b850b7e4ef with: use context manager for lock in continue
Bryan O'Sullivan <bryano@fb.com>
parents: 27837
diff changeset
   638
    with repo.lock():
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   639
        checkparents(repo, state)
26992
b3b5ed560283 shelve: switch to mergestate.read()
Siddharth Agarwal <sid0@fb.com>
parents: 26942
diff changeset
   640
        ms = merge.mergestate.read(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   641
        if [f for f in ms if ms[f] == 'u']:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   642
            raise error.Abort(
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   643
                _("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
   644
                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
   645
31312
7eb53603744b vfs: use repo.vfs.rename
Mads Kiilerich <mads@kiilerich.com>
parents: 31311
diff changeset
   646
        repo.vfs.rename('unshelverebasestate', 'rebasestate')
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   647
        try:
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   648
            rebase.rebase(ui, repo, **{
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   649
                'continue' : True
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   650
            })
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   651
        except Exception:
31312
7eb53603744b vfs: use repo.vfs.rename
Mads Kiilerich <mads@kiilerich.com>
parents: 31311
diff changeset
   652
            repo.vfs.rename('rebasestate', 'unshelverebasestate')
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   653
            raise
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   654
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   655
        shelvectx = repo['tip']
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   656
        if not shelvectx in state.pendingctx.children():
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   657
            # 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
   658
            shelvectx = state.pendingctx
22842
d43d116a118c shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21852
diff changeset
   659
        else:
d43d116a118c shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21852
diff changeset
   660
            # only strip the shelvectx if the rebase produced it
31888
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   661
            state.nodestoremove.append(shelvectx.node())
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   662
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   663
        mergefiles(ui, repo, state.wctx, shelvectx)
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   664
        restorebranch(ui, repo, state.branchtorestore)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   665
31888
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   666
        repair.strip(ui, repo, state.nodestoremove, backup=False,
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   667
                     topic='shelve')
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   668
        _restoreactivebookmark(repo, state.activebookmark)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   669
        shelvedstate.clear(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   670
        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
   671
        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
   672
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   673
def _commitworkingcopychanges(ui, repo, opts, tmpwctx):
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   674
    """Temporarily commit working copy changes before moving unshelve commit"""
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   675
    # Store pending changes in a commit and remember added in case a shelve
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   676
    # contains unknown files that are part of the pending change
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   677
    s = repo.status()
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   678
    addedbefore = frozenset(s.added)
30846
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   679
    if not (s.modified or s.added or s.removed):
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   680
        return tmpwctx, addedbefore
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   681
    ui.status(_("temporarily committing pending changes "
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   682
                "(restore with 'hg unshelve --abort')\n"))
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   683
    commitfunc = getcommitfunc(extra=None, interactive=False,
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   684
                               editor=False)
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   685
    tempopts = {}
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   686
    tempopts['message'] = "pending changes temporary commit"
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   687
    tempopts['date'] = opts.get('date')
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   688
    with ui.configoverride({('ui', 'quiet'): True}):
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   689
        node = cmdutil.commit(ui, repo, commitfunc, [], tempopts)
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   690
    tmpwctx = repo[node]
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   691
    return tmpwctx, addedbefore
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   692
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   693
def _unshelverestorecommit(ui, repo, basename):
30454
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
   694
    """Recreate commit in the repository during the unshelve"""
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   695
    with ui.configoverride({('ui', 'quiet'): True}):
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   696
        shelvedfile(repo, basename, 'hg').applybundle()
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   697
        shelvectx = repo['tip']
30454
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
   698
    return repo, shelvectx
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
   699
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   700
def _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, basename, pctx,
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   701
                          tmpwctx, shelvectx, branchtorestore,
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   702
                          activebookmark):
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   703
    """Rebase restored commit from its original location to a destination"""
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   704
    # If the shelve is not immediately on top of the commit
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   705
    # we'll be merging with, rebase it to be on top.
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   706
    if tmpwctx.node() == shelvectx.parents()[0].node():
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   707
        return shelvectx
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   708
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   709
    ui.status(_('rebasing shelved changes\n'))
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   710
    try:
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   711
        rebase.rebase(ui, repo, **{
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   712
            'rev': [shelvectx.rev()],
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   713
            'dest': str(tmpwctx.rev()),
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   714
            'keep': True,
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   715
            'tool': opts.get('tool', ''),
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   716
        })
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   717
    except error.InterventionRequired:
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   718
        tr.close()
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   719
31888
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   720
        nodestoremove = [repo.changelog.node(rev)
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   721
                         for rev in xrange(oldtiprev, len(repo))]
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   722
        shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove,
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   723
                          branchtorestore, opts.get('keep'), activebookmark)
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   724
31312
7eb53603744b vfs: use repo.vfs.rename
Mads Kiilerich <mads@kiilerich.com>
parents: 31311
diff changeset
   725
        repo.vfs.rename('rebasestate', 'unshelverebasestate')
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   726
        raise error.InterventionRequired(
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   727
            _("unresolved conflicts (see 'hg resolve', then "
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   728
              "'hg unshelve --continue')"))
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   729
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   730
    # refresh ctx after rebase completes
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   731
    shelvectx = repo['tip']
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   732
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   733
    if not shelvectx in tmpwctx.children():
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   734
        # rebase was a no-op, so it produced no child commit
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   735
        shelvectx = tmpwctx
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   736
    return shelvectx
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   737
30456
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   738
def _forgetunknownfiles(repo, shelvectx, addedbefore):
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   739
    # Forget any files that were unknown before the shelve, unknown before
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   740
    # unshelve started, but are now added.
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   741
    shelveunknown = shelvectx.extra().get('shelve_unknown')
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   742
    if not shelveunknown:
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   743
        return
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   744
    shelveunknown = frozenset(shelveunknown.split('\0'))
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   745
    addedafter = frozenset(repo.status().added)
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   746
    toforget = (addedafter & shelveunknown) - addedbefore
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   747
    repo[None].forget(toforget)
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   748
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   749
def _finishunshelve(repo, oldtiprev, tr, activebookmark):
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   750
    _restoreactivebookmark(repo, activebookmark)
30457
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   751
    # The transaction aborting will strip all the commits for us,
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   752
    # but it doesn't update the inmemory structures, so addchangegroup
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   753
    # hooks still fire and try to operate on the missing commits.
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   754
    # Clean up manually to prevent this.
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   755
    repo.unfiltered().changelog.strip(oldtiprev, tr)
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   756
    _aborttransaction(repo)
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   757
30846
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   758
def _checkunshelveuntrackedproblems(ui, repo, shelvectx):
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   759
    """Check potential problems which may result from working
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   760
    copy having untracked changes."""
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   761
    wcdeleted = set(repo.status().deleted)
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   762
    shelvetouched = set(shelvectx.files())
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   763
    intersection = wcdeleted.intersection(shelvetouched)
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   764
    if intersection:
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   765
        m = _("shelved change touches missing files")
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   766
        hint = _("run hg status to see which files are missing")
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   767
        raise error.Abort(m, hint=hint)
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   768
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   769
@command('unshelve',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   770
         [('a', 'abort', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   771
           _('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
   772
          ('c', 'continue', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   773
           _('continue an incomplete unshelve operation')),
27019
5cf184398ee7 unshelve: add -k as short form of --keep
Siddharth Agarwal <sid0@fb.com>
parents: 26992
diff changeset
   774
          ('k', 'keep', None,
20960
8e5b21ce8ee9 shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents: 20958
diff changeset
   775
           _('keep shelve after unshelving')),
31021
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   776
          ('n', 'name', '',
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   777
           _('restore shelved change with given name'), _('NAME')),
27021
f2554154509f unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents: 27020
diff changeset
   778
          ('t', 'tool', '', _('specify merge tool')),
20960
8e5b21ce8ee9 shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents: 20958
diff changeset
   779
          ('', 'date', '',
8e5b21ce8ee9 shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents: 20958
diff changeset
   780
           _('set date for temporary commits (DEPRECATED)'), _('DATE'))],
31021
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   781
         _('hg unshelve [[-n] SHELVED]'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   782
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
   783
    """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
   784
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   785
    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
   786
    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
   787
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   788
    If a shelved change is applied successfully, the bundle that
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   789
    contains the shelved changes is moved to a backup location
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   790
    (.hg/shelve-backup).
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   791
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   792
    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
   793
    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
   794
    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
   795
    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
   796
    ``--continue`` to complete the unshelve operation. (The bundle
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   797
    will not be moved until you successfully complete the unshelve.)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   798
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   799
    (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
   800
    that causes a conflict. This reverts the unshelved changes, and
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   801
    leaves the bundle in place.)
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   802
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   803
    If bare shelved change(when no files are specified, without interactive,
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   804
    include and exclude option) was done on newly created branch it would
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   805
    restore branch information to the working directory.
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   806
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   807
    After a successful unshelve, the shelved changes are stored in a
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   808
    backup directory. Only the N most recent backups are kept. N
25852
870e361e049c shelve: make maxbackup doc check-config friendly
Matt Mackall <mpm@selenic.com>
parents: 25799
diff changeset
   809
    defaults to 10 but can be overridden using the ``shelve.maxbackups``
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   810
    configuration option.
25774
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   811
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   812
    .. container:: verbose
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   813
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   814
       Timestamp in seconds is used to decide order of backups. More
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   815
       than ``maxbackups`` backups are kept, if same timestamp
4f8c20fe66f0 shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25713
diff changeset
   816
       prevents from deciding exact order of them, for safety.
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   817
    """
27837
496ca4deddc5 with: use context manager for wlock in unshelve
Bryan O'Sullivan <bryano@fb.com>
parents: 27836
diff changeset
   818
    with repo.wlock():
27287
c9ceea3f2d8e shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27198
diff changeset
   819
        return _dounshelve(ui, repo, *shelved, **opts)
c9ceea3f2d8e shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27198
diff changeset
   820
c9ceea3f2d8e shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27198
diff changeset
   821
def _dounshelve(ui, repo, *shelved, **opts):
28401
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   822
    abortf = opts.get('abort')
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   823
    continuef = opts.get('continue')
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   824
    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
   825
        cmdutil.checkunfinished(repo)
31021
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   826
    shelved = list(shelved)
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   827
    if opts.get("name"):
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   828
        shelved.append(opts["name"])
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   829
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   830
    if abortf or continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   831
        if abortf and continuef:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   832
            raise error.Abort(_('cannot use both abort and continue'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   833
        if shelved:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   834
            raise error.Abort(_('cannot combine abort/continue with '
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   835
                               'naming a shelved change'))
27021
f2554154509f unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents: 27020
diff changeset
   836
        if abortf and opts.get('tool', False):
f2554154509f unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents: 27020
diff changeset
   837
            ui.warn(_('tool option will be ignored\n'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   838
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   839
        try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   840
            state = shelvedstate.load(repo)
30522
7b3136bc7bfd shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents: 30457
diff changeset
   841
            if opts.get('keep') is None:
7b3136bc7bfd shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents: 30457
diff changeset
   842
                opts['keep'] = state.keep
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25260
diff changeset
   843
        except IOError as err:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   844
            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
   845
                raise
28124
983365382465 shelve: suggest the correct tool to continue (not unshelve)
timeless <timeless@mozdev.org>
parents: 27931
diff changeset
   846
            cmdutil.wrongtooltocontinue(repo, _('unshelve'))
29536
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   847
        except error.CorruptedState as err:
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   848
            ui.debug(str(err) + '\n')
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   849
            if continuef:
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   850
                msg = _('corrupted shelved state file')
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   851
                hint = _('please run hg unshelve --abort to abort unshelve '
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   852
                         'operation')
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   853
                raise error.Abort(msg, hint=hint)
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   854
            elif abortf:
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   855
                msg = _('could not read shelved state file, your working copy '
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   856
                        'may be in an unexpected state\nplease update to some '
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   857
                        'commit\n')
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   858
                ui.warn(msg)
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   859
                shelvedstate.clear(repo)
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   860
            return
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   861
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   862
        if abortf:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   863
            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
   864
        elif continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   865
            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
   866
    elif len(shelved) > 1:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   867
        raise error.Abort(_('can only unshelve one change at a time'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   868
    elif not shelved:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   869
        shelved = listshelves(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   870
        if not shelved:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   871
            raise error.Abort(_('no shelved changes to apply!'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   872
        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
   873
        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
   874
    else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   875
        basename = shelved[0]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   876
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   877
    if not shelvedfile(repo, basename, patchextension).exists():
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   878
        raise error.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
   879
27287
c9ceea3f2d8e shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27198
diff changeset
   880
    lock = tr = None
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   881
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   882
        lock = repo.lock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   883
        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
   884
        oldtiprev = len(repo)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   885
20958
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   886
        pctx = repo['.']
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   887
        tmpwctx = pctx
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   888
        # 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
   889
        # ...-> pctx -> tmpwctx -> shelvectx
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   890
        # 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
   891
        # 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
   892
        # to the original pctx.
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   893
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   894
        activebookmark = _backupactivebookmark(repo)
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   895
        overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   896
        with ui.configoverride(overrides, 'unshelve'):
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   897
            tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   898
                                                             tmpwctx)
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   899
            repo, shelvectx = _unshelverestorecommit(ui, repo, basename)
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   900
            _checkunshelveuntrackedproblems(ui, repo, shelvectx)
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   901
            branchtorestore = ''
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   902
            if shelvectx.branch() != shelvectx.p1().branch():
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   903
                branchtorestore = shelvectx.branch()
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   904
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   905
            shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev,
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   906
                                              basename, pctx, tmpwctx,
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   907
                                              shelvectx, branchtorestore,
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   908
                                              activebookmark)
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   909
            mergefiles(ui, repo, pctx, shelvectx)
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   910
            restorebranch(ui, repo, branchtorestore)
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   911
            _forgetunknownfiles(repo, shelvectx, addedbefore)
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   912
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   913
            shelvedstate.clear(repo)
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   914
            _finishunshelve(repo, oldtiprev, tr, activebookmark)
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   915
            unshelvecleanup(ui, repo, basename, opts)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   916
    finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   917
        if tr:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   918
            tr.release()
27287
c9ceea3f2d8e shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27198
diff changeset
   919
        lockmod.release(lock)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   920
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   921
@command('shelve',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   922
         [('A', 'addremove', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   923
           _('mark new/missing files as added/removed before shelving')),
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   924
          ('u', 'unknown', None,
27921
158bdc896572 shelve: lowercase flag description
timeless <timeless@mozdev.org>
parents: 27908
diff changeset
   925
           _('store unknown files in the shelve')),
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   926
          ('', 'cleanup', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   927
           _('delete all shelved changes')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   928
          ('', 'date', '',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   929
           _('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
   930
          ('d', 'delete', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   931
           _('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
   932
          ('e', 'edit', False,
37a5decc6924 shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21851
diff changeset
   933
           _('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
   934
          ('l', 'list', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   935
           _('list current shelves')),
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   936
          ('m', 'message', '',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   937
           _('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
   938
          ('n', 'name', '',
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   939
           _('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
   940
          ('p', 'patch', None,
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   941
           _('show patch')),
24477
325f03de849d shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents: 23895
diff changeset
   942
          ('i', 'interactive', None,
25260
8fa3e995a375 selve: make 'shelve --interactive' not experimental
Laurent Charignon <lcharignon@fb.com>
parents: 25186
diff changeset
   943
           _('interactive mode, only works while creating a shelve')),
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   944
          ('', 'stat', None,
20409
0b7a9940a397 shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents: 20408
diff changeset
   945
           _('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
   946
         _('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
   947
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
   948
    '''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
   949
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   950
    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
   951
    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
   952
    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
   953
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   954
    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
   955
    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
   956
    commit.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   957
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   958
    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
   959
    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
   960
    those files are shelved.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   961
30419
819f96b82fa4 shelve: add missing space in help text
Mads Kiilerich <madski@unity3d.com>
parents: 29841
diff changeset
   962
    In bare shelve (when no files are specified, without interactive,
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   963
    include and exclude option), shelving remembers information if the
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   964
    working directory was on newly created branch, in other words working
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   965
    directory was on different branch than its first parent. In this
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   966
    situation unshelving restores branch information to the working directory.
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   967
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   968
    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
   969
    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
   970
    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
   971
    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
   972
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   973
    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
   974
    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
   975
    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
   976
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   977
    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
   978
    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
   979
    '''
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   980
    allowables = [
25103
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   981
        ('addremove', set(['create'])), # 'create' is pseudo action
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   982
        ('unknown', set(['create'])),
25103
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   983
        ('cleanup', set(['cleanup'])),
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   984
#       ('date', set(['create'])), # ignored for passing '--date "0 0"' in tests
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   985
        ('delete', set(['delete'])),
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   986
        ('edit', set(['create'])),
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   987
        ('list', set(['list'])),
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   988
        ('message', set(['create'])),
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   989
        ('name', set(['create'])),
25104
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   990
        ('patch', set(['patch', 'list'])),
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   991
        ('stat', set(['stat', 'list'])),
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   992
    ]
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   993
    def checkopt(opt):
28401
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   994
        if opts.get(opt):
21851
aad28ff87788 shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21064
diff changeset
   995
            for i, allowable in allowables:
25103
ce00b2e96d09 shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents: 25080
diff changeset
   996
                if opts[i] and opt not in allowable:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   997
                    raise error.Abort(_("options '--%s' and '--%s' may not be "
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   998
                                       "used together") % (opt, i))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   999
            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
  1000
    if checkopt('cleanup'):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1001
        if pats:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
  1002
            raise error.Abort(_("cannot specify names when using '--cleanup'"))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1003
        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
  1004
    elif checkopt('delete'):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1005
        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
  1006
    elif checkopt('list'):
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1007
        return listcmd(ui, repo, pats, opts)
25104
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
  1008
    elif checkopt('patch'):
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
  1009
        return patchcmds(ui, repo, pats, opts, subcommand='patch')
25104
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
  1010
    elif checkopt('stat'):
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
  1011
        return patchcmds(ui, repo, pats, opts, subcommand='stat')
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1012
    else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1013
        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
  1014
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1015
def extsetup(ui):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1016
    cmdutil.unfinishedstates.append(
19963
6f29cc567845 shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19961
diff changeset
  1017
        [shelvedstate._filename, False, False,
6f29cc567845 shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19961
diff changeset
  1018
         _('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
  1019
         _("use 'hg unshelve --continue' or 'hg unshelve --abort'")])
27694
2dc363274702 shelve: hook afterresolvedstates
timeless <timeless@mozdev.org>
parents: 27651
diff changeset
  1020
    cmdutil.afterresolvedstates.append(
2dc363274702 shelve: hook afterresolvedstates
timeless <timeless@mozdev.org>
parents: 27651
diff changeset
  1021
        [shelvedstate._filename, _('hg unshelve --continue')])