mercurial/shelve.py
author Navaneeth Suresh <navaneeths1998@gmail.com>
Wed, 24 Jul 2019 18:15:27 +0530
changeset 42702 4814d993fe21
parent 42668 52a383451739
child 42703 073cfff9aaef
permissions -rw-r--r--
unshelve: handle stripping changesets on interactive mode On interactive mode, changesets on `nodestoremove` should be stripped regardless of the shelve is partial or not. This patch modifies `unshelvecontinue()` to do that. Differential Revision: https://phab.mercurial-scm.org/D6686
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
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    28
import stat
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28862
diff changeset
    29
42541
3de4f17f4824 shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42540
diff changeset
    30
from .i18n import _
3de4f17f4824 shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42540
diff changeset
    31
from . import (
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
    32
    bookmarks,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    33
    bundle2,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    34
    bundlerepo,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    35
    changegroup,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    36
    cmdutil,
34097
f7d41b85bbf6 changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents: 33440
diff changeset
    37
    discovery,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    38
    error,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    39
    exchange,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    40
    hg,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    41
    lock as lockmod,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    42
    mdiff,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    43
    merge,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    44
    node as nodemod,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    45
    patch,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    46
    phases,
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
    47
    pycompat,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    48
    repair,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    49
    scmutil,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    50
    templatefilters,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    51
    util,
31244
636f55b9ba23 vfs: use 'vfs' module directly in 'hgext.shelve'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31096
diff changeset
    52
    vfs as vfsmod,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
    53
)
42541
3de4f17f4824 shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42540
diff changeset
    54
from .utils import (
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
    55
    dateutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
    56
    stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
    57
)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    58
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
    59
backupdir = 'shelve-backup'
28862
39130afcce60 shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents: 28666
diff changeset
    60
shelvedir = 'shelved'
39372
da121c9dc0f2 shelve: store shelved node in a new data file
Boris Feld <boris.feld@octobus.net>
parents: 39344
diff changeset
    61
shelvefileextensions = ['hg', 'patch', 'shelve']
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
    62
# 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
    63
patchextension = 'patch'
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
    64
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
    65
# 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
    66
# generic user for all shelve operations
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
    67
shelveuser = 'shelve@localhost'
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
    68
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    69
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
    70
    """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
    71
22581
c5ece02fb211 shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22202
diff changeset
    72
    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
    73
    the vfs layer"""
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    74
    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
    75
        self.repo = repo
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    76
        self.name = name
31335
3acc7af5859c shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31312
diff changeset
    77
        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
    78
        self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
23895
cda18ded2c48 changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents: 23877
diff changeset
    79
        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
    80
        if filetype:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    81
            self.fname = name + '.' + filetype
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    82
        else:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    83
            self.fname = name
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    84
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    85
    def exists(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    86
        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
    87
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    88
    def filename(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
    89
        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
    90
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    91
    def backupfilename(self):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    92
        def gennames(base):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    93
            yield base
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    94
            base, ext = base.rsplit('.', 1)
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    95
            for i in itertools.count(1):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    96
                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
    97
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    98
        name = self.backupvfs.join(self.fname)
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
    99
        for n in gennames(name):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   100
            if not self.backupvfs.exists(n):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   101
                return n
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   102
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   103
    def movetobackup(self):
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   104
        if not self.backupvfs.isdir():
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   105
            self.backupvfs.makedir()
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   106
        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
   107
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   108
    def stat(self):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   109
        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
   110
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   111
    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
   112
        try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   113
            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
   114
        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
   115
            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
   116
                raise
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   117
            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
   118
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   119
    def applybundle(self, tr):
20982
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   120
        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
   121
        try:
39519
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   122
            targetphase = phases.internal
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   123
            if not phases.supportinternal(self.repo):
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   124
                targetphase = phases.secret
21064
4d9d490d7bbe bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21063
diff changeset
   125
            gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
39889
d9ba836fc234 shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents: 39888
diff changeset
   126
            pretip = self.repo['tip']
d9ba836fc234 shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents: 39888
diff changeset
   127
            bundle2.applybundle(self.repo, gen, tr,
33043
18c2489ac96d bundle: make applybundle() delegate v1 bundles to applybundle1()
Martin von Zweigbergk <martinvonz@google.com>
parents: 33039
diff changeset
   128
                                source='unshelve',
18c2489ac96d bundle: make applybundle() delegate v1 bundles to applybundle1()
Martin von Zweigbergk <martinvonz@google.com>
parents: 33039
diff changeset
   129
                                url='bundle:' + self.vfs.join(self.fname),
39519
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   130
                                targetphase=targetphase)
39889
d9ba836fc234 shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents: 39888
diff changeset
   131
            shelvectx = self.repo['tip']
d9ba836fc234 shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents: 39888
diff changeset
   132
            if pretip == shelvectx:
d9ba836fc234 shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents: 39888
diff changeset
   133
                shelverev = tr.changes['revduplicates'][-1]
d9ba836fc234 shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents: 39888
diff changeset
   134
                shelvectx = self.repo[shelverev]
d9ba836fc234 shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents: 39888
diff changeset
   135
            return shelvectx
20982
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   136
        finally:
1df99f1ea28d shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20960
diff changeset
   137
            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
   138
22898
43816070284e shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents: 22844
diff changeset
   139
    def bundlerepo(self):
39601
84d6e9a2b104 shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39519
diff changeset
   140
        path = self.vfs.join(self.fname)
84d6e9a2b104 shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39519
diff changeset
   141
        return bundlerepo.instance(self.repo.baseui,
84d6e9a2b104 shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39519
diff changeset
   142
                                   'bundle://%s+%s' % (self.repo.root, path))
84d6e9a2b104 shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39519
diff changeset
   143
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
39373
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
   153
        repo = self.repo.unfiltered()
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
   154
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
   155
        outgoing = discovery.outgoing(repo, missingroots=bases,
34097
f7d41b85bbf6 changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents: 33440
diff changeset
   156
                                      missingheads=[node])
39373
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
   157
        cg = changegroup.makechangegroup(repo, outgoing, cgversion, 'shelve')
34097
f7d41b85bbf6 changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents: 33440
diff changeset
   158
28666
ae53ecc47414 bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 28573
diff changeset
   159
        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
   160
                                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
   161
39343
bab58b1d87c7 shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents: 39342
diff changeset
   162
    def writeinfo(self, info):
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
   163
        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
   164
39343
bab58b1d87c7 shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents: 39342
diff changeset
   165
    def readinfo(self):
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
   166
        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
   167
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   168
class shelvedstate(object):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   169
    """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
   170
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   171
    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
   172
    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
   173
    """
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   174
    _version = 2
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   175
    _filename = 'shelvedstate'
30522
7b3136bc7bfd shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents: 30457
diff changeset
   176
    _keep = 'keep'
7b3136bc7bfd shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents: 30457
diff changeset
   177
    _nokeep = 'nokeep'
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   178
    # 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
   179
    _noactivebook = ':no-active-bookmark'
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   180
    _interactive = 'interactive'
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   181
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   182
    @classmethod
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   183
    def _verifyandtransform(cls, d):
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   184
        """Some basic shelvestate syntactic verification and transformation"""
19904
5b327880a660 shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19887
diff changeset
   185
        try:
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   186
            d['originalwctx'] = nodemod.bin(d['originalwctx'])
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   187
            d['pendingctx'] = nodemod.bin(d['pendingctx'])
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   188
            d['parents'] = [nodemod.bin(h)
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   189
                            for h in d['parents'].split(' ')]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   190
            d['nodestoremove'] = [nodemod.bin(h)
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   191
                                  for h in d['nodestoremove'].split(' ')]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   192
        except (ValueError, TypeError, KeyError) as err:
36496
7af7443877da py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36185
diff changeset
   193
            raise error.CorruptedState(pycompat.bytestr(err))
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   194
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   195
    @classmethod
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   196
    def _getversion(cls, repo):
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   197
        """Read version information from shelvestate file"""
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   198
        fp = repo.vfs(cls._filename)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   199
        try:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   200
            version = int(fp.readline().strip())
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   201
        except ValueError as err:
36496
7af7443877da py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36185
diff changeset
   202
            raise error.CorruptedState(pycompat.bytestr(err))
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   203
        finally:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   204
            fp.close()
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   205
        return version
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   206
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   207
    @classmethod
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   208
    def _readold(cls, repo):
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   209
        """Read the old position-based version of a shelvestate file"""
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   210
        # Order is important, because old shelvestate file uses it
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   211
        # to detemine values of fields (i.g. name is on the second line,
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   212
        # originalwctx is on the third and so forth). Please do not change.
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   213
        keys = ['version', 'name', 'originalwctx', 'pendingctx', 'parents',
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   214
                'nodestoremove', 'branchtorestore', 'keep', 'activebook']
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   215
        # this is executed only seldomly, so it is not a big deal
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   216
        # that we open this file twice
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   217
        fp = repo.vfs(cls._filename)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   218
        d = {}
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   219
        try:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   220
            for key in keys:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   221
                d[key] = fp.readline().strip()
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   222
        finally:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   223
            fp.close()
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   224
        return d
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   225
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   226
    @classmethod
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   227
    def load(cls, repo):
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   228
        version = cls._getversion(repo)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   229
        if version < cls._version:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   230
            d = cls._readold(repo)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   231
        elif version == cls._version:
41759
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 41596
diff changeset
   232
            d = scmutil.simplekeyvaluefile(
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 41596
diff changeset
   233
                repo.vfs, cls._filename).read(firstlinenonkeyval=True)
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   234
        else:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   235
            raise error.Abort(_('this version of shelve is incompatible '
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   236
                                'with the version used in this repo'))
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   237
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   238
        cls._verifyandtransform(d)
29536
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   239
        try:
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
   240
            obj = cls()
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   241
            obj.name = d['name']
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   242
            obj.wctx = repo[d['originalwctx']]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   243
            obj.pendingctx = repo[d['pendingctx']]
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   244
            obj.parents = d['parents']
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   245
            obj.nodestoremove = d['nodestoremove']
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   246
            obj.branchtorestore = d.get('branchtorestore', '')
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   247
            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
   248
            obj.activebookmark = ''
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   249
            if d.get('activebook', '') != cls._noactivebook:
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   250
                obj.activebookmark = d.get('activebook', '')
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   251
            obj.interactive = d.get('interactive') == cls._interactive
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
   252
        except (error.RepoLookupError, KeyError) as err:
36496
7af7443877da py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36185
diff changeset
   253
            raise error.CorruptedState(pycompat.bytestr(err))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   254
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   255
        return obj
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   256
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   257
    @classmethod
31888
1c398f7f4aa4 shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents: 31757
diff changeset
   258
    def save(cls, repo, name, originalwctx, pendingctx, nodestoremove,
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   259
             branchtorestore, keep=False, activebook='', interactive=False):
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   260
        info = {
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   261
            "name": name,
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   262
            "originalwctx": nodemod.hex(originalwctx.node()),
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   263
            "pendingctx": nodemod.hex(pendingctx.node()),
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   264
            "parents": ' '.join([nodemod.hex(p)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   265
                                 for p in repo.dirstate.parents()]),
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   266
            "nodestoremove": ' '.join([nodemod.hex(n)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   267
                                      for n in nodestoremove]),
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   268
            "branchtorestore": branchtorestore,
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   269
            "keep": cls._keep if keep else cls._nokeep,
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   270
            "activebook": activebook or cls._noactivebook
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
   271
        }
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   272
        if interactive:
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   273
            info['interactive'] = cls._interactive
41759
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 41596
diff changeset
   274
        scmutil.simplekeyvaluefile(
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 41596
diff changeset
   275
            repo.vfs, cls._filename).write(info,
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 41596
diff changeset
   276
                                           firstline=("%d" % cls._version))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   277
19908
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
   278
    @classmethod
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
   279
    def clear(cls, repo):
31311
f59b6cf663a9 vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents: 31244
diff changeset
   280
        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
   281
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   282
def cleanupoldbackups(repo):
31335
3acc7af5859c shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31312
diff changeset
   283
    vfs = vfsmod.vfs(repo.vfs.join(backupdir))
34496
18cd210535b3 configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents: 34097
diff changeset
   284
    maxbackups = repo.ui.configint('shelve', 'maxbackups')
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   285
    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
   286
               if f.endswith('.' + patchextension)]
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
   287
    hgfiles = sorted([(vfs.stat(f)[stat.ST_MTIME], f) for f in hgfiles])
40029
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 39889
diff changeset
   288
    if maxbackups > 0 and maxbackups < len(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
   289
        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
   290
    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
   291
        bordermtime = None
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   292
    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
   293
        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
   294
            # 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
   295
            continue
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   296
        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
   297
        for ext in shelvefileextensions:
31543
d5758760c0f4 shelve: use tryunlink
Ryan McElroy <rmcelroy@fb.com>
parents: 31462
diff changeset
   298
            vfs.tryunlink(base + '.' + ext)
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   299
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   300
def _backupactivebookmark(repo):
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   301
    activebookmark = repo._activebookmark
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   302
    if activebookmark:
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   303
        bookmarks.deactivate(repo)
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   304
    return activebookmark
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   305
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   306
def _restoreactivebookmark(repo, mark):
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   307
    if mark:
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   308
        bookmarks.activate(repo, mark)
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   309
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   310
def _aborttransaction(repo, tr):
26522
10f14bb22950 shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26520
diff changeset
   311
    '''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
   312
    '''
38869
ad24b581e4d9 narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents: 38783
diff changeset
   313
    dirstatebackupname = 'dirstate.shelve'
ad24b581e4d9 narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents: 38783
diff changeset
   314
    repo.dirstate.savebackup(tr, dirstatebackupname)
29270
48b38b16a8f8 shelve: use backup functions instead of manually copying dirstate
Mateusz Kwapich <mitrandir@fb.com>
parents: 29205
diff changeset
   315
    tr.abort()
38869
ad24b581e4d9 narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents: 38783
diff changeset
   316
    repo.dirstate.restorebackup(None, dirstatebackupname)
26522
10f14bb22950 shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26520
diff changeset
   317
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   318
def getshelvename(repo, parent, opts):
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   319
    """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
   320
    def gennames():
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   321
        yield label
32968
4107eb8a5648 shelve: allow unlimited shelved changes per name
Jun Wu <quark@fb.com>
parents: 32930
diff changeset
   322
        for i in itertools.count(1):
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   323
            yield '%s-%02d' % (label, i)
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   324
    name = opts.get('name')
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   325
    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
   326
    # 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
   327
    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
   328
    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
   329
    # 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
   330
    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
   331
        label = label.replace('.', '_', 1)
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   332
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   333
    if name:
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   334
        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
   335
            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
   336
            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
   337
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
   338
        # 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
   339
        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
   340
            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
   341
        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
   342
            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
   343
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   344
    else:
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   345
        for n in gennames():
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   346
            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
   347
                name = n
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   348
                break
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   349
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   350
    return name
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   351
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   352
def mutableancestors(ctx):
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   353
    """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
   354
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   355
    Much faster than the revset ancestors(ctx) & draft()"""
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32285
diff changeset
   356
    seen = {nodemod.nullrev}
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   357
    visit = collections.deque()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   358
    visit.append(ctx)
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   359
    while visit:
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   360
        ctx = visit.popleft()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   361
        yield ctx.node()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   362
        for parent in ctx.parents():
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   363
            rev = parent.rev()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   364
            if rev not in seen:
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   365
                seen.add(rev)
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   366
                if parent.mutable():
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   367
                    visit.append(parent)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   368
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   369
def getcommitfunc(extra, interactive, editor=False):
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   370
    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
   371
        hasmq = util.safehasattr(repo, 'mq')
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   372
        if hasmq:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   373
            saved, repo.mq.checkapplied = repo.mq.checkapplied, False
39519
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   374
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   375
        targetphase = phases.internal
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   376
        if not phases.supportinternal(repo):
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   377
            targetphase = phases.secret
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   378
        overrides = {('phases', 'new-commit'): targetphase}
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   379
        try:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   380
            editor_ = False
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   381
            if editor:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   382
                editor_ = cmdutil.getcommiteditor(editform='shelve.shelve',
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
   383
                                                  **pycompat.strkwargs(opts))
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   384
            with repo.ui.configoverride(overrides):
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   385
                return repo.commit(message, shelveuser, opts.get('date'),
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
   386
                                   match, editor=editor_, extra=extra)
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   387
        finally:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   388
            if hasmq:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   389
                repo.mq.checkapplied = saved
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   390
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   391
    def interactivecommitfunc(ui, repo, *pats, **opts):
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
   392
        opts = pycompat.byteskwargs(opts)
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   393
        match = scmutil.match(repo['.'], pats, {})
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   394
        message = opts['message']
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   395
        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
   396
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   397
    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
   398
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   399
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
   400
    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
   401
    if stat.deleted:
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   402
        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
   403
                    "'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
   404
    else:
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   405
        ui.status(_("nothing changed\n"))
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   406
42012
9b78bbb76111 shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42011
diff changeset
   407
def _shelvecreatedcommit(repo, node, name, match):
39372
da121c9dc0f2 shelve: store shelved node in a new data file
Boris Feld <boris.feld@octobus.net>
parents: 39344
diff changeset
   408
    info = {'node': nodemod.hex(node)}
da121c9dc0f2 shelve: store shelved node in a new data file
Boris Feld <boris.feld@octobus.net>
parents: 39344
diff changeset
   409
    shelvedfile(repo, name, 'shelve').writeinfo(info)
30383
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   410
    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
   411
    shelvedfile(repo, name, 'hg').writebundle(bases, node)
37603
678d760c71ff export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
   412
    with shelvedfile(repo, name, patchextension).opener('wb') as fp:
40628
29e4a77b5305 shelve: use matcher to restrict prefetch to just the modified files
Kyle Lippincott <spectral@google.com>
parents: 40366
diff changeset
   413
        cmdutil.exportfile(repo, [node], fp, opts=mdiff.diffopts(git=True),
29e4a77b5305 shelve: use matcher to restrict prefetch to just the modified files
Kyle Lippincott <spectral@google.com>
parents: 40366
diff changeset
   414
                           match=match)
30383
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
   415
30384
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   416
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
   417
    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
   418
                    unknown=True)
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   419
    if s.unknown:
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   420
        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
   421
        repo[None].add(s.unknown)
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   422
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   423
def _finishshelve(repo, tr):
39744
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
   424
    if phases.supportinternal(repo):
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
   425
        tr.close()
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
   426
    else:
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   427
        _aborttransaction(repo, tr)
30385
b573d7ca31c4 shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30384
diff changeset
   428
39342
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
   429
def createcmd(ui, repo, pats, opts):
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
   430
    """subcommand that creates a new shelve"""
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
   431
    with repo.wlock():
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
   432
        cmdutil.checkunfinished(repo)
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
   433
        return _docreatecmd(ui, repo, pats, opts)
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
   434
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
   435
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
   436
    wctx = repo[None]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   437
    parents = wctx.parents()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   438
    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
   439
    origbranch = wctx.branch()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   440
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
   441
    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
   442
        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
   443
    else:
20411
66359d8b8d7e shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents: 20410
diff changeset
   444
        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
   445
28401
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   446
    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
   447
        opts['message'] = desc
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   448
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   449
    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
   450
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   451
        lock = repo.lock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   452
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 19943
diff changeset
   453
        # 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
   454
        # pull races. ensure we don't print the abort message to stderr.
40854
236af7cfa4c3 shelve: change transaction description from "commit" to "shelve"
Martin von Zweigbergk <martinvonz@google.com>
parents: 40853
diff changeset
   455
        tr = repo.transaction('shelve', report=lambda x: None)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   456
24477
325f03de849d shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents: 23895
diff changeset
   457
        interactive = opts.get('interactive', False)
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   458
        includeunknown = (opts.get('unknown', False) and
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   459
                          not opts.get('addremove', False))
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   460
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
   461
        name = getshelvename(repo, parent, opts)
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   462
        activebookmark = _backupactivebookmark(repo)
39376
5f8282f368b2 shelve: add an "internal" extra
Boris Feld <boris.feld@octobus.net>
parents: 39375
diff changeset
   463
        extra = {'internal': 'shelve'}
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
   464
        if includeunknown:
30384
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
   465
            _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
   466
28572
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   467
        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
   468
            # 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
   469
            # at bundled commit
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   470
            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
   471
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   472
        commitfunc = getcommitfunc(extra, interactive, editor=True)
24478
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
   473
        if not interactive:
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
   474
            node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
   475
        else:
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
   476
            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
   477
                                    False, cmdutil.recordfilter, *pats,
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
   478
                                    **pycompat.strkwargs(opts))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   479
        if not node:
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
   480
            _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
   481
            return 1
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   482
42012
9b78bbb76111 shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42011
diff changeset
   483
        # Create a matcher so that prefetch doesn't attempt to fetch
42013
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
   484
        # the entire repository pointlessly, and as an optimisation
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
   485
        # for movedirstate, if needed.
42012
9b78bbb76111 shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42011
diff changeset
   486
        match = scmutil.matchfiles(repo, repo[node].files())
9b78bbb76111 shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42011
diff changeset
   487
        _shelvecreatedcommit(repo, node, name, match)
19874
5836edcbdc2e shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents: 19856
diff changeset
   488
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   489
        if ui.formatted():
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
   490
            desc = stringutil.ellipsis(desc, ui.termwidth())
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   491
        ui.status(_('shelved as %s\n') % name)
42013
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
   492
        if opts['keep']:
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
   493
            with repo.dirstate.parentchange():
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
   494
                scmutil.movedirstate(repo, parent, match)
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
   495
        else:
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
   496
            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
   497
        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
   498
            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
   499
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   500
        _finishshelve(repo, tr)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   501
    finally:
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   502
        _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
   503
        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
   504
28571
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
   505
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
   506
    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
   507
            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
   508
            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
   509
            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
   510
28572
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   511
def _iswctxonnewbranch(repo):
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
   512
    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
   513
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   514
def cleanupcmd(ui, repo):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   515
    """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
   516
27835
c448d7e00bf9 with: use context manager for wlock in shelve cleanupcmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27834
diff changeset
   517
    with repo.wlock():
28862
39130afcce60 shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents: 28666
diff changeset
   518
        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
   519
            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
   520
            if suffix in shelvefileextensions:
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
   521
                shelvedfile(repo, name).movetobackup()
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   522
            cleanupoldbackups(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   523
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   524
def deletecmd(ui, repo, pats):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   525
    """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
   526
    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
   527
        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
   528
    with repo.wlock():
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   529
        try:
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   530
            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
   531
                for suffix in shelvefileextensions:
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   532
                    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
   533
                    # 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
   534
                    # 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
   535
                    # 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
   536
                    # 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
   537
                    # bundle
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   538
                    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
   539
                        shfile.movetobackup()
27836
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   540
            cleanupoldbackups(repo)
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   541
        except OSError as err:
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   542
            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
   543
                raise
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
   544
            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
   545
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   546
def listshelves(repo):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   547
    """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
   548
    try:
28862
39130afcce60 shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents: 28666
diff changeset
   549
        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
   550
    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
   551
        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
   552
            raise
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   553
        return []
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   554
    info = []
22199
b3e51675f98e cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents: 22184
diff changeset
   555
    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
   556
        pfx, sfx = name.rsplit('.', 1)
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   557
        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
   558
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   559
        st = shelvedfile(repo, name).stat()
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
   560
        info.append((st[stat.ST_MTIME], shelvedfile(repo, pfx).filename()))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   561
    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
   562
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   563
def listcmd(ui, repo, pats, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   564
    """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
   565
    pats = set(pats)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   566
    width = 80
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   567
    if not ui.plain():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   568
        width = ui.termwidth()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   569
    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
   570
    ui.pager('shelve')
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   571
    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
   572
        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
   573
        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
   574
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   575
        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
   576
        namelabel = 'shelve.name'
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   577
        if ui.quiet:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   578
            ui.write('\n')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   579
            continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   580
        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
   581
        used = 16
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36496
diff changeset
   582
        date = dateutil.makedate(mtime)
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36496
diff changeset
   583
        age = '(%s)' % templatefilters.age(date, abbrev=True)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   584
        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
   585
        ui.write(' ' * (12 - len(age)))
a3b285882724 shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents: 19854
diff changeset
   586
        used += 12
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   587
        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
   588
            while True:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   589
                line = fp.readline()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   590
                if not line:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   591
                    break
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   592
                if not line.startswith('#'):
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   593
                    desc = line.rstrip()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   594
                    if ui.formatted():
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
   595
                        desc = stringutil.ellipsis(desc, width - used)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   596
                    ui.write(desc)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   597
                    break
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   598
            ui.write('\n')
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   599
            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
   600
                continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   601
            difflines = fp.readlines()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   602
            if opts['patch']:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   603
                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
   604
                    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
   605
            if opts['stat']:
30407
e1677cc29da6 patch: remove unused git parameter from patch.diffstat()
Henning Schild <henning@hennsch.de>
parents: 30385
diff changeset
   606
                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
   607
                    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
   608
38715
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
   609
def patchcmds(ui, repo, pats, opts):
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   610
    """subcommand that displays shelves"""
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   611
    if len(pats) == 0:
38715
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
   612
        shelves = listshelves(repo)
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
   613
        if not shelves:
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
   614
            raise error.Abort(_("there are no shelves to show"))
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
   615
        mtime, name = shelves[0]
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
   616
        sname = util.split(name)[1]
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
   617
        pats = [sname]
25104
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   618
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   619
    for shelfname in pats:
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
   620
        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
   621
            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
   622
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
   623
    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
   624
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   625
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
   626
    """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
   627
    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
   628
        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
   629
                           'state'))
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   630
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   631
def _loadshelvedstate(ui, repo, opts):
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   632
    try:
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   633
        state = shelvedstate.load(repo)
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   634
        if opts.get('keep') is None:
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   635
            opts['keep'] = state.keep
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   636
    except IOError as err:
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   637
        if err.errno != errno.ENOENT:
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   638
            raise
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   639
        cmdutil.wrongtooltocontinue(repo, _('unshelve'))
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   640
    except error.CorruptedState as err:
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   641
        ui.debug(pycompat.bytestr(err) + '\n')
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   642
        if opts.get('continue'):
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   643
            msg = _('corrupted shelved state file')
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   644
            hint = _('please run hg unshelve --abort to abort unshelve '
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   645
                     'operation')
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   646
            raise error.Abort(msg, hint=hint)
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   647
        elif opts.get('abort'):
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   648
            shelvedstate.clear(repo)
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   649
            raise error.Abort(_('could not read shelved state file, your '
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   650
                                'working copy may be in an unexpected state\n'
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   651
                                'please update to some commit\n'))
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   652
    return state
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   653
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   654
def unshelveabort(ui, repo, state):
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
   655
    """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
   656
    with repo.lock():
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   657
        try:
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   658
            checkparents(repo, state)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   659
40366
b14fdf1fb615 update: clarify update() call sites by specifying argument names
Martin von Zweigbergk <martinvonz@google.com>
parents: 40293
diff changeset
   660
            merge.update(repo, state.pendingctx, branchmerge=False, force=True)
38462
61e4cf1be5b2 shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents: 37967
diff changeset
   661
            if (state.activebookmark
61e4cf1be5b2 shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents: 37967
diff changeset
   662
                    and state.activebookmark in repo._bookmarks):
61e4cf1be5b2 shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents: 37967
diff changeset
   663
                bookmarks.activate(repo, state.activebookmark)
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   664
            mergefiles(ui, repo, state.wctx, state.pendingctx)
39744
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
   665
            if not phases.supportinternal(repo):
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
   666
                repair.strip(ui, repo, state.nodestoremove, backup=False,
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
   667
                             topic='shelve')
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   668
        finally:
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   669
            shelvedstate.clear(repo)
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
   670
            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
   671
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   672
def hgabortunshelve(ui, repo):
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   673
    """logic to  abort unshelve using 'hg abort"""
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   674
    with repo.wlock():
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   675
        state = _loadshelvedstate(ui, repo, {'abort' : True})
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   676
        return unshelveabort(ui, repo, state)
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   677
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   678
def mergefiles(ui, repo, wctx, shelvectx):
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   679
    """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
   680
    dirstate."""
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   681
    with ui.configoverride({('ui', 'quiet'): True}):
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   682
        hg.update(repo, wctx.node())
22184
fb8065de47b0 unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents: 22057
diff changeset
   683
        ui.pushbuffer(True)
42038
e08559769bc6 shelve: let cmdutil.revert() take care of backing up untracked files
Martin von Zweigbergk <martinvonz@google.com>
parents: 42037
diff changeset
   684
        cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents())
22184
fb8065de47b0 unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents: 22057
diff changeset
   685
        ui.popbuffer()
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   686
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   687
def restorebranch(ui, repo, branchtorestore):
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   688
    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
   689
        repo.dirstate.setbranch(branchtorestore)
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   690
        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
   691
                  % branchtorestore)
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
   692
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   693
def unshelvecleanup(ui, repo, name, opts):
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
   694
    """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
   695
    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
   696
        for filetype in shelvefileextensions:
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   697
            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
   698
            if shfile.exists():
c5126aab9c37 shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents: 29841
diff changeset
   699
                shfile.movetobackup()
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
   700
        cleanupoldbackups(repo)
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   701
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
   702
    """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
   703
    # 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
   704
    # parent, second is the temporary "fake" commit we're unshelving.
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   705
    interactive = state.interactive
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   706
    basename = state.name
27838
60b850b7e4ef with: use context manager for lock in continue
Bryan O'Sullivan <bryano@fb.com>
parents: 27837
diff changeset
   707
    with repo.lock():
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   708
        checkparents(repo, state)
26992
b3b5ed560283 shelve: switch to mergestate.read()
Siddharth Agarwal <sid0@fb.com>
parents: 26942
diff changeset
   709
        ms = merge.mergestate.read(repo)
33313
ea03b3223611 shelve: don't reimplement mergestate.unresolved()
Martin von Zweigbergk <martinvonz@google.com>
parents: 33043
diff changeset
   710
        if list(ms.unresolved()):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   711
            raise error.Abort(
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   712
                _("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
   713
                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
   714
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   715
        shelvectx = repo[state.parents[1]]
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   716
        pendingctx = state.pendingctx
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   717
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   718
        with repo.dirstate.parentchange():
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   719
            repo.setparents(state.pendingctx.node(), nodemod.nullid)
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   720
            repo.dirstate.write(repo.currenttransaction())
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   721
39519
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   722
        targetphase = phases.internal
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   723
        if not phases.supportinternal(repo):
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   724
            targetphase = phases.secret
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
   725
        overrides = {('phases', 'new-commit'): targetphase}
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   726
        with repo.ui.configoverride(overrides, 'unshelve'):
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   727
            with repo.dirstate.parentchange():
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   728
                repo.setparents(state.parents[0], nodemod.nullid)
42656
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   729
                newnode, ispartialunshelve = _createunshelvectx(ui,
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   730
                        repo, shelvectx, basename, interactive, opts)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   731
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   732
        if newnode is None:
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   733
            # If it ended up being a no-op commit, then the normal
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   734
            # merge state clean-up path doesn't happen, so do it
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   735
            # here. Fix issue5494
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   736
            merge.mergestate.clean(repo)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   737
            shelvectx = state.pendingctx
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   738
            msg = _('note: unshelved changes already existed '
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   739
                    'in the working copy\n')
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   740
            ui.status(msg)
22842
d43d116a118c shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21852
diff changeset
   741
        else:
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   742
            # only strip the shelvectx if we produced one
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   743
            state.nodestoremove.append(newnode)
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   744
            shelvectx = repo[newnode]
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
   745
38508
39db5a01cd53 cleanup: pass in overwrite flag to hg.updaterepo() as named argument
Yuya Nishihara <yuya@tcha.org>
parents: 38463
diff changeset
   746
        hg.updaterepo(repo, pendingctx.node(), overwrite=False)
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
   747
        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
   748
        restorebranch(ui, repo, state.branchtorestore)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   749
42702
4814d993fe21 unshelve: handle stripping changesets on interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42668
diff changeset
   750
        if not phases.supportinternal(repo):
4814d993fe21 unshelve: handle stripping changesets on interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42668
diff changeset
   751
            repair.strip(ui, repo, state.nodestoremove, backup=False,
4814d993fe21 unshelve: handle stripping changesets on interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42668
diff changeset
   752
                         topic='shelve')
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   753
        if not ispartialunshelve:
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   754
            shelvedstate.clear(repo)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   755
            unshelvecleanup(ui, repo, state.name, opts)
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   756
        _restoreactivebookmark(repo, state.activebookmark)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   757
        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
   758
42614
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
   759
def hgcontinueunshelve(ui, repo):
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
   760
    """logic to resume unshelve using 'hg continue'"""
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
   761
    with repo.wlock():
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
   762
        state = _loadshelvedstate(ui, repo, {'continue' : True})
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
   763
        return unshelvecontinue(ui, repo, state, {'keep' : state.keep})
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
   764
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   765
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
   766
    """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
   767
    # 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
   768
    # 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
   769
    s = repo.status()
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   770
    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
   771
    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
   772
        return tmpwctx, addedbefore
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   773
    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
   774
                "(restore with 'hg unshelve --abort')\n"))
39376
5f8282f368b2 shelve: add an "internal" extra
Boris Feld <boris.feld@octobus.net>
parents: 39375
diff changeset
   775
    extra = {'internal': 'shelve'}
5f8282f368b2 shelve: add an "internal" extra
Boris Feld <boris.feld@octobus.net>
parents: 39375
diff changeset
   776
    commitfunc = getcommitfunc(extra=extra, interactive=False,
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   777
                               editor=False)
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   778
    tempopts = {}
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   779
    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
   780
    tempopts['date'] = opts.get('date')
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   781
    with ui.configoverride({('ui', 'quiet'): True}):
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
   782
        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
   783
    tmpwctx = repo[node]
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   784
    return tmpwctx, addedbefore
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
   785
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   786
def _unshelverestorecommit(ui, repo, tr, basename):
30454
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
   787
    """Recreate commit in the repository during the unshelve"""
39373
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
   788
    repo = repo.unfiltered()
39387
da84cca65036 shelve: fix crash on unshelve without .shelve metadata file
Yuya Nishihara <yuya@tcha.org>
parents: 39376
diff changeset
   789
    node = None
39374
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
   790
    if shelvedfile(repo, basename, 'shelve').exists():
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
   791
        node = shelvedfile(repo, basename, 'shelve').readinfo()['node']
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
   792
    if node is None or node not in repo:
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
   793
        with ui.configoverride({('ui', 'quiet'): True}):
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   794
            shelvectx = shelvedfile(repo, basename, 'hg').applybundle(tr)
39375
38373da1af02 shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents: 39374
diff changeset
   795
        # We might not strip the unbundled changeset, so we should keep track of
38373da1af02 shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents: 39374
diff changeset
   796
        # the unshelve node in case we need to reuse it (eg: unshelve --keep)
38373da1af02 shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents: 39374
diff changeset
   797
        if node is None:
39387
da84cca65036 shelve: fix crash on unshelve without .shelve metadata file
Yuya Nishihara <yuya@tcha.org>
parents: 39376
diff changeset
   798
            info = {'node': nodemod.hex(shelvectx.node())}
39375
38373da1af02 shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents: 39374
diff changeset
   799
            shelvedfile(repo, basename, 'shelve').writeinfo(info)
39374
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
   800
    else:
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
   801
        shelvectx = repo[node]
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
   802
30454
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
   803
    return repo, shelvectx
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
   804
42656
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   805
def _createunshelvectx(ui, repo, shelvectx, basename, interactive, opts):
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   806
    """Handles the creation of unshelve commit and updates the shelve if it
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   807
    was partially unshelved.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   808
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   809
    If interactive is:
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   810
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   811
      * False: Commits all the changes in the working directory.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   812
      * True: Prompts the user to select changes to unshelve and commit them.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   813
              Update the shelve with remaining changes.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   814
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   815
    Returns the node of the new commit formed and a bool indicating whether
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   816
    the shelve was partially unshelved.Creates a commit ctx to unshelve
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   817
    interactively or non-interactively.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   818
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   819
    The user might want to unshelve certain changes only from the stored
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   820
    shelve in interactive. So, we would create two commits. One with requested
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   821
    changes to unshelve at that time and the latter is shelved for future.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   822
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   823
    Here, we return both the newnode which is created interactively and a
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   824
    bool to know whether the shelve is partly done or completely done.
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   825
    """
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   826
    opts['message'] = shelvectx.description()
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   827
    opts['interactive-unshelve'] = True
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   828
    pats = []
42656
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   829
    if not interactive:
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   830
        newnode = repo.commit(text=shelvectx.description(),
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   831
                              extra=shelvectx.extra(),
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   832
                              user=shelvectx.user(),
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   833
                              date=shelvectx.date())
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   834
        return newnode, False
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   835
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   836
    commitfunc = getcommitfunc(shelvectx.extra(), interactive=True,
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   837
                               editor=True)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   838
    newnode = cmdutil.dorecord(ui, repo, commitfunc, None, False,
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   839
                               cmdutil.recordfilter, *pats,
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   840
                               **pycompat.strkwargs(opts))
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   841
    snode = repo.commit(text=shelvectx.description(),
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   842
                        extra=shelvectx.extra(),
42657
aaad4fe55ad1 unshelve: changes how date is set on interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42656
diff changeset
   843
                        user=shelvectx.user())
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   844
    if snode:
42658
d5cdce3d9164 unshelve: create a matcher only if required on creating unshelve ctx
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42657
diff changeset
   845
        m = scmutil.matchfiles(repo, repo[snode].files())
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   846
        _shelvecreatedcommit(repo, snode, basename, m)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   847
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   848
    return newnode, bool(snode)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   849
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   850
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
   851
                          tmpwctx, shelvectx, branchtorestore,
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   852
                          activebookmark):
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   853
    """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
   854
    # 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
   855
    # we'll be merging with, rebase it to be on top.
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   856
    interactive = opts.get('interactive')
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   857
    if tmpwctx.node() == shelvectx.p1().node() and not interactive:
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   858
        # We won't skip on interactive mode because, the user might want to
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   859
        # unshelve certain changes only.
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   860
        return shelvectx, False
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   861
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   862
    overrides = {
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   863
        ('ui', 'forcemerge'): opts.get('tool', ''),
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   864
        ('phases', 'new-commit'): phases.secret,
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   865
    }
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   866
    with repo.ui.configoverride(overrides, 'unshelve'):
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   867
        ui.status(_('rebasing shelved changes\n'))
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   868
        stats = merge.graft(repo, shelvectx, shelvectx.p1(),
38619
9b077e5fa8ba shelve: use more accurate description in conflict marker
Boris Feld <boris.feld@octobus.net>
parents: 38618
diff changeset
   869
                           labels=['shelve', 'working-copy'],
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   870
                           keepconflictparent=True)
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   871
        if stats.unresolvedcount:
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   872
            tr.close()
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   873
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   874
            nodestoremove = [repo.changelog.node(rev)
38783
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38715
diff changeset
   875
                             for rev in pycompat.xrange(oldtiprev, len(repo))]
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   876
            shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove,
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   877
                              branchtorestore, opts.get('keep'), activebookmark,
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   878
                              interactive)
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   879
            raise error.InterventionRequired(
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   880
                _("unresolved conflicts (see 'hg resolve', then "
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   881
                  "'hg unshelve --continue')"))
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   882
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   883
        with repo.dirstate.parentchange():
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   884
            repo.setparents(tmpwctx.node(), nodemod.nullid)
42656
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   885
            newnode, ispartialunshelve = _createunshelvectx(ui, repo,
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
   886
                                       shelvectx, basename, interactive, opts)
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   887
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   888
        if newnode is None:
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   889
            # If it ended up being a no-op commit, then the normal
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   890
            # merge state clean-up path doesn't happen, so do it
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   891
            # here. Fix issue5494
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   892
            merge.mergestate.clean(repo)
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   893
            shelvectx = tmpwctx
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   894
            msg = _('note: unshelved changes already existed '
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   895
                    'in the working copy\n')
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   896
            ui.status(msg)
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   897
        else:
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   898
            shelvectx = repo[newnode]
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
   899
            hg.updaterepo(repo, tmpwctx.node(), False)
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   900
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   901
    return shelvectx, ispartialunshelve
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
   902
30456
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   903
def _forgetunknownfiles(repo, shelvectx, addedbefore):
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   904
    # 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
   905
    # 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
   906
    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
   907
    if not shelveunknown:
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   908
        return
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   909
    shelveunknown = frozenset(shelveunknown.split('\0'))
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   910
    addedafter = frozenset(repo.status().added)
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   911
    toforget = (addedafter & shelveunknown) - addedbefore
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   912
    repo[None].forget(toforget)
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
   913
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   914
def _finishunshelve(repo, oldtiprev, tr, activebookmark):
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   915
    _restoreactivebookmark(repo, activebookmark)
30457
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   916
    # 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
   917
    # 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
   918
    # 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
   919
    # 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
   920
    repo.unfiltered().changelog.strip(oldtiprev, tr)
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   921
    _aborttransaction(repo, tr)
30457
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
   922
30846
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   923
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
   924
    """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
   925
    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
   926
    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
   927
    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
   928
    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
   929
    if intersection:
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
   930
        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
   931
        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
   932
        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
   933
42560
70f1a84d0794 unshelve: rename _dounshelve() to dounshelve()
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42541
diff changeset
   934
def dounshelve(ui, repo, *shelved, **opts):
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
   935
    opts = pycompat.byteskwargs(opts)
28401
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   936
    abortf = opts.get('abort')
2565fe39a76c shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents: 28378
diff changeset
   937
    continuef = opts.get('continue')
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   938
    interactive = opts.get('interactive')
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   939
    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
   940
        cmdutil.checkunfinished(repo)
31021
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   941
    shelved = list(shelved)
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   942
    if opts.get("name"):
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
   943
        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
   944
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   945
    if abortf or continuef:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   946
        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
   947
            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
   948
        if shelved:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
   949
            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
   950
                               'naming a shelved change'))
27021
f2554154509f unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents: 27020
diff changeset
   951
        if abortf and opts.get('tool', False):
f2554154509f unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents: 27020
diff changeset
   952
            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
   953
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   954
        state = _loadshelvedstate(ui, repo, opts)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   955
        if abortf:
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
   956
            return unshelveabort(ui, repo, state)
42668
52a383451739 unshelve: add abort on using continue and interactive together
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42662
diff changeset
   957
        elif continuef and interactive:
52a383451739 unshelve: add abort on using continue and interactive together
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42662
diff changeset
   958
            raise error.Abort(_('cannot use both continue and interactive'))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   959
        elif continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   960
            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
   961
    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
   962
        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
   963
    elif not shelved:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   964
        shelved = listshelves(repo)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   965
        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
   966
            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
   967
        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
   968
        ui.status(_("unshelving change '%s'\n") % basename)
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
   969
    else:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   970
        basename = shelved[0]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   971
30554
1775975dd439 shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents: 30542
diff changeset
   972
    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
   973
        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
   974
39373
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
   975
    repo = repo.unfiltered()
27287
c9ceea3f2d8e shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27198
diff changeset
   976
    lock = tr = None
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   977
    try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   978
        lock = repo.lock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
   979
        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
   980
        oldtiprev = len(repo)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   981
20958
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   982
        pctx = repo['.']
df33c9014430 shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents: 20942
diff changeset
   983
        tmpwctx = pctx
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   984
        # 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
   985
        # ...-> pctx -> tmpwctx -> shelvectx
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   986
        # 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
   987
        # 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
   988
        # to the original pctx.
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
   989
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
   990
        activebookmark = _backupactivebookmark(repo)
37967
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
   991
        tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
   992
                                                         tmpwctx)
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
   993
        repo, shelvectx = _unshelverestorecommit(ui, repo, tr, basename)
37967
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
   994
        _checkunshelveuntrackedproblems(ui, repo, shelvectx)
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
   995
        branchtorestore = ''
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
   996
        if shelvectx.branch() != shelvectx.p1().branch():
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
   997
            branchtorestore = shelvectx.branch()
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
   998
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
   999
        shelvectx, ispartialunshelve = _rebaserestoredcommit(ui, repo, opts,
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
  1000
            tr, oldtiprev, basename, pctx, tmpwctx, shelvectx,
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
  1001
            branchtorestore, activebookmark)
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
  1002
        overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
  1003
        with ui.configoverride(overrides, 'unshelve'):
37967
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
  1004
            mergefiles(ui, repo, pctx, shelvectx)
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
  1005
        restorebranch(ui, repo, branchtorestore)
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
  1006
        if not ispartialunshelve:
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
  1007
            _forgetunknownfiles(repo, shelvectx, addedbefore)
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
  1008
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
  1009
            shelvedstate.clear(repo)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
  1010
            _finishunshelve(repo, oldtiprev, tr, activebookmark)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
  1011
            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
  1012
    finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1013
        if tr:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
  1014
            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
  1015
        lockmod.release(lock)