##// END OF EJS Templates
templater: factor out function that evaluates argument as integer...
templater: factor out function that evaluates argument as integer We have more bare int()s that may raise ValueError or TypeError. This function will be used to fix them.

File last commit:

r28124:98336538 default
r28343:a6c2310b default
Show More
shelve.py
859 lines | 31.8 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".
"""
Martin von Zweigbergk
util: drop alias for collections.deque...
r25113 import collections
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 import itertools
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 from mercurial.i18n import _
Mads Kiilerich
shelve: publicancestors do not have to visit nullrev...
r20407 from mercurial.node import nullid, nullrev, bin, hex
Mads Kiilerich
shelve: mention walk options in help
r20409 from mercurial import changegroup, cmdutil, scmutil, phases, commands
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 from mercurial import error, hg, mdiff, merge, patch, repair, util
Pierre-Yves David
shelve: properly process bundle2 bundle
r26799 from mercurial import templatefilters, exchange, bundlerepo, bundle2
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 from mercurial import lock as lockmod
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 from hgext import rebase
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 import errno
cmdtable = {}
command = cmdutil.command(cmdtable)
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # Note for extension authors: ONLY specify testedwith = 'internal' for
# 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.
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 testedwith = 'internal'
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 backupdir = 'shelve-backup'
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
self.vfs = scmutil.vfs(repo.join('shelved'))
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 self.backupvfs = scmutil.vfs(repo.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
FUJIWARA Katsunori
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs...
r20982 def applybundle(self):
fp = self.opener()
try:
Pierre-Yves David
bundle2: add a ui argument to readbundle...
r21064 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
Pierre-Yves David
shelve: properly process bundle2 bundle
r26799 if not isinstance(gen, bundle2.unbundle20):
gen.apply(self.repo, 'unshelve',
'bundle:' + self.vfs.join(self.fname),
targetphase=phases.secret)
if isinstance(gen, bundle2.unbundle20):
bundle2.applybundle(self.repo, gen,
self.repo.currenttransaction(),
source='unshelve',
url='bundle:' + self.vfs.join(self.fname))
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):
return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root,
self.vfs.join(self.fname))
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'
cg = changegroup.changegroupsubset(self.repo, bases, [node], 'shelve',
version=cgversion)
changegroup.writebundle(self.ui, cg, self.fname, btype, self.vfs,
compression=compression)
FUJIWARA Katsunori
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
r20983
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.
"""
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 _version = 1
_filename = 'shelvedstate'
@classmethod
def load(cls, repo):
Angel Ezquerra
localrepo: remove all external users of localrepo.opener...
r23877 fp = repo.vfs(cls._filename)
Pierre-Yves David
shelve: drop pickle usage...
r19904 try:
version = int(fp.readline().strip())
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Pierre-Yves David
shelve: drop pickle usage...
r19904 if version != cls._version:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('this version of shelve is incompatible '
Pierre-Yves David
shelve: drop pickle usage...
r19904 'with the version used in this repo'))
name = fp.readline().strip()
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 wctx = fp.readline().strip()
pendingctx = fp.readline().strip()
Pierre-Yves David
shelve: drop pickle usage...
r19904 parents = [bin(h) for h in fp.readline().split()]
stripnodes = [bin(h) for h in fp.readline().split()]
finally:
fp.close()
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
obj = cls()
obj.name = name
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 obj.wctx = repo[bin(wctx)]
obj.pendingctx = repo[bin(pendingctx)]
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 obj.parents = parents
obj.stripnodes = stripnodes
return obj
@classmethod
Durham Goode
unshelve: don't commit unknown files during unshelve (issue4113)...
r20149 def save(cls, repo, name, originalwctx, pendingctx, stripnodes):
Angel Ezquerra
localrepo: remove all external users of localrepo.opener...
r23877 fp = repo.vfs(cls._filename, 'wb')
Pierre-Yves David
shelve: drop pickle usage...
r19904 fp.write('%i\n' % cls._version)
fp.write('%s\n' % name)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 fp.write('%s\n' % hex(originalwctx.node()))
fp.write('%s\n' % hex(pendingctx.node()))
Pierre-Yves David
shelve: drop pickle usage...
r19904 fp.write('%s\n' % ' '.join([hex(p) for p in repo.dirstate.parents()]))
fp.write('%s\n' % ' '.join([hex(n) for n in stripnodes]))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 fp.close()
Pierre-Yves David
shelve: use the class constant in the clear method...
r19908 @classmethod
def clear(cls, repo):
util.unlinkpath(repo.join(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):
vfs = scmutil.vfs(repo.join(backupdir))
maxbackups = repo.ui.configint('shelve', 'maxbackups', 10)
hgfiles = [f for f in vfs.listdir() if f.endswith('.hg')]
hgfiles = sorted([(vfs.stat(f).st_mtime, f) for f in hgfiles])
FUJIWARA Katsunori
shelve: keep old backups if timestamp can't decide exact order of them...
r25774 if 0 < maxbackups and maxbackups < len(hgfiles):
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
Colin Chan
shelve: only keep the latest N shelve backups...
r25713 base = f[:-3]
for ext in 'hg patch'.split():
try:
vfs.unlink(base + '.' + ext)
except OSError as err:
if err.errno != errno.ENOENT:
raise
FUJIWARA Katsunori
shelve: add utility to abort current transaction but keep dirstate...
r26522 def _aborttransaction(repo):
'''Abort current transaction for shelve/unshelve, but keep dirstate
'''
backupname = 'dirstate.shelve'
dirstatebackup = None
try:
# create backup of (un)shelved dirstate, because aborting transaction
# should restore dirstate to one at the beginning of the
# transaction, which doesn't include the result of (un)shelving
fp = repo.vfs.open(backupname, "w")
dirstatebackup = backupname
# clearing _dirty/_dirtypl of dirstate by _writedirstate below
# is unintentional. but it doesn't cause problem in this case,
# because no code path refers them until transaction is aborted.
repo.dirstate._writedirstate(fp) # write in-memory changes forcibly
tr = repo.currenttransaction()
tr.abort()
# restore to backuped dirstate
repo.vfs.rename(dirstatebackup, 'dirstate')
dirstatebackup = None
finally:
if dirstatebackup:
repo.vfs.unlink(dirstatebackup)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 def createcmd(ui, repo, pats, opts):
Augie Fackler
shelve: some docstring cleanups
r19911 """subcommand that creates a new shelve"""
Bryan O'Sullivan
with: use context manager for wlock in shelve createcmd
r27834 with repo.wlock():
FUJIWARA Katsunori
shelve: execute checkunfinished inside wlock scope...
r27198 cmdutil.checkunfinished(repo)
FUJIWARA Katsunori
shelve: widen wlock scope of shelve for consistency while processing...
r27197 return _docreatecmd(ui, repo, pats, opts)
Pierre-Yves David
shelve: add minimal documentation to all functions...
r19909
FUJIWARA Katsunori
shelve: widen wlock scope of shelve for consistency while processing...
r27197 def _docreatecmd(ui, repo, pats, opts):
Pierre-Yves David
shelve: rename 'publicancestors' to something accurate (issue4737)...
r26602 def mutableancestors(ctx):
"""return all mutable ancestors for ctx (included)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Mads Kiilerich
shelve: really pass publicancestors to changegroupsubset - not the parents...
r20408 Much faster than the revset ancestors(ctx) & draft()"""
Mads Kiilerich
shelve: publicancestors do not have to visit nullrev...
r20407 seen = set([nullrev])
Martin von Zweigbergk
util: drop alias for collections.deque...
r25113 visit = collections.deque()
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 visit.append(ctx)
while visit:
ctx = visit.popleft()
Mads Kiilerich
shelve: really pass publicancestors to changegroupsubset - not the parents...
r20408 yield ctx.node()
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 for parent in ctx.parents():
rev = parent.rev()
if rev not in seen:
seen.add(rev)
if parent.mutable():
visit.append(parent)
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]
# we never need the user, so we use a generic user for all shelve operations
user = 'shelve@localhost'
Ryan McElroy
bookmarks: rename bookmarkcurrent to activebookmark (API)...
r24947 label = repo._activebookmark or parent.branch() or 'default'
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
# slashes aren't allowed in filenames, therefore we rename it
Sean Farley
shelve: remove unused variable caught by pyflakes
r20937 label = label.replace('/', '_')
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
def gennames():
yield label
for i in xrange(1, 100):
yield '%s-%02d' % (label, i)
if parent.node() != 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
if not opts['message']:
opts['message'] = desc
name = opts['name']
FUJIWARA Katsunori
shelve: widen wlock scope of shelve for consistency while processing...
r27197 lock = tr = 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.
tr = repo.transaction('commit', report=lambda x: None)
if name:
if shelvedfile(repo, name, 'hg').exists():
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("a shelved change named '%s' already exists"
) % name)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 else:
for n in gennames():
if not shelvedfile(repo, n, 'hg').exists():
name = n
break
else:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("too many shelved changes named '%s'") %
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 label)
# ensure we are not creating a subdirectory or a hidden file
if '/' in name or '\\' in name:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_('shelved change names may not contain slashes'))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if name.startswith('.'):
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("shelved change names may not start with '.'"))
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))
extra={}
if includeunknown:
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)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Simon Farnsworth
shelve: move commitfunc closer to use site...
r27888 def commitfunc(ui, repo, message, match, opts):
hasmq = util.safehasattr(repo, 'mq')
if hasmq:
saved, repo.mq.checkapplied = repo.mq.checkapplied, False
backup = repo.ui.backupconfig('phases', 'new-commit')
try:
repo.ui. setconfig('phases', 'new-commit', phases.secret)
editor = cmdutil.getcommiteditor(editform='shelve.shelve',
**opts)
return repo.commit(message, user, opts.get('date'), match,
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908 editor=editor, extra=extra)
Simon Farnsworth
shelve: move commitfunc closer to use site...
r27888 finally:
repo.ui.restoreconfig(backup)
if hasmq:
repo.mq.checkapplied = saved
Laurent Charignon
shelve: add interactive mode...
r24478 def interactivecommitfunc(ui, repo, *pats, **opts):
match = scmutil.match(repo['.'], pats, {})
message = opts['message']
return commitfunc(ui, repo, message, match, opts)
if not interactive:
node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
else:
FUJIWARA Katsunori
shelve: omit incorrect 'commit' suggestion at 'hg shelve -i'...
r25799 node = cmdutil.dorecord(ui, repo, interactivecommitfunc, None,
Laurent Charignon
shelve: add interactive mode...
r24478 False, cmdutil.recordfilter, *pats, **opts)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if not node:
stat = repo.status(match=scmutil.match(repo[None], pats, opts))
Martin von Zweigbergk
shelve: access status fields by name rather than index
r22922 if stat.deleted:
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 ui.status(_("nothing changed (%d missing files, see "
Martin von Zweigbergk
shelve: access status fields by name rather than index
r22922 "'hg status')\n") % len(stat.deleted))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 else:
ui.status(_("nothing changed\n"))
return 1
Pierre-Yves David
shelve: rename 'publicancestors' to something accurate (issue4737)...
r26602 bases = list(mutableancestors(repo[node]))
Pierre-Yves David
shelve: move changegroup generation inside writebundle...
r26506 shelvedfile(repo, name, 'hg').writebundle(bases, node)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 cmdutil.export(repo, [node],
fp=shelvedfile(repo, name, 'patch').opener('wb'),
opts=mdiff.diffopts(git=True))
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():
desc = util.ellipsis(desc, ui.termwidth())
ui.status(_('shelved as %s\n') % name)
hg.update(repo, parent.node())
FUJIWARA Katsunori
shelve: restore shelved dirstate explicitly after aborting transaction...
r26523
_aborttransaction(repo)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 finally:
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
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():
Mads Kiilerich
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n...
r22199 for (name, _type) in repo.vfs.readdir('shelved'):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 suffix = name.rsplit('.', 1)[-1]
Martin von Zweigbergk
shelve: avoid writing file that is never read from...
r22581 if suffix in ('hg', 'patch'):
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:
for suffix in 'hg patch'.split():
shelvedfile(repo, name, suffix).movetobackup()
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:
names = repo.vfs.readdir('shelved')
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)
if not pfx or sfx != 'patch':
continue
st = shelvedfile(repo, name).stat()
info.append((st.st_mtime, shelvedfile(repo, pfx).filename()))
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'
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
David Soria Parra
shelve: new output format for shelve listings...
r19855 age = '(%s)' % templatefilters.age(util.makedate(mtime), 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
Bryan O'Sullivan
shelve: use a context manager for file I/O in listcmd
r27775 with open(name + '.patch', '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():
desc = util.ellipsis(desc, width - used)
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']:
for chunk, label in patch.diffstatui(difflines, width=width,
git=True):
ui.write(chunk, label=label)
Tony Tung
shelve: allow --patch and --stat without --list for a single shelf...
r25104 def singlepatchcmds(ui, repo, pats, opts, subcommand):
"""subcommand that displays a single shelf"""
if len(pats) != 1:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(_("--%s expects a single shelf") % subcommand)
Tony Tung
shelve: allow --patch and --stat without --list for a single shelf...
r25104 shelfname = pats[0]
if not shelvedfile(repo, shelfname, 'patch').exists():
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 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
Bryan O'Sullivan
with: use context manager in unshelveabort
r27841 util.rename(repo.join('unshelverebasestate'),
repo.join('rebasestate'))
try:
rebase.rebase(ui, repo, **{
'abort' : True
})
except Exception:
util.rename(repo.join('rebasestate'),
repo.join('unshelverebasestate'))
raise
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)
repair.strip(ui, repo, state.stripnodes, backup=False,
topic='shelve')
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."""
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 oldquiet = ui.quiet
try:
ui.quiet = True
hg.update(repo, wctx.node())
files = []
files.extend(shelvectx.files())
files.extend(shelvectx.parents()[0].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:
Siddharth Agarwal
origpath: move from cmdutil to scmutil...
r27651 util.rename(file, scmutil.origpath(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),
**{'no_backup': True})
Matt Mackall
unshelve: silence internal revert...
r22184 ui.popbuffer()
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 finally:
ui.quiet = oldquiet
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"""
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if not opts['keep']:
Martin von Zweigbergk
shelve: avoid writing file that is never read from...
r22581 for filetype in 'hg patch'.split():
Colin Chan
shelve: always backup shelves instead of deleting them...
r25712 shelvedfile(repo, name, filetype).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)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if [f for f in ms if ms[f] == 'u']:
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
util.rename(repo.join('unshelverebasestate'),
repo.join('rebasestate'))
try:
rebase.rebase(ui, repo, **{
'continue' : True
})
except Exception:
util.rename(repo.join('rebasestate'),
repo.join('unshelverebasestate'))
raise
shelvectx = repo['tip']
if not shelvectx in state.pendingctx.children():
# rebase was a no-op, so it produced no child commit
shelvectx = state.pendingctx
Jordi Gutiérrez Hermoso
shelve: don't delete "." when rebase is a no-op (issue4398)...
r22842 else:
# only strip the shelvectx if the rebase produced it
state.stripnodes.append(shelvectx.node())
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)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
Jordi Gutiérrez Hermoso
strip: remove -b/--backup codepaths...
r22057 repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve')
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)
@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')),
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'))],
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 _('hg unshelve [SHELVED]'))
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
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):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 abortf = opts['abort']
continuef = opts['continue']
if not abortf and not continuef:
cmdutil.checkunfinished(repo)
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)
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'))
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]
Martin von Zweigbergk
shelve: avoid writing file that is never read from...
r22581 if not shelvedfile(repo, basename, 'patch').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
Mads Kiilerich
shelve: be quiet when unshelve pulls from the shelve bundle...
r20412 oldquiet = ui.quiet
FUJIWARA Katsunori
shelve: widen wlock scope of unshelve for consistency while processing...
r27287 lock = tr = None
Siddharth Agarwal
unshelve: add support for custom merge tools...
r27021 forcemerge = ui.backupconfig('ui', 'forcemerge')
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 try:
Siddharth Agarwal
unshelve: add support for custom merge tools...
r27021 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'unshelve')
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 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
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908 # Store pending changes in a commit and remember added in case a shelve
# contains unknown files that are part of the pending change
Martin von Zweigbergk
shelve: access status fields by name rather than index
r22922 s = repo.status()
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908 addedbefore = frozenset(s.added)
Martin von Zweigbergk
shelve: access status fields by name rather than index
r22922 if s.modified or s.added or s.removed or s.deleted:
Mads Kiilerich
shelve: status messages from unshelve...
r20413 ui.status(_("temporarily committing pending changes "
"(restore with 'hg unshelve --abort')\n"))
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 def commitfunc(ui, repo, message, match, opts):
hasmq = util.safehasattr(repo, 'mq')
if hasmq:
saved, repo.mq.checkapplied = repo.mq.checkapplied, False
Pierre-Yves David
shelve: do not retract phase boundary by hand...
r22040 backup = repo.ui.backupconfig('phases', 'new-commit')
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 try:
Siddharth Agarwal
unshelve: shed spurious space
r27020 repo.ui.setconfig('phases', 'new-commit', phases.secret)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 return repo.commit(message, 'shelve@localhost',
opts.get('date'), match)
finally:
Pierre-Yves David
shelve: do not retract phase boundary by hand...
r22040 repo.ui.restoreconfig(backup)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 if hasmq:
repo.mq.checkapplied = saved
tempopts = {}
tempopts['message'] = "pending changes temporary commit"
Mads Kiilerich
shelve: introduce secret option for using fixed date for temporary commit...
r20960 tempopts['date'] = opts.get('date')
Mads Kiilerich
shelve: be quiet when unshelve pulls from the shelve bundle...
r20412 ui.quiet = True
node = cmdutil.commit(ui, repo, commitfunc, [], tempopts)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 tmpwctx = repo[node]
FUJIWARA Katsunori
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs...
r20982 ui.quiet = True
shelvedfile(repo, basename, 'hg').applybundle()
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Mads Kiilerich
shelve: be quiet when unshelve pulls from the shelve bundle...
r20412 ui.quiet = oldquiet
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 shelvectx = repo['tip']
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 # If the shelve is not immediately on top of the commit
# we'll be merging with, rebase it to be on top.
if tmpwctx.node() != shelvectx.parents()[0].node():
Mads Kiilerich
shelve: status messages from unshelve...
r20413 ui.status(_('rebasing shelved changes\n'))
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 try:
rebase.rebase(ui, repo, **{
'rev' : [shelvectx.rev()],
'dest' : str(tmpwctx.rev()),
'keep' : True,
Siddharth Agarwal
unshelve: add support for custom merge tools...
r27021 'tool' : opts.get('tool', ''),
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 })
except error.InterventionRequired:
tr.close()
stripnodes = [repo.changelog.node(rev)
for rev in xrange(oldtiprev, len(repo))]
Mads Kiilerich
shelve: repo['.'] is not a wctx but a pctx...
r20958 shelvedstate.save(repo, basename, pctx, tmpwctx, stripnodes)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
util.rename(repo.join('rebasestate'),
repo.join('unshelverebasestate'))
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 raise error.InterventionRequired(
_("unresolved conflicts (see 'hg resolve', then "
"'hg unshelve --continue')"))
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961
# refresh ctx after rebase completes
shelvectx = repo['tip']
if not shelvectx in tmpwctx.children():
# rebase was a no-op, so it produced no child commit
shelvectx = tmpwctx
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
Mads Kiilerich
shelve: repo['.'] is not a wctx but a pctx...
r20958 mergefiles(ui, repo, pctx, shelvectx)
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908
# Forget any files that were unknown before the shelve, unknown before
# unshelve started, but are now added.
shelveunknown = shelvectx.extra().get('shelve_unknown')
if shelveunknown:
shelveunknown = frozenset(shelveunknown.split('\0'))
addedafter = frozenset(repo.status().added)
toforget = (addedafter & shelveunknown) - addedbefore
repo[None].forget(toforget)
Durham Goode
shelve: use rebase instead of merge (issue4068)...
r19961 shelvedstate.clear(repo)
# 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.
David Soria Parra
shelve: unshelve using an unfiltered repository...
r20064 repo.unfiltered().changelog.strip(oldtiprev, tr)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854
unshelvecleanup(ui, repo, basename, opts)
FUJIWARA Katsunori
shelve: restore unshelved dirstate explicitly after aborting transaction...
r26524
_aborttransaction(repo)
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 finally:
Mads Kiilerich
shelve: be quiet when unshelve pulls from the shelve bundle...
r20412 ui.quiet = oldquiet
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if tr:
tr.release()
FUJIWARA Katsunori
shelve: widen wlock scope of unshelve for consistency while processing...
r27287 lockmod.release(lock)
Siddharth Agarwal
unshelve: add support for custom merge tools...
r27021 ui.restoreconfig(forcemerge)
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,
_('show patch')),
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,
Mads Kiilerich
shelve: mention walk options in help
r20409 _('output diffstat-style summary of changes'))] + commands.walkopts,
Mads Kiilerich
shelve: mention FILE options in help...
r20410 _('hg shelve [OPTION]... [FILE]...'))
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.
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``.
'''
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 allowables = [
Tony Tung
shelve: refactor allowables to specify sets of valid operations...
r25103 ('addremove', set(['create'])), # 'create' is pseudo action
Simon Farnsworth
shelve: permit shelves to contain unknown files...
r27908 ('unknown', set(['create'])),
Tony Tung
shelve: refactor allowables to specify sets of valid operations...
r25103 ('cleanup', set(['cleanup'])),
# ('date', set(['create'])), # ignored for passing '--date "0 0"' in tests
('delete', set(['delete'])),
('edit', set(['create'])),
('list', set(['list'])),
('message', set(['create'])),
('name', set(['create'])),
Tony Tung
shelve: allow --patch and --stat without --list for a single shelf...
r25104 ('patch', set(['patch', 'list'])),
('stat', set(['stat', 'list'])),
FUJIWARA Katsunori
shelve: refactor option combination check to easily add new ones...
r21851 ]
def checkopt(opt):
David Soria Parra
shelve: add a shelve extension to save/restore working changes...
r19854 if opts[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)
Tony Tung
shelve: allow --patch and --stat without --list for a single shelf...
r25104 elif checkopt('patch'):
return singlepatchcmds(ui, repo, pats, opts, subcommand='patch')
elif checkopt('stat'):
return singlepatchcmds(ui, repo, pats, opts, subcommand='stat')
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')])