##// END OF EJS Templates
contrib: enforce wrapping too-long lines with () instead of \...
contrib: enforce wrapping too-long lines with () instead of \ This is the style I prefer, and an anecdotal exploration of styles recommended in style guides etc. Further, to quote pep8: > The preferred way of wrapping long lines is by using Python's implied > line continuation inside parentheses, brackets and braces. Long lines > can be broken over multiple lines by wrapping expressions in > parentheses. These should be used in preference to using a backslash > for line continuation. So I think this is a virtuous change. Differential Revision: https://phab.mercurial-scm.org/D5995

File last commit:

r41925:aaad36b8 default
r41927:e2472b12 default
Show More
shelve.py
1148 lines | 43.0 KiB | text/x-python | PythonLexer
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 # shelve.py - save/restore working directory state
#
# Copyright 2013 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""save and restore changes to the working directory
The "hg shelve" command saves changes made to the working directory
and reverts those changes, resetting the working directory to a clean
state.
Later on, the "hg unshelve" command restores the changes saved by "hg
shelve". Changes can be restored even after updating to a different
parent, in which case Mercurial's merge machinery will resolve any
conflicts if necessary.
You can have more than one shelved change outstanding at a time; each
shelved change has a distinct name. For details, see the help for "hg
shelve".
"""
timeless
shelve: use absolute_import
r28378 from __future__ import absolute_import
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Martin von Zweigbergk
util: drop alias for collections.deque...
r25113 import collections
timeless
shelve: use absolute_import
r28378 import errno
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 import itertools
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 import stat
Yuya Nishihara
py3: move up symbol imports to enforce import-checker rules...
r29205
from mercurial.i18n import _
timeless
shelve: use absolute_import
r28378 from mercurial import (
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 bookmarks,
timeless
shelve: use absolute_import
r28378 bundle2,
bundlerepo,
changegroup,
cmdutil,
Durham Goode
changegroup: replace changegroupsubset with makechangegroup...
r34099 discovery,
timeless
shelve: use absolute_import
r28378 error,
exchange,
hg,
lock as lockmod,
mdiff,
merge,
node as nodemod,
patch,
phases,
Pulkit Goyal
py3: handle keyword arguments in hgext/shelve.py...
r35006 pycompat,
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 registrar,
timeless
shelve: use absolute_import
r28378 repair,
scmutil,
templatefilters,
util,
Pierre-Yves David
vfs: use 'vfs' module directly in 'hgext.shelve'...
r31244 vfs as vfsmod,
timeless
shelve: use absolute_import
r28378 )
from . import (
rebase,
)
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 from mercurial.utils import (
dateutil,
stringutil,
)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
cmdtable = {}
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 command = registrar.command(cmdtable)
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 testedwith = 'ships-with-hg-core'
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Boris Feld
configitems: register the 'shelve.maxbackups' config
r34497 configtable = {}
configitem = registrar.configitem(configtable)
configitem('shelve', 'maxbackups',
default=10,
)
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 backupdir = 'shelve-backup'
Oleg Afanasyev
shelve: refactor directory name into constant...
r28862 shelvedir = 'shelved'
Boris Feld
shelve: store shelved node in a new data file...
r39408 shelvefileextensions = ['hg', 'patch', 'shelve']
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 # universal extension is present in all types of shelves
patchextension = 'patch'
Colin Chan
shelve: only keep the latest N shelve backups...
r25713
Kostia Balytskyi
shelve: move commitfunc creation to a separate function...
r30381 # we never need the user, so we use a
# generic user for all shelve operations
shelveuser = 'shelve@localhost'
Colin Chan
shelve: only keep the latest N shelve backups...
r25713
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 class shelvedfile(object):
Pierre-Yves David
shelve: add minimal documentation to all functions...
r19909 """Helper for the file storing a single shelve
Martin von Zweigbergk
shelve: avoid writing file that is never read from...
r22581 Handles common functions on shelve files (.hg/.patch) using
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 the vfs layer"""
def __init__(self, repo, name, filetype=None):
self.repo = repo
self.name = name
Pierre-Yves David
shelve: directly use repo.vfs.join...
r31335 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
Eric Sumner
changegroup.writebundle: provide ui...
r23895 self.ui = self.repo.ui
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if filetype:
self.fname = name + '.' + filetype
else:
self.fname = name
def exists(self):
return self.vfs.exists(self.fname)
def filename(self):
return self.vfs.join(self.fname)
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 def backupfilename(self):
def gennames(base):
yield base
base, ext = base.rsplit('.', 1)
for i in itertools.count(1):
yield '%s-%d.%s' % (base, i, ext)
name = self.backupvfs.join(self.fname)
for n in gennames(name):
if not self.backupvfs.exists(n):
return n
def movetobackup(self):
if not self.backupvfs.isdir():
self.backupvfs.makedir()
util.rename(self.filename(), self.backupfilename())
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
def stat(self):
return self.vfs.stat(self.fname)
def opener(self, mode='rb'):
try:
return self.vfs(self.fname, mode)
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except IOError as err:
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if err.errno != errno.ENOENT:
raise
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("shelved change '%s' not found") % self.name)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 def applybundle(self, tr):
FUJIWARA Katsunori
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs...
r20982 fp = self.opener()
try:
Boris Feld
shelve: use the internal phase when possible...
r39555 targetphase = phases.internal
if not phases.supportinternal(self.repo):
targetphase = phases.secret
Pierre-Yves David
bundle2: add a ui argument to readbundle...
r21064 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
Boris Feld
shelve: find shelvedctx from bundle even if they are already in the repo...
r39925 pretip = self.repo['tip']
bundle2.applybundle(self.repo, gen, tr,
Martin von Zweigbergk
bundle: make applybundle() delegate v1 bundles to applybundle1()
r33043 source='unshelve',
url='bundle:' + self.vfs.join(self.fname),
Boris Feld
shelve: use the internal phase when possible...
r39555 targetphase=targetphase)
Boris Feld
shelve: find shelvedctx from bundle even if they are already in the repo...
r39925 shelvectx = self.repo['tip']
if pretip == shelvectx:
shelverev = tr.changes['revduplicates'][-1]
shelvectx = self.repo[shelverev]
return shelvectx
FUJIWARA Katsunori
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs...
r20982 finally:
fp.close()
Matt Mackall
shelve: add a bundlerepo method
r22898 def bundlerepo(self):
Gregory Szorc
shelve: use bundlerepo.instance() to construct a repo object...
r39637 path = self.vfs.join(self.fname)
return bundlerepo.instance(self.repo.baseui,
'bundle://%s+%s' % (self.repo.root, path))
Pierre-Yves David
shelve: move changegroup generation inside writebundle...
r26506 def writebundle(self, bases, node):
Martin von Zweigbergk
shelve: use cg3 for treemanifests...
r27931 cgversion = changegroup.safeversion(self.repo)
if cgversion == '01':
btype = 'HG10BZ'
compression = None
else:
Pierre-Yves David
shelve: bundle using bundle2 if repository is general delta (issue4862)...
r26507 btype = 'HG20'
compression = 'BZ'
Boris Feld
shelve: handle shelved node on unfiltered repository...
r39409 repo = self.repo.unfiltered()
outgoing = discovery.outgoing(repo, missingroots=bases,
Durham Goode
changegroup: replace changegroupsubset with makechangegroup...
r34099 missingheads=[node])
Boris Feld
shelve: handle shelved node on unfiltered repository...
r39409 cg = changegroup.makechangegroup(repo, outgoing, cgversion, 'shelve')
Durham Goode
changegroup: replace changegroupsubset with makechangegroup...
r34099
Martin von Zweigbergk
bundle: move writebundle() from changegroup.py to bundle2.py (API)...
r28666 bundle2.writebundle(self.ui, cg, self.fname, btype, self.vfs,
Pierre-Yves David
shelve: bundle using bundle2 if repository is general delta (issue4862)...
r26507 compression=compression)
FUJIWARA Katsunori
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
r20983
Boris Feld
shelve: rename method for data write/read...
r39379 def writeinfo(self, info):
Kostia Balytskyi
shelve: add an ability to write key-val data to a new type of shelve files...
r31554 scmutil.simplekeyvaluefile(self.vfs, self.fname).write(info)
Boris Feld
shelve: rename method for data write/read...
r39379 def readinfo(self):
Kostia Balytskyi
shelve: add an ability to write key-val data to a new type of shelve files...
r31554 return scmutil.simplekeyvaluefile(self.vfs, self.fname).read()
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 class shelvedstate(object):
Augie Fackler
shelve: some docstring cleanups
r19911 """Handle persistence during unshelving operations.
Pierre-Yves David
shelve: add minimal documentation to all functions...
r19909
Handles saving and restoring a shelved state. Ensures that different
Augie Fackler
shelve: some docstring cleanups
r19911 versions of a shelved state are possible and handles them appropriately.
"""
Kostia Balytskyi
shelve: make shelvestate use simplekeyvaluefile...
r32285 _version = 2
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 _filename = 'shelvedstate'
Kostia Balytskyi
shelve: make --keep option survive user intervention (issue5431)...
r30522 _keep = 'keep'
_nokeep = 'nokeep'
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 # colon is essential to differentiate from a real bookmark name
_noactivebook = ':no-active-bookmark'
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
@classmethod
Kostia Balytskyi
shelve: make shelvestate use simplekeyvaluefile...
r32285 def _verifyandtransform(cls, d):
"""Some basic shelvestate syntactic verification and transformation"""
Pierre-Yves David
shelve: drop pickle usage...
r19904 try:
Kostia Balytskyi
shelve: refactor shelvestate loading...
r32284 d['originalwctx'] = nodemod.bin(d['originalwctx'])
d['pendingctx'] = nodemod.bin(d['pendingctx'])
d['parents'] = [nodemod.bin(h)
for h in d['parents'].split(' ')]
d['nodestoremove'] = [nodemod.bin(h)
for h in d['nodestoremove'].split(' ')]
except (ValueError, TypeError, KeyError) as err:
Pulkit Goyal
py3: replace str() with it's bytes equivalent in hgext/shelve.py...
r36514 raise error.CorruptedState(pycompat.bytestr(err))
Kostia Balytskyi
shelve: refactor shelvestate loading...
r32284
Kostia Balytskyi
shelve: make shelvestate use simplekeyvaluefile...
r32285 @classmethod
def _getversion(cls, repo):
"""Read version information from shelvestate file"""
fp = repo.vfs(cls._filename)
try:
version = int(fp.readline().strip())
except ValueError as err:
Pulkit Goyal
py3: replace str() with it's bytes equivalent in hgext/shelve.py...
r36514 raise error.CorruptedState(pycompat.bytestr(err))
Kostia Balytskyi
shelve: make shelvestate use simplekeyvaluefile...
r32285 finally:
fp.close()
return version
@classmethod
def _readold(cls, repo):
"""Read the old position-based version of a shelvestate file"""
# Order is important, because old shelvestate file uses it
# to detemine values of fields (i.g. name is on the second line,
# originalwctx is on the third and so forth). Please do not change.
keys = ['version', 'name', 'originalwctx', 'pendingctx', 'parents',
'nodestoremove', 'branchtorestore', 'keep', 'activebook']
# this is executed only seldomly, so it is not a big deal
# that we open this file twice
fp = repo.vfs(cls._filename)
d = {}
try:
for key in keys:
d[key] = fp.readline().strip()
finally:
fp.close()
return d
@classmethod
def load(cls, repo):
version = cls._getversion(repo)
if version < cls._version:
d = cls._readold(repo)
elif version == cls._version:
Augie Fackler
cleanup: use () to wrap long lines instead of \...
r41925 d = scmutil.simplekeyvaluefile(
repo.vfs, cls._filename).read(firstlinenonkeyval=True)
Kostia Balytskyi
shelve: make shelvestate use simplekeyvaluefile...
r32285 else:
raise error.Abort(_('this version of shelve is incompatible '
'with the version used in this repo'))
cls._verifyandtransform(d)
Kostia Balytskyi
shelve: make unshelve be able to abort in any case
r29536 try:
obj = cls()
Kostia Balytskyi
shelve: refactor shelvestate loading...
r32284 obj.name = d['name']
obj.wctx = repo[d['originalwctx']]
obj.pendingctx = repo[d['pendingctx']]
obj.parents = d['parents']
obj.nodestoremove = d['nodestoremove']
obj.branchtorestore = d.get('branchtorestore', '')
obj.keep = d.get('keep') == cls._keep
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 obj.activebookmark = ''
Kostia Balytskyi
shelve: refactor shelvestate loading...
r32284 if d.get('activebook', '') != cls._noactivebook:
obj.activebookmark = d.get('activebook', '')
except (error.RepoLookupError, KeyError) as err:
Pulkit Goyal
py3: replace str() with it's bytes equivalent in hgext/shelve.py...
r36514 raise error.CorruptedState(pycompat.bytestr(err))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
return obj
@classmethod
Kostia Balytskyi
shelve: rename nodestoprune to nodestoremove...
r31888 def save(cls, repo, name, originalwctx, pendingctx, nodestoremove,
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 branchtorestore, keep=False, activebook=''):
Kostia Balytskyi
shelve: make shelvestate use simplekeyvaluefile...
r32285 info = {
"name": name,
"originalwctx": nodemod.hex(originalwctx.node()),
"pendingctx": nodemod.hex(pendingctx.node()),
"parents": ' '.join([nodemod.hex(p)
for p in repo.dirstate.parents()]),
"nodestoremove": ' '.join([nodemod.hex(n)
for n in nodestoremove]),
"branchtorestore": branchtorestore,
"keep": cls._keep if keep else cls._nokeep,
"activebook": activebook or cls._noactivebook
}
Augie Fackler
cleanup: use () to wrap long lines instead of \...
r41925 scmutil.simplekeyvaluefile(
repo.vfs, cls._filename).write(info,
firstline=("%d" % cls._version))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Pierre-Yves David
shelve: use the class constant in the clear method...
r19908 @classmethod
def clear(cls, repo):
Mads Kiilerich
vfs: use repo.vfs.unlinkpath
r31311 repo.vfs.unlinkpath(cls._filename, ignoremissing=True)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 def cleanupoldbackups(repo):
Pierre-Yves David
shelve: directly use repo.vfs.join...
r31335 vfs = vfsmod.vfs(repo.vfs.join(backupdir))
Boris Feld
configitems: register the 'shelve.maxbackups' config
r34497 maxbackups = repo.ui.configint('shelve', 'maxbackups')
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 hgfiles = [f for f in vfs.listdir()
if f.endswith('.' + patchextension)]
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 hgfiles = sorted([(vfs.stat(f)[stat.ST_MTIME], f) for f in hgfiles])
Martin von Zweigbergk
cleanup: some Yoda conditions, this patch removes...
r40065 if maxbackups > 0 and maxbackups < len(hgfiles):
FUJIWARA Katsunori
shelve: keep old backups if timestamp can't decide exact order of them...
r25774 bordermtime = hgfiles[-maxbackups][0]
else:
bordermtime = None
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 for mtime, f in hgfiles[:len(hgfiles) - maxbackups]:
FUJIWARA Katsunori
shelve: keep old backups if timestamp can't decide exact order of them...
r25774 if mtime == bordermtime:
# keep it, because timestamp can't decide exact order of backups
continue
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 base = f[:-(1 + len(patchextension))]
Kostia Balytskyi
shelve: move possible shelve file extensions to a single place...
r30378 for ext in shelvefileextensions:
Ryan McElroy
shelve: use tryunlink
r31543 vfs.tryunlink(base + '.' + ext)
Colin Chan
shelve: only keep the latest N shelve backups...
r25713
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 def _backupactivebookmark(repo):
activebookmark = repo._activebookmark
if activebookmark:
bookmarks.deactivate(repo)
return activebookmark
def _restoreactivebookmark(repo, mark):
if mark:
bookmarks.activate(repo, mark)
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 def _aborttransaction(repo, tr):
FUJIWARA Katsunori
shelve: add utility to abort current transaction but keep dirstate...
r26522 '''Abort current transaction for shelve/unshelve, but keep dirstate
'''
Martin von Zweigbergk
narrow: call narrowspec.{save,restore,clear}backup directly...
r38905 dirstatebackupname = 'dirstate.shelve'
repo.dirstate.savebackup(tr, dirstatebackupname)
Mateusz Kwapich
shelve: use backup functions instead of manually copying dirstate...
r29270 tr.abort()
Martin von Zweigbergk
narrow: call narrowspec.{save,restore,clear}backup directly...
r38905 repo.dirstate.restorebackup(None, dirstatebackupname)
FUJIWARA Katsunori
shelve: add utility to abort current transaction but keep dirstate...
r26522
Kostia Balytskyi
shelve: move shelve name generation to a separate function...
r30379 def getshelvename(repo, parent, opts):
"""Decide on the name this shelve is going to have"""
def gennames():
yield label
Jun Wu
shelve: allow unlimited shelved changes per name...
r32968 for i in itertools.count(1):
Kostia Balytskyi
shelve: move shelve name generation to a separate function...
r30379 yield '%s-%02d' % (label, i)
name = opts.get('name')
label = repo._activebookmark or parent.branch() or 'default'
# slashes aren't allowed in filenames, therefore we rename it
label = label.replace('/', '_')
Pulkit Goyal
shelve: choose a legal shelve name when no name is passed (issue5112)...
r30671 label = label.replace('\\', '_')
# filenames must not start with '.' as it should not be hidden
if label.startswith('.'):
label = label.replace('.', '_', 1)
Kostia Balytskyi
shelve: move shelve name generation to a separate function...
r30379
if name:
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 if shelvedfile(repo, name, patchextension).exists():
Kostia Balytskyi
shelve: move shelve name generation to a separate function...
r30379 e = _("a shelved change named '%s' already exists") % name
raise error.Abort(e)
Pulkit Goyal
shelve: choose a legal shelve name when no name is passed (issue5112)...
r30671
# ensure we are not creating a subdirectory or a hidden file
if '/' in name or '\\' in name:
raise error.Abort(_('shelved change names can not contain slashes'))
if name.startswith('.'):
raise error.Abort(_("shelved change names can not start with '.'"))
Kostia Balytskyi
shelve: move shelve name generation to a separate function...
r30379 else:
for n in gennames():
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 if not shelvedfile(repo, n, patchextension).exists():
Kostia Balytskyi
shelve: move shelve name generation to a separate function...
r30379 name = n
break
return name
Kostia Balytskyi
shelve: move mutableancestors to not be a closure...
r30380 def mutableancestors(ctx):
"""return all mutable ancestors for ctx (included)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Kostia Balytskyi
shelve: move mutableancestors to not be a closure...
r30380 Much faster than the revset ancestors(ctx) & draft()"""
Martin von Zweigbergk
cleanup: use set literals...
r32291 seen = {nodemod.nullrev}
Kostia Balytskyi
shelve: move mutableancestors to not be a closure...
r30380 visit = collections.deque()
visit.append(ctx)
while visit:
ctx = visit.popleft()
yield ctx.node()
for parent in ctx.parents():
rev = parent.rev()
if rev not in seen:
seen.add(rev)
if parent.mutable():
visit.append(parent)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Kostia Balytskyi
shelve: move commitfunc creation to a separate function...
r30381 def getcommitfunc(extra, interactive, editor=False):
def commitfunc(ui, repo, message, match, opts):
hasmq = util.safehasattr(repo, 'mq')
if hasmq:
saved, repo.mq.checkapplied = repo.mq.checkapplied, False
Boris Feld
shelve: use the internal phase when possible...
r39555
targetphase = phases.internal
if not phases.supportinternal(repo):
targetphase = phases.secret
overrides = {('phases', 'new-commit'): targetphase}
Kostia Balytskyi
shelve: move commitfunc creation to a separate function...
r30381 try:
editor_ = False
if editor:
editor_ = cmdutil.getcommiteditor(editform='shelve.shelve',
Pulkit Goyal
py3: handle keyword arguments in hgext/shelve.py...
r35006 **pycompat.strkwargs(opts))
Jun Wu
shelve: get rid of ui.backupconfig
r31462 with repo.ui.configoverride(overrides):
return repo.commit(message, shelveuser, opts.get('date'),
match, editor=editor_, extra=extra)
Kostia Balytskyi
shelve: move commitfunc creation to a separate function...
r30381 finally:
if hasmq:
repo.mq.checkapplied = saved
def interactivecommitfunc(ui, repo, *pats, **opts):
Pulkit Goyal
py3: handle keyword arguments in hgext/shelve.py...
r35006 opts = pycompat.byteskwargs(opts)
Kostia Balytskyi
shelve: move commitfunc creation to a separate function...
r30381 match = scmutil.match(repo['.'], pats, {})
message = opts['message']
return commitfunc(ui, repo, message, match, opts)
return interactivecommitfunc if interactive else commitfunc
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Kostia Balytskyi
shelve: move 'nothing changed' messaging to a separate function...
r30382 def _nothingtoshelvemessaging(ui, repo, pats, opts):
stat = repo.status(match=scmutil.match(repo[None], pats, opts))
if stat.deleted:
ui.status(_("nothing changed (%d missing files, see "
"'hg status')\n") % len(stat.deleted))
else:
ui.status(_("nothing changed\n"))
Kostia Balytskyi
shelve: move actual created commit shelving to a separate function...
r30383 def _shelvecreatedcommit(repo, node, name):
Boris Feld
shelve: store shelved node in a new data file...
r39408 info = {'node': nodemod.hex(node)}
shelvedfile(repo, name, 'shelve').writeinfo(info)
Kostia Balytskyi
shelve: move actual created commit shelving to a separate function...
r30383 bases = list(mutableancestors(repo[node]))
shelvedfile(repo, name, 'hg').writebundle(bases, node)
Kyle Lippincott
shelve: use matcher to restrict prefetch to just the modified files...
r40662 # Create a matcher so that prefetch doesn't attempt to fetch the entire
# repository pointlessly.
match = scmutil.matchfiles(repo, repo[node].files())
Yuya Nishihara
export: extract function to write patch to file object (API)...
r37621 with shelvedfile(repo, name, patchextension).opener('wb') as fp:
Kyle Lippincott
shelve: use matcher to restrict prefetch to just the modified files...
r40662 cmdutil.exportfile(repo, [node], fp, opts=mdiff.diffopts(git=True),
match=match)
Kostia Balytskyi
shelve: move actual created commit shelving to a separate function...
r30383
Kostia Balytskyi
shelve: move unknown files handling to a separate function...
r30384 def _includeunknownfiles(repo, pats, opts, extra):
s = repo.status(match=scmutil.match(repo[None], pats, opts),
unknown=True)
if s.unknown:
extra['shelve_unknown'] = '\0'.join(s.unknown)
repo[None].add(s.unknown)
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 def _finishshelve(repo, tr):
Boris Feld
shelve: no longer strip internal commit when using internal phase...
r39780 if phases.supportinternal(repo):
tr.close()
else:
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 _aborttransaction(repo, tr)
Kostia Balytskyi
shelve: move shelve-finishing logic to a separate function...
r30385
Boris Feld
shelve: move createcmd next to _docreatecmd...
r39378 def createcmd(ui, repo, pats, opts):
"""subcommand that creates a new shelve"""
with repo.wlock():
cmdutil.checkunfinished(repo)
return _docreatecmd(ui, repo, pats, opts)
Kostia Balytskyi
shelve: move mutableancestors to not be a closure...
r30380 def _docreatecmd(ui, repo, pats, opts):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 wctx = repo[None]
parents = wctx.parents()
if len(parents) > 1:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('cannot shelve while merging'))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 parent = parents[0]
liscju
shelve: preserve newly created branch on non-bare shelve in wctx (BC)...
r28571 origbranch = wctx.branch()
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
timeless
shelve: use absolute_import
r28378 if parent.node() != nodemod.nullid:
Siddharth Agarwal
shelve: use colon instead of quotes in 'changes to' description...
r27092 desc = "changes to: %s" % parent.description().split('\n', 1)[0]
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 else:
Mads Kiilerich
shelve: add 'changes to' prefix to default shelve message...
r20411 desc = '(changes in empty repository)'
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
liscju
shelve: changes getting opts values by get method...
r28401 if not opts.get('message'):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 opts['message'] = desc
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 lock = tr = activebookmark = None
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 try:
lock = repo.lock()
Mads Kiilerich
spelling: random spell checker fixes
r19951 # use an uncommitted transaction to generate the bundle to avoid
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 # pull races. ensure we don't print the abort message to stderr.
Martin von Zweigbergk
shelve: change transaction description from "commit" to "shelve"...
r40889 tr = repo.transaction('shelve', report=lambda x: None)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Laurent Charignon
shelve: add interactive mode command line option
r24477 interactive = opts.get('interactive', False)
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908 includeunknown = (opts.get('unknown', False) and
not opts.get('addremove', False))
Kostia Balytskyi
shelve: move shelve name generation to a separate function...
r30379 name = getshelvename(repo, parent, opts)
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 activebookmark = _backupactivebookmark(repo)
Boris Feld
shelve: add an "internal" extra...
r39412 extra = {'internal': 'shelve'}
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908 if includeunknown:
Kostia Balytskyi
shelve: move unknown files handling to a separate function...
r30384 _includeunknownfiles(repo, pats, opts, extra)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
liscju
shelve: make non bare shelve not saving branch information in bundle...
r28572 if _iswctxonnewbranch(repo) and not _isbareshelve(pats, opts):
# In non-bare shelve we don't store newly created branch
# at bundled commit
repo.dirstate.setbranch(repo['.'].branch())
Kostia Balytskyi
shelve: move commitfunc creation to a separate function...
r30381 commitfunc = getcommitfunc(extra, interactive, editor=True)
Laurent Charignon
shelve: add interactive mode...
r24478 if not interactive:
node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
else:
Kostia Balytskyi
shelve: move commitfunc creation to a separate function...
r30381 node = cmdutil.dorecord(ui, repo, commitfunc, None,
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 False, cmdutil.recordfilter, *pats,
Pulkit Goyal
py3: handle keyword arguments in hgext/shelve.py...
r35006 **pycompat.strkwargs(opts))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if not node:
Kostia Balytskyi
shelve: move 'nothing changed' messaging to a separate function...
r30382 _nothingtoshelvemessaging(ui, repo, pats, opts)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 return 1
Kostia Balytskyi
shelve: move actual created commit shelving to a separate function...
r30383 _shelvecreatedcommit(repo, node, name)
David Soria Parra
shelve: copy bookmarks and restore them after a commit...
r19874
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if ui.formatted():
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 desc = stringutil.ellipsis(desc, ui.termwidth())
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ui.status(_('shelved as %s\n') % name)
hg.update(repo, parent.node())
liscju
shelve: preserve newly created branch on non-bare shelve in wctx (BC)...
r28571 if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
repo.dirstate.setbranch(origbranch)
FUJIWARA Katsunori
shelve: restore shelved dirstate explicitly after aborting transaction...
r26523
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 _finishshelve(repo, tr)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 finally:
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 _restoreactivebookmark(repo, activebookmark)
FUJIWARA Katsunori
shelve: widen wlock scope of shelve for consistency while processing...
r27197 lockmod.release(tr, lock)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
liscju
shelve: preserve newly created branch on non-bare shelve in wctx (BC)...
r28571 def _isbareshelve(pats, opts):
return (not pats
and not opts.get('interactive', False)
and not opts.get('include', False)
and not opts.get('exclude', False))
liscju
shelve: make non bare shelve not saving branch information in bundle...
r28572 def _iswctxonnewbranch(repo):
return repo[None].branch() != repo['.'].branch()
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 def cleanupcmd(ui, repo):
Augie Fackler
shelve: some docstring cleanups
r19911 """subcommand that deletes all shelves"""
Pierre-Yves David
shelve: add minimal documentation to all functions...
r19909
Bryan O'Sullivan
with: use context manager for wlock in shelve cleanupcmd
r27835 with repo.wlock():
Oleg Afanasyev
shelve: refactor directory name into constant...
r28862 for (name, _type) in repo.vfs.readdir(shelvedir):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 suffix = name.rsplit('.', 1)[-1]
Kostia Balytskyi
shelve: move possible shelve file extensions to a single place...
r30378 if suffix in shelvefileextensions:
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 shelvedfile(repo, name).movetobackup()
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 cleanupoldbackups(repo)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
def deletecmd(ui, repo, pats):
Augie Fackler
shelve: some docstring cleanups
r19911 """subcommand that deletes a specific shelve"""
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if not pats:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('no shelved changes specified!'))
Bryan O'Sullivan
with: use context manager for wlock in shelve deletecmd
r27836 with repo.wlock():
try:
for name in pats:
Kostia Balytskyi
shelve: move possible shelve file extensions to a single place...
r30378 for suffix in shelvefileextensions:
shfile = shelvedfile(repo, name, suffix)
# patch file is necessary, as it should
# be present for any kind of shelve,
# but the .hg file is optional as in future we
# will add obsolete shelve with does not create a
# bundle
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 if shfile.exists() or suffix == patchextension:
Kostia Balytskyi
shelve: move possible shelve file extensions to a single place...
r30378 shfile.movetobackup()
Bryan O'Sullivan
with: use context manager for wlock in shelve deletecmd
r27836 cleanupoldbackups(repo)
except OSError as err:
if err.errno != errno.ENOENT:
raise
raise error.Abort(_("shelved change '%s' not found") % name)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
def listshelves(repo):
Augie Fackler
shelve: some docstring cleanups
r19911 """return all shelves in repo as list of (time, filename)"""
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 try:
Oleg Afanasyev
shelve: refactor directory name into constant...
r28862 names = repo.vfs.readdir(shelvedir)
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except OSError as err:
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if err.errno != errno.ENOENT:
raise
return []
info = []
Mads Kiilerich
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n...
r22199 for (name, _type) in names:
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 pfx, sfx = name.rsplit('.', 1)
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 if not pfx or sfx != patchextension:
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 continue
st = shelvedfile(repo, name).stat()
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 info.append((st[stat.ST_MTIME], shelvedfile(repo, pfx).filename()))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 return sorted(info, reverse=True)
def listcmd(ui, repo, pats, opts):
Augie Fackler
shelve: some docstring cleanups
r19911 """subcommand that displays the list of shelves"""
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 pats = set(pats)
width = 80
if not ui.plain():
width = ui.termwidth()
namelabel = 'shelve.newest'
Pulkit Goyal
pager: add support to --patch, --list and --stat options of hg shelve
r31096 ui.pager('shelve')
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 for mtime, name in listshelves(repo):
sname = util.split(name)[1]
if pats and sname not in pats:
continue
ui.write(sname, label=namelabel)
namelabel = 'shelve.name'
if ui.quiet:
ui.write('\n')
continue
ui.write(' ' * (16 - len(sname)))
used = 16
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 date = dateutil.makedate(mtime)
age = '(%s)' % templatefilters.age(date, abbrev=True)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ui.write(age, label='shelve.age')
David Soria Parra
shelve: new output format for shelve listings...
r19855 ui.write(' ' * (12 - len(age)))
used += 12
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 with open(name + '.' + patchextension, 'rb') as fp:
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 while True:
line = fp.readline()
if not line:
break
if not line.startswith('#'):
desc = line.rstrip()
if ui.formatted():
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 desc = stringutil.ellipsis(desc, width - used)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ui.write(desc)
break
ui.write('\n')
if not (opts['patch'] or opts['stat']):
continue
difflines = fp.readlines()
if opts['patch']:
for chunk, label in patch.difflabel(iter, difflines):
ui.write(chunk, label=label)
if opts['stat']:
Henning Schild
patch: remove unused git parameter from patch.diffstat()...
r30407 for chunk, label in patch.diffstatui(difflines, width=width):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ui.write(chunk, label=label)
Danny Hooper
shelve: pick the most recent shelve if none specified for --patch/--stat...
r38737 def patchcmds(ui, repo, pats, opts):
Pulkit Goyal
shelve: allow multiple shelves with --patch and --stat...
r30823 """subcommand that displays shelves"""
if len(pats) == 0:
Danny Hooper
shelve: pick the most recent shelve if none specified for --patch/--stat...
r38737 shelves = listshelves(repo)
if not shelves:
raise error.Abort(_("there are no shelves to show"))
mtime, name = shelves[0]
sname = util.split(name)[1]
pats = [sname]
Tony Tung
shelve: allow --patch and --stat without --list for a single shelf...
r25104
Pulkit Goyal
shelve: allow multiple shelves with --patch and --stat...
r30823 for shelfname in pats:
if not shelvedfile(repo, shelfname, patchextension).exists():
raise error.Abort(_("cannot find shelf %s") % shelfname)
Tony Tung
shelve: allow --patch and --stat without --list for a single shelf...
r25104
listcmd(ui, repo, pats, opts)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 def checkparents(repo, state):
Pierre-Yves David
shelve: add minimal documentation to all functions...
r19909 """check parent while resuming an unshelve"""
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if state.parents != repo.dirstate.parents():
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('working directory parents do not match unshelve '
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 'state'))
Takumi IINO
shelve: make unshelve work even if it don't run in repository root...
r19943 def pathtofiles(repo, files):
cwd = repo.getcwd()
return [repo.pathto(f, cwd) for f in files]
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 def unshelveabort(ui, repo, state, opts):
Pierre-Yves David
shelve: add minimal documentation to all functions...
r19909 """subcommand that abort an in-progress unshelve"""
Bryan O'Sullivan
with: use context manager in unshelveabort
r27841 with repo.lock():
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 try:
Bryan O'Sullivan
with: use context manager in unshelveabort
r27841 checkparents(repo, state)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Martin von Zweigbergk
update: clarify update() call sites by specifying argument names...
r40402 merge.update(repo, state.pendingctx, branchmerge=False, force=True)
Boris Feld
shelve: directly handle the abort process...
r38480 if (state.activebookmark
and state.activebookmark in repo._bookmarks):
bookmarks.activate(repo, state.activebookmark)
if repo.vfs.exists('unshelverebasestate'):
repo.vfs.rename('unshelverebasestate', 'rebasestate')
rebase.clearstatus(repo)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Bryan O'Sullivan
with: use context manager in unshelveabort
r27841 mergefiles(ui, repo, state.wctx, state.pendingctx)
Boris Feld
shelve: no longer strip internal commit when using internal phase...
r39780 if not phases.supportinternal(repo):
repair.strip(ui, repo, state.nodestoremove, backup=False,
topic='shelve')
Bryan O'Sullivan
with: use context manager in unshelveabort
r27841 finally:
shelvedstate.clear(repo)
ui.warn(_("unshelve of '%s' aborted\n") % state.name)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Durham Goode
unshelve: don't commit unknown files during unshelve (issue4113)...
r20149 def mergefiles(ui, repo, wctx, shelvectx):
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 """updates to wctx and merges the changes from shelvectx into the
Durham Goode
unshelve: don't commit unknown files during unshelve (issue4113)...
r20149 dirstate."""
Kostia Balytskyi
shelve: move ui.quiet manipulations to configoverride
r31757 with ui.configoverride({('ui', 'quiet'): True}):
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 hg.update(repo, wctx.node())
files = []
files.extend(shelvectx.files())
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 files.extend(shelvectx.p1().files())
Durham Goode
unshelve: don't commit unknown files during unshelve (issue4113)...
r20149
# revert will overwrite unknown files, so move them out of the way
Martin von Zweigbergk
shelve: access status fields by name rather than index
r22922 for file in repo.status(unknown=True).unknown:
Durham Goode
unshelve: don't commit unknown files during unshelve (issue4113)...
r20149 if file in files:
Martin von Zweigbergk
shelve: fix broken backup of conflicting untracked file...
r41736 util.rename(repo.wjoin(file),
scmutil.backuppath(ui, repo, file))
Matt Mackall
unshelve: silence internal revert...
r22184 ui.pushbuffer(True)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
*pathtofiles(repo, files),
Pulkit Goyal
py3: add r'' to convert keys to keyword arguments to str...
r35930 **{r'no_backup': True})
Matt Mackall
unshelve: silence internal revert...
r22184 ui.popbuffer()
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
liscju
shelve: adds restoring newly created branch (issue5048) (BC)...
r28573 def restorebranch(ui, repo, branchtorestore):
if branchtorestore and branchtorestore != repo.dirstate.branch():
repo.dirstate.setbranch(branchtorestore)
ui.status(_('marked working directory as branch %s\n')
% branchtorestore)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 def unshelvecleanup(ui, repo, name, opts):
Augie Fackler
shelve: some docstring cleanups
r19911 """remove related files after an unshelve"""
liscju
shelve: changes getting opts values by get method...
r28401 if not opts.get('keep'):
Kostia Balytskyi
shelve: move possible shelve file extensions to a single place...
r30378 for filetype in shelvefileextensions:
shfile = shelvedfile(repo, name, filetype)
if shfile.exists():
shfile.movetobackup()
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 cleanupoldbackups(repo)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
def unshelvecontinue(ui, repo, state, opts):
Pierre-Yves David
shelve: add minimal documentation to all functions...
r19909 """subcommand to continue an in-progress unshelve"""
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 # We're finishing off a merge. First parent is our original
# parent, second is the temporary "fake" commit we're unshelving.
Bryan O'Sullivan
with: use context manager for lock in continue
r27838 with repo.lock():
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 checkparents(repo, state)
Siddharth Agarwal
shelve: switch to mergestate.read()...
r26992 ms = merge.mergestate.read(repo)
Martin von Zweigbergk
shelve: don't reimplement mergestate.unresolved()
r33313 if list(ms.unresolved()):
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 _("unresolved conflicts, can't continue"),
hint=_("see 'hg resolve', then 'hg unshelve --continue'"))
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Boris Feld
shelve: directly handle `--continue`...
r38481 shelvectx = repo[state.parents[1]]
pendingctx = state.pendingctx
Boris Feld
shelve: directly handle the initial parent alignment...
r38637 with repo.dirstate.parentchange():
repo.setparents(state.pendingctx.node(), nodemod.nullid)
repo.dirstate.write(repo.currenttransaction())
Boris Feld
shelve: use the internal phase when possible...
r39555 targetphase = phases.internal
if not phases.supportinternal(repo):
targetphase = phases.secret
overrides = {('phases', 'new-commit'): targetphase}
Boris Feld
shelve: directly handle `--continue`...
r38481 with repo.ui.configoverride(overrides, 'unshelve'):
with repo.dirstate.parentchange():
repo.setparents(state.parents[0], nodemod.nullid)
newnode = repo.commit(text=shelvectx.description(),
extra=shelvectx.extra(),
user=shelvectx.user(),
date=shelvectx.date())
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Boris Feld
shelve: directly handle `--continue`...
r38481 if newnode is None:
# If it ended up being a no-op commit, then the normal
# merge state clean-up path doesn't happen, so do it
# here. Fix issue5494
merge.mergestate.clean(repo)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 shelvectx = state.pendingctx
Boris Feld
shelve: directly handle `--continue`...
r38481 msg = _('note: unshelved changes already existed '
'in the working copy\n')
ui.status(msg)
Jordi Gutiérrez Hermoso
shelve: don't delete "." when rebase is a no-op (issue4398)...
r22842 else:
Boris Feld
shelve: directly handle `--continue`...
r38481 # only strip the shelvectx if we produced one
state.nodestoremove.append(newnode)
shelvectx = repo[newnode]
Yuya Nishihara
cleanup: pass in overwrite flag to hg.updaterepo() as named argument...
r38527 hg.updaterepo(repo, pendingctx.node(), overwrite=False)
Boris Feld
shelve: directly handle `--continue`...
r38481
if repo.vfs.exists('unshelverebasestate'):
repo.vfs.rename('unshelverebasestate', 'rebasestate')
rebase.clearstatus(repo)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Durham Goode
unshelve: don't commit unknown files during unshelve (issue4113)...
r20149 mergefiles(ui, repo, state.wctx, shelvectx)
liscju
shelve: adds restoring newly created branch (issue5048) (BC)...
r28573 restorebranch(ui, repo, state.branchtorestore)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Boris Feld
shelve: no longer strip internal commit when using internal phase...
r39780 if not phases.supportinternal(repo):
repair.strip(ui, repo, state.nodestoremove, backup=False,
topic='shelve')
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 _restoreactivebookmark(repo, state.activebookmark)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 shelvedstate.clear(repo)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 unshelvecleanup(ui, repo, state.name, opts)
ui.status(_("unshelve of '%s' complete\n") % state.name)
Kostia Balytskyi
shelve: move temporary commit creation to a separate function...
r30453 def _commitworkingcopychanges(ui, repo, opts, tmpwctx):
"""Temporarily commit working copy changes before moving unshelve commit"""
# Store pending changes in a commit and remember added in case a shelve
# contains unknown files that are part of the pending change
s = repo.status()
addedbefore = frozenset(s.added)
Kostia Balytskyi
shelve: make unshelve not crash when there are missing files (issue4176)...
r30846 if not (s.modified or s.added or s.removed):
Kostia Balytskyi
shelve: move temporary commit creation to a separate function...
r30453 return tmpwctx, addedbefore
ui.status(_("temporarily committing pending changes "
"(restore with 'hg unshelve --abort')\n"))
Boris Feld
shelve: add an "internal" extra...
r39412 extra = {'internal': 'shelve'}
commitfunc = getcommitfunc(extra=extra, interactive=False,
Kostia Balytskyi
shelve: move temporary commit creation to a separate function...
r30453 editor=False)
tempopts = {}
tempopts['message'] = "pending changes temporary commit"
tempopts['date'] = opts.get('date')
Kostia Balytskyi
shelve: move ui.quiet manipulations to configoverride
r31757 with ui.configoverride({('ui', 'quiet'): True}):
node = cmdutil.commit(ui, repo, commitfunc, [], tempopts)
Kostia Balytskyi
shelve: move temporary commit creation to a separate function...
r30453 tmpwctx = repo[node]
return tmpwctx, addedbefore
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 def _unshelverestorecommit(ui, repo, tr, basename):
Kostia Balytskyi
shelve: move commit restoration logic to a separate function
r30454 """Recreate commit in the repository during the unshelve"""
Boris Feld
shelve: handle shelved node on unfiltered repository...
r39409 repo = repo.unfiltered()
Yuya Nishihara
shelve: fix crash on unshelve without .shelve metadata file...
r39424 node = None
Boris Feld
shelve: look for shelved node in the repository before unbundling...
r39410 if shelvedfile(repo, basename, 'shelve').exists():
node = shelvedfile(repo, basename, 'shelve').readinfo()['node']
if node is None or node not in repo:
with ui.configoverride({('ui', 'quiet'): True}):
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 shelvectx = shelvedfile(repo, basename, 'hg').applybundle(tr)
Boris Feld
shelve: write metadata file on the fly if they are missing...
r39411 # We might not strip the unbundled changeset, so we should keep track of
# the unshelve node in case we need to reuse it (eg: unshelve --keep)
if node is None:
Yuya Nishihara
shelve: fix crash on unshelve without .shelve metadata file...
r39424 info = {'node': nodemod.hex(shelvectx.node())}
Boris Feld
shelve: write metadata file on the fly if they are missing...
r39411 shelvedfile(repo, basename, 'shelve').writeinfo(info)
Boris Feld
shelve: look for shelved node in the repository before unbundling...
r39410 else:
shelvectx = repo[node]
Kostia Balytskyi
shelve: move commit restoration logic to a separate function
r30454 return repo, shelvectx
Kostia Balytskyi
shelve: move rebasing logic to a separate function...
r30455 def _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, basename, pctx,
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 tmpwctx, shelvectx, branchtorestore,
activebookmark):
Kostia Balytskyi
shelve: move rebasing logic to a separate function...
r30455 """Rebase restored commit from its original location to a destination"""
# If the shelve is not immediately on top of the commit
# we'll be merging with, rebase it to be on top.
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 if tmpwctx.node() == shelvectx.p1().node():
Kostia Balytskyi
shelve: move rebasing logic to a separate function...
r30455 return shelvectx
Boris Feld
shelve: directly handle the initial parent alignment...
r38637 overrides = {
('ui', 'forcemerge'): opts.get('tool', ''),
('phases', 'new-commit'): phases.secret,
}
with repo.ui.configoverride(overrides, 'unshelve'):
ui.status(_('rebasing shelved changes\n'))
stats = merge.graft(repo, shelvectx, shelvectx.p1(),
Boris Feld
shelve: use more accurate description in conflict marker...
r38638 labels=['shelve', 'working-copy'],
Boris Feld
shelve: directly handle the initial parent alignment...
r38637 keepconflictparent=True)
if stats.unresolvedcount:
tr.close()
nodestoremove = [repo.changelog.node(rev)
Gregory Szorc
global: use pycompat.xrange()...
r38806 for rev in pycompat.xrange(oldtiprev, len(repo))]
Boris Feld
shelve: directly handle the initial parent alignment...
r38637 shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove,
branchtorestore, opts.get('keep'), activebookmark)
raise error.InterventionRequired(
_("unresolved conflicts (see 'hg resolve', then "
"'hg unshelve --continue')"))
Kostia Balytskyi
shelve: move rebasing logic to a separate function...
r30455
Boris Feld
shelve: directly handle the initial parent alignment...
r38637 with repo.dirstate.parentchange():
repo.setparents(tmpwctx.node(), nodemod.nullid)
newnode = repo.commit(text=shelvectx.description(),
extra=shelvectx.extra(),
user=shelvectx.user(),
date=shelvectx.date())
Kostia Balytskyi
shelve: move rebasing logic to a separate function...
r30455
Boris Feld
shelve: directly handle the initial parent alignment...
r38637 if newnode is None:
# If it ended up being a no-op commit, then the normal
# merge state clean-up path doesn't happen, so do it
# here. Fix issue5494
merge.mergestate.clean(repo)
shelvectx = tmpwctx
msg = _('note: unshelved changes already existed '
'in the working copy\n')
ui.status(msg)
else:
shelvectx = repo[newnode]
hg.updaterepo(repo, tmpwctx.node(), False)
Kostia Balytskyi
shelve: move rebasing logic to a separate function...
r30455
return shelvectx
Kostia Balytskyi
shelve: move file-forgetting logic to a separate function...
r30456 def _forgetunknownfiles(repo, shelvectx, addedbefore):
# Forget any files that were unknown before the shelve, unknown before
# unshelve started, but are now added.
shelveunknown = shelvectx.extra().get('shelve_unknown')
if not shelveunknown:
return
shelveunknown = frozenset(shelveunknown.split('\0'))
addedafter = frozenset(repo.status().added)
toforget = (addedafter & shelveunknown) - addedbefore
repo[None].forget(toforget)
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 def _finishunshelve(repo, oldtiprev, tr, activebookmark):
_restoreactivebookmark(repo, activebookmark)
Kostia Balytskyi
shelve: move unshelve-finishing logic to a separate function...
r30457 # The transaction aborting will strip all the commits for us,
# but it doesn't update the inmemory structures, so addchangegroup
# hooks still fire and try to operate on the missing commits.
# Clean up manually to prevent this.
repo.unfiltered().changelog.strip(oldtiprev, tr)
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 _aborttransaction(repo, tr)
Kostia Balytskyi
shelve: move unshelve-finishing logic to a separate function...
r30457
Kostia Balytskyi
shelve: make unshelve not crash when there are missing files (issue4176)...
r30846 def _checkunshelveuntrackedproblems(ui, repo, shelvectx):
"""Check potential problems which may result from working
copy having untracked changes."""
wcdeleted = set(repo.status().deleted)
shelvetouched = set(shelvectx.files())
intersection = wcdeleted.intersection(shelvetouched)
if intersection:
m = _("shelved change touches missing files")
hint = _("run hg status to see which files are missing")
raise error.Abort(m, hint=hint)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 @command('unshelve',
[('a', 'abort', None,
_('abort an incomplete unshelve operation')),
('c', 'continue', None,
_('continue an incomplete unshelve operation')),
Siddharth Agarwal
unshelve: add -k as short form of --keep...
r27019 ('k', 'keep', None,
Mads Kiilerich
shelve: introduce secret option for using fixed date for temporary commit...
r20960 _('keep shelve after unshelving')),
liscju
shelve: add -n/--name option to unshelve (issue5475)...
r31021 ('n', 'name', '',
_('restore shelved change with given name'), _('NAME')),
Siddharth Agarwal
unshelve: add support for custom merge tools...
r27021 ('t', 'tool', '', _('specify merge tool')),
Mads Kiilerich
shelve: introduce secret option for using fixed date for temporary commit...
r20960 ('', 'date', '',
_('set date for temporary commits (DEPRECATED)'), _('DATE'))],
rdamazio@google.com
help: assigning categories to existing commands...
r40329 _('hg unshelve [[-n] SHELVED]'),
helpcategory=command.CATEGORY_WORKING_DIRECTORY)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 def unshelve(ui, repo, *shelved, **opts):
"""restore a shelved change to the working directory
This command accepts an optional name of a shelved change to
restore. If none is given, the most recent shelved change is used.
If a shelved change is applied successfully, the bundle that
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 contains the shelved changes is moved to a backup location
(.hg/shelve-backup).
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Since you can restore a shelved change on top of an arbitrary
commit, it is possible that unshelving will result in a conflict
between your changes and the commits you are unshelving onto. If
this occurs, you must resolve the conflict, then use
``--continue`` to complete the unshelve operation. (The bundle
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 will not be moved until you successfully complete the unshelve.)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
(Alternatively, you can use ``--abort`` to abandon an unshelve
that causes a conflict. This reverts the unshelved changes, and
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 leaves the bundle in place.)
Colin Chan
shelve: only keep the latest N shelve backups...
r25713
liscju
shelve: adds restoring newly created branch (issue5048) (BC)...
r28573 If bare shelved change(when no files are specified, without interactive,
include and exclude option) was done on newly created branch it would
restore branch information to the working directory.
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 After a successful unshelve, the shelved changes are stored in a
backup directory. Only the N most recent backups are kept. N
Matt Mackall
shelve: make maxbackup doc check-config friendly
r25852 defaults to 10 but can be overridden using the ``shelve.maxbackups``
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 configuration option.
FUJIWARA Katsunori
shelve: keep old backups if timestamp can't decide exact order of them...
r25774
.. container:: verbose
Timestamp in seconds is used to decide order of backups. More
than ``maxbackups`` backups are kept, if same timestamp
prevents from deciding exact order of them, for safety.
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 """
Bryan O'Sullivan
with: use context manager for wlock in unshelve
r27837 with repo.wlock():
FUJIWARA Katsunori
shelve: widen wlock scope of unshelve for consistency while processing...
r27287 return _dounshelve(ui, repo, *shelved, **opts)
def _dounshelve(ui, repo, *shelved, **opts):
Pulkit Goyal
py3: handle keyword arguments in hgext/shelve.py...
r35006 opts = pycompat.byteskwargs(opts)
liscju
shelve: changes getting opts values by get method...
r28401 abortf = opts.get('abort')
continuef = opts.get('continue')
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if not abortf and not continuef:
cmdutil.checkunfinished(repo)
liscju
shelve: add -n/--name option to unshelve (issue5475)...
r31021 shelved = list(shelved)
if opts.get("name"):
shelved.append(opts["name"])
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
if abortf or continuef:
if abortf and continuef:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('cannot use both abort and continue'))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if shelved:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('cannot combine abort/continue with '
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 'naming a shelved change'))
Siddharth Agarwal
unshelve: add support for custom merge tools...
r27021 if abortf and opts.get('tool', False):
ui.warn(_('tool option will be ignored\n'))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
try:
state = shelvedstate.load(repo)
Kostia Balytskyi
shelve: make --keep option survive user intervention (issue5431)...
r30522 if opts.get('keep') is None:
opts['keep'] = state.keep
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except IOError as err:
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if err.errno != errno.ENOENT:
raise
timeless
shelve: suggest the correct tool to continue (not unshelve)...
r28124 cmdutil.wrongtooltocontinue(repo, _('unshelve'))
Kostia Balytskyi
shelve: make unshelve be able to abort in any case
r29536 except error.CorruptedState as err:
Pulkit Goyal
py3: replace str() with it's bytes equivalent in hgext/shelve.py...
r36514 ui.debug(pycompat.bytestr(err) + '\n')
Kostia Balytskyi
shelve: make unshelve be able to abort in any case
r29536 if continuef:
msg = _('corrupted shelved state file')
hint = _('please run hg unshelve --abort to abort unshelve '
'operation')
raise error.Abort(msg, hint=hint)
elif abortf:
msg = _('could not read shelved state file, your working copy '
'may be in an unexpected state\nplease update to some '
'commit\n')
ui.warn(msg)
shelvedstate.clear(repo)
return
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
if abortf:
return unshelveabort(ui, repo, state, opts)
elif continuef:
return unshelvecontinue(ui, repo, state, opts)
elif len(shelved) > 1:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('can only unshelve one change at a time'))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 elif not shelved:
shelved = listshelves(repo)
if not shelved:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('no shelved changes to apply!'))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 basename = util.split(shelved[0][1])[1]
ui.status(_("unshelving change '%s'\n") % basename)
else:
basename = shelved[0]
Kostia Balytskyi
shelve: move patch extension to a string constant...
r30554 if not shelvedfile(repo, basename, patchextension).exists():
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("shelved change '%s' not found") % basename)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Boris Feld
shelve: handle shelved node on unfiltered repository...
r39409 repo = repo.unfiltered()
FUJIWARA Katsunori
shelve: widen wlock scope of unshelve for consistency while processing...
r27287 lock = tr = None
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 try:
lock = repo.lock()
tr = repo.transaction('unshelve', report=lambda x: None)
oldtiprev = len(repo)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Mads Kiilerich
shelve: repo['.'] is not a wctx but a pctx...
r20958 pctx = repo['.']
tmpwctx = pctx
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 # The goal is to have a commit structure like so:
Mads Kiilerich
shelve: repo['.'] is not a wctx but a pctx...
r20958 # ...-> pctx -> tmpwctx -> shelvectx
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 # where tmpwctx is an optional commit with the user's pending changes
# and shelvectx is the unshelved changes. Then we merge it all down
Mads Kiilerich
shelve: repo['.'] is not a wctx but a pctx...
r20958 # to the original pctx.
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Kostia Balytskyi
shelve: add logic to preserve active bookmarks...
r31664 activebookmark = _backupactivebookmark(repo)
Martin von Zweigbergk
shelve: reduce scope of merge tool config override...
r37986 tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,
tmpwctx)
Martin von Zweigbergk
shelve: pass transaction around to clarify where it's used...
r41043 repo, shelvectx = _unshelverestorecommit(ui, repo, tr, basename)
Martin von Zweigbergk
shelve: reduce scope of merge tool config override...
r37986 _checkunshelveuntrackedproblems(ui, repo, shelvectx)
branchtorestore = ''
if shelvectx.branch() != shelvectx.p1().branch():
branchtorestore = shelvectx.branch()
shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev,
basename, pctx, tmpwctx,
shelvectx, branchtorestore,
activebookmark)
Jun Wu
shelve: get rid of ui.backupconfig
r31462 overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
with ui.configoverride(overrides, 'unshelve'):
Martin von Zweigbergk
shelve: reduce scope of merge tool config override...
r37986 mergefiles(ui, repo, pctx, shelvectx)
restorebranch(ui, repo, branchtorestore)
_forgetunknownfiles(repo, shelvectx, addedbefore)
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908
Martin von Zweigbergk
shelve: reduce scope of merge tool config override...
r37986 shelvedstate.clear(repo)
_finishunshelve(repo, oldtiprev, tr, activebookmark)
unshelvecleanup(ui, repo, basename, opts)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 finally:
if tr:
tr.release()
FUJIWARA Katsunori
shelve: widen wlock scope of unshelve for consistency while processing...
r27287 lockmod.release(lock)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
@command('shelve',
[('A', 'addremove', None,
_('mark new/missing files as added/removed before shelving')),
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908 ('u', 'unknown', None,
timeless
shelve: lowercase flag description...
r27921 _('store unknown files in the shelve')),
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ('', 'cleanup', None,
_('delete all shelved changes')),
('', 'date', '',
_('shelve with the specified commit date'), _('DATE')),
('d', 'delete', None,
_('delete the named shelved change(s)')),
FUJIWARA Katsunori
shelve: accept '--edit' like other commands creating new changeset...
r21852 ('e', 'edit', False,
_('invoke editor on commit messages')),
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ('l', 'list', None,
_('list current shelves')),
('m', 'message', '',
_('use text as shelve message'), _('TEXT')),
('n', 'name', '',
_('use the given name for the shelved commit'), _('NAME')),
('p', 'patch', None,
Danny Hooper
shelve: improve help text for --patch and --stat...
r38736 _('output patches for changes (provide the names of the shelved '
'changes as positional arguments)')),
Laurent Charignon
shelve: add interactive mode command line option
r24477 ('i', 'interactive', None,
Laurent Charignon
selve: make 'shelve --interactive' not experimental...
r25260 _('interactive mode, only works while creating a shelve')),
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ('', 'stat', None,
Danny Hooper
shelve: improve help text for --patch and --stat...
r38736 _('output diffstat-style summary of changes (provide the names of '
'the shelved changes as positional arguments)')
)] + cmdutil.walkopts,
rdamazio@google.com
help: assigning categories to existing commands...
r40329 _('hg shelve [OPTION]... [FILE]...'),
helpcategory=command.CATEGORY_WORKING_DIRECTORY)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 def shelvecmd(ui, repo, *pats, **opts):
'''save and set aside changes from the working directory
Shelving takes files that "hg status" reports as not clean, saves
the modifications to a bundle (a shelved change), and reverts the
files so that their state in the working directory becomes clean.
To restore these changes to the working directory, using "hg
unshelve"; this will work even if you switch to a different
commit.
When no files are specified, "hg shelve" saves all not-clean
files. If specific files or directories are named, only changes to
those files are shelved.
Mads Kiilerich
shelve: add missing space in help text...
r30419 In bare shelve (when no files are specified, without interactive,
liscju
shelve: adds restoring newly created branch (issue5048) (BC)...
r28573 include and exclude option), shelving remembers information if the
working directory was on newly created branch, in other words working
directory was on different branch than its first parent. In this
situation unshelving restores branch information to the working directory.
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 Each shelved change has a name that makes it easier to find later.
The name of a shelved change defaults to being based on the active
bookmark, or if there is no active bookmark, the current named
branch. To specify a different name, use ``--name``.
To see a list of existing shelved changes, use the ``--list``
option. For each shelved change, this will print its name, age,
and description; use ``--patch`` or ``--stat`` for more details.
To delete specific shelved changes, use ``--delete``. To delete
all shelved changes, use ``--cleanup``.
'''
Pulkit Goyal
py3: handle keyword arguments in hgext/shelve.py...
r35006 opts = pycompat.byteskwargs(opts)
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 allowables = [
Martin von Zweigbergk
cleanup: use set literals...
r32291 ('addremove', {'create'}), # 'create' is pseudo action
('unknown', {'create'}),
('cleanup', {'cleanup'}),
# ('date', {'create'}), # ignored for passing '--date "0 0"' in tests
('delete', {'delete'}),
('edit', {'create'}),
('list', {'list'}),
('message', {'create'}),
('name', {'create'}),
('patch', {'patch', 'list'}),
('stat', {'stat', 'list'}),
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 ]
def checkopt(opt):
liscju
shelve: changes getting opts values by get method...
r28401 if opts.get(opt):
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 for i, allowable in allowables:
Tony Tung
shelve: refactor allowables to specify sets of valid operations...
r25103 if opts[i] and opt not in allowable:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("options '--%s' and '--%s' may not be "
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 "used together") % (opt, i))
return True
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 if checkopt('cleanup'):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if pats:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("cannot specify names when using '--cleanup'"))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 return cleanupcmd(ui, repo)
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 elif checkopt('delete'):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 return deletecmd(ui, repo, pats)
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 elif checkopt('list'):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 return listcmd(ui, repo, pats, opts)
Danny Hooper
shelve: pick the most recent shelve if none specified for --patch/--stat...
r38737 elif checkopt('patch') or checkopt('stat'):
return patchcmds(ui, repo, pats, opts)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 else:
return createcmd(ui, repo, pats, opts)
def extsetup(ui):
cmdutil.unfinishedstates.append(
FUJIWARA Katsunori
shelve: disallow commit while unshelve is in progress...
r19963 [shelvedstate._filename, False, False,
_('unshelve already in progress'),
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 _("use 'hg unshelve --continue' or 'hg unshelve --abort'")])
timeless
shelve: hook afterresolvedstates
r27694 cmdutil.afterresolvedstates.append(
[shelvedstate._filename, _('hg unshelve --continue')])