Commit bb58edac authored by Navaneeth Suresh's avatar Navaneeth Suresh
Browse files

shelve: move shelve extension to core

Until now, `shelve` was bootstrapped as an extension. This patch adds
`shelve` on core.

Differential Revision: https://phab.mercurial-scm.org/D6553
parent 80e0ea08b55c
......@@ -64,7 +64,6 @@ editor = notepad
;relink =
;schemes =
;share =
;shelve =
;transplant =
;win32mbcs =
;zeroconf =
......
......@@ -58,6 +58,7 @@ from . import (
rewriteutil,
scmutil,
server,
shelve as shelvemod,
state as statemod,
streamclone,
tags as tagsmod,
......@@ -5324,6 +5325,106 @@ def serve(ui, repo, **opts):
service = server.createservice(ui, repo, opts)
return server.runservice(opts, initfn=service.init, runfn=service.run)
@command('shelve',
[('A', 'addremove', None,
_('mark new/missing files as added/removed before shelving')),
('u', 'unknown', None,
_('store unknown files in the shelve')),
('', 'cleanup', None,
_('delete all shelved changes')),
('', 'date', '',
_('shelve with the specified commit date'), _('DATE')),
('d', 'delete', None,
_('delete the named shelved change(s)')),
('e', 'edit', False,
_('invoke editor on commit messages')),
('k', 'keep', False,
_('shelve, but keep changes in the working directory')),
('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,
_('output patches for changes (provide the names of the shelved '
'changes as positional arguments)')),
('i', 'interactive', None,
_('interactive mode, only works while creating a shelve')),
('', 'stat', None,
_('output diffstat-style summary of changes (provide the names of '
'the shelved changes as positional arguments)')
)] + cmdutil.walkopts,
_('hg shelve [OPTION]... [FILE]...'),
helpcategory=command.CATEGORY_WORKING_DIRECTORY)
def shelve(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.
In bare shelve (when no files are specified, without interactive,
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.
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``.
'''
opts = pycompat.byteskwargs(opts)
allowables = [
('addremove', {'create'}), # 'create' is pseudo action
('unknown', {'create'}),
('cleanup', {'cleanup'}),
# ('date', {'create'}), # ignored for passing '--date "0 0"' in tests
('delete', {'delete'}),
('edit', {'create'}),
('keep', {'create'}),
('list', {'list'}),
('message', {'create'}),
('name', {'create'}),
('patch', {'patch', 'list'}),
('stat', {'stat', 'list'}),
]
def checkopt(opt):
if opts.get(opt):
for i, allowable in allowables:
if opts[i] and opt not in allowable:
raise error.Abort(_("options '--%s' and '--%s' may not be "
"used together") % (opt, i))
return True
if checkopt('cleanup'):
if pats:
raise error.Abort(_("cannot specify names when using '--cleanup'"))
return shelvemod.cleanupcmd(ui, repo)
elif checkopt('delete'):
return shelvemod.deletecmd(ui, repo, pats)
elif checkopt('list'):
return shelvemod.listcmd(ui, repo, pats, opts)
elif checkopt('patch') or checkopt('stat'):
return shelvemod.patchcmds(ui, repo, pats, opts)
else:
return shelvemod.createcmd(ui, repo, pats, opts)
_NOTTERSE = 'nothing'
@command('status|st',
......@@ -6052,6 +6153,59 @@ def unbundle(ui, repo, fname1, *fnames, **opts):
return postincoming(ui, repo, modheads, opts.get(r'update'), None, None)
@command('unshelve',
[('a', 'abort', None,
_('abort an incomplete unshelve operation')),
('c', 'continue', None,
_('continue an incomplete unshelve operation')),
('k', 'keep', None,
_('keep shelve after unshelving')),
('n', 'name', '',
_('restore shelved change with given name'), _('NAME')),
('t', 'tool', '', _('specify merge tool')),
('', 'date', '',
_('set date for temporary commits (DEPRECATED)'), _('DATE'))],
_('hg unshelve [[-n] SHELVED]'),
helpcategory=command.CATEGORY_WORKING_DIRECTORY)
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
contains the shelved changes is moved to a backup location
(.hg/shelve-backup).
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
will not be moved until you successfully complete the unshelve.)
(Alternatively, you can use ``--abort`` to abandon an unshelve
that causes a conflict. This reverts the unshelved changes, and
leaves the bundle in place.)
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.
After a successful unshelve, the shelved changes are stored in a
backup directory. Only the N most recent backups are kept. N
defaults to 10 but can be overridden using the ``shelve.maxbackups``
configuration option.
.. 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.
"""
with repo.wlock():
return shelvemod._dounshelve(ui, repo, *shelved, **opts)
@command('update|up|checkout|co',
[('C', 'clean', None, _('discard uncommitted changes (no backup)')),
('c', 'check', None, _('require clean working directory')),
......
......@@ -1091,6 +1091,9 @@ coreconfigitem('share', 'pool',
coreconfigitem('share', 'poolnaming',
default='identity',
)
coreconfigitem('shelve','maxbackups',
default=10,
)
coreconfigitem('smtp', 'host',
default=None,
)
......
......@@ -27,8 +27,8 @@ import errno
import itertools
import stat
from mercurial.i18n import _
from mercurial import (
from .i18n import _
from . import (
bookmarks,
bundle2,
bundlerepo,
......@@ -45,35 +45,17 @@ from mercurial import (
patch,
phases,
pycompat,
registrar,
repair,
scmutil,
state as statemod,
templatefilters,
util,
vfs as vfsmod,
)
from mercurial.utils import (
from .utils import (
dateutil,
stringutil,
)
cmdtable = {}
command = registrar.command(cmdtable)
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' 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.
testedwith = 'ships-with-hg-core'
configtable = {}
configitem = registrar.configitem(configtable)
configitem('shelve', 'maxbackups',
default=10,
)
backupdir = 'shelve-backup'
shelvedir = 'shelved'
shelvefileextensions = ['hg', 'patch', 'shelve']
......@@ -863,59 +845,6 @@ def _checkunshelveuntrackedproblems(ui, repo, shelvectx):
hint = _("run hg status to see which files are missing")
raise error.Abort(m, hint=hint)
@command('unshelve',
[('a', 'abort', None,
_('abort an incomplete unshelve operation')),
('c', 'continue', None,
_('continue an incomplete unshelve operation')),
('k', 'keep', None,
_('keep shelve after unshelving')),
('n', 'name', '',
_('restore shelved change with given name'), _('NAME')),
('t', 'tool', '', _('specify merge tool')),
('', 'date', '',
_('set date for temporary commits (DEPRECATED)'), _('DATE'))],
_('hg unshelve [[-n] SHELVED]'),
helpcategory=command.CATEGORY_WORKING_DIRECTORY)
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
contains the shelved changes is moved to a backup location
(.hg/shelve-backup).
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
will not be moved until you successfully complete the unshelve.)
(Alternatively, you can use ``--abort`` to abandon an unshelve
that causes a conflict. This reverts the unshelved changes, and
leaves the bundle in place.)
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.
After a successful unshelve, the shelved changes are stored in a
backup directory. Only the N most recent backups are kept. N
defaults to 10 but can be overridden using the ``shelve.maxbackups``
configuration option.
.. 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.
"""
with repo.wlock():
return _dounshelve(ui, repo, *shelved, **opts)
def _dounshelve(ui, repo, *shelved, **opts):
opts = pycompat.byteskwargs(opts)
abortf = opts.get('abort')
......@@ -1017,110 +946,3 @@ def _dounshelve(ui, repo, *shelved, **opts):
if tr:
tr.release()
lockmod.release(lock)
@command('shelve',
[('A', 'addremove', None,
_('mark new/missing files as added/removed before shelving')),
('u', 'unknown', None,
_('store unknown files in the shelve')),
('', 'cleanup', None,
_('delete all shelved changes')),
('', 'date', '',
_('shelve with the specified commit date'), _('DATE')),
('d', 'delete', None,
_('delete the named shelved change(s)')),
('e', 'edit', False,
_('invoke editor on commit messages')),
('k', 'keep', False,
_('shelve, but keep changes in the working directory')),
('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,
_('output patches for changes (provide the names of the shelved '
'changes as positional arguments)')),
('i', 'interactive', None,
_('interactive mode, only works while creating a shelve')),
('', 'stat', None,
_('output diffstat-style summary of changes (provide the names of '
'the shelved changes as positional arguments)')
)] + cmdutil.walkopts,
_('hg shelve [OPTION]... [FILE]...'),
helpcategory=command.CATEGORY_WORKING_DIRECTORY)
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.
In bare shelve (when no files are specified, without interactive,
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.
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``.
'''
opts = pycompat.byteskwargs(opts)
allowables = [
('addremove', {'create'}), # 'create' is pseudo action
('unknown', {'create'}),
('cleanup', {'cleanup'}),
# ('date', {'create'}), # ignored for passing '--date "0 0"' in tests
('delete', {'delete'}),
('edit', {'create'}),
('keep', {'create'}),
('list', {'list'}),
('message', {'create'}),
('name', {'create'}),
('patch', {'patch', 'list'}),
('stat', {'stat', 'list'}),
]
def checkopt(opt):
if opts.get(opt):
for i, allowable in allowables:
if opts[i] and opt not in allowable:
raise error.Abort(_("options '--%s' and '--%s' may not be "
"used together") % (opt, i))
return True
if checkopt('cleanup'):
if pats:
raise error.Abort(_("cannot specify names when using '--cleanup'"))
return cleanupcmd(ui, repo)
elif checkopt('delete'):
return deletecmd(ui, repo, pats)
elif checkopt('list'):
return listcmd(ui, repo, pats, opts)
elif checkopt('patch') or checkopt('stat'):
return patchcmds(ui, repo, pats, opts)
else:
return createcmd(ui, repo, pats, opts)
def extsetup(ui):
statemod.addunfinished(
'unshelve', fname=shelvedstate._filename, continueflag=True,
cmdmsg=_('unshelve already in progress')
)
......@@ -195,6 +195,10 @@ addunfinished(
continueflag=True,
cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop")
)
addunfinished(
'unshelve', fname='shelvedstate', continueflag=True,
cmdmsg=_('unshelve already in progress')
)
addunfinished(
'update', fname='updatestate', clearable=True,
cmdmsg=_('last update was interrupted'),
......
......@@ -102,7 +102,6 @@ username =
#
# histedit =
# rebase =
# shelve =
# uncommit =
""",
......
......@@ -58,6 +58,8 @@
* `util.dirs()` and `util.finddirs()` now include an entry for the
root directory (empty string).
* shelve is no longer an extension now. it will be turned on by default.
* New API to manage unfinished operations: Earlier there were distinct APIs
which dealt with unfinished states and separate lists maintaining them
that are `cmdutil.afterresolvestates`, `cmdutil.unfinishedstates` and
......
......@@ -215,11 +215,11 @@ test shelving
$ hg diff --stat
test | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
$ hg --config extensions.shelve= shelve
$ hg shelve
shelved as Z
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg pull -uq
$ hg --trace --config extensions.shelve= unshelve
$ hg unshelve
unshelving change 'Z'
rebasing shelved changes
$ hg diff --stat
......
......@@ -45,12 +45,14 @@ Show all commands except debug commands
rollback
root
serve
shelve
status
summary
tag
tags
tip
unbundle
unshelve
update
verify
version
......@@ -228,7 +230,7 @@ Show the options for the "serve" command
Show an error if we use --options with an ambiguous abbreviation
$ hg debugcomplete --options s
hg: command 's' is ambiguous:
serve showconfig status summary
serve shelve showconfig status summary
[255]
Show all commands + options
......@@ -340,12 +342,14 @@ Show all commands + options
rollback: dry-run, force
root: template
serve: accesslog, daemon, daemon-postexec, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate, print-url, subrepos
shelve: addremove, unknown, cleanup, date, delete, edit, keep, list, message, name, patch, interactive, stat, include, exclude
status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, terse, copies, print0, rev, change, include, exclude, subrepos, template
summary: remote
tag: force, local, rev, remove, edit, message, date, user
tags: template
tip: patch, git, style, template
unbundle: update
unshelve: abort, continue, keep, name, tool, date
update: clean, check, merge, date, rev, tool
verify: full
version: template
......
......@@ -15,7 +15,6 @@ Test for the heuristic copytracing algorithm
$ cat >> $HGRCPATH << EOF
> [extensions]
> rebase=
> shelve=
> [alias]
> l = log -G -T 'rev: {rev}\ndesc: {desc}\n'
> pl = log -G -T 'rev: {rev}, phase: {phase}\ndesc: {desc}\n'
......
......@@ -356,8 +356,10 @@ Testing -h/--help:
resolve redo merges or set/view the merge status of files
revert restore files to their checkout state
root print the root (top) of the current working directory
shelve save and set aside changes from the working directory
status show changed files in the working directory
summary summarize working directory state
unshelve restore a shelved change to the working directory
update update working directory (or switch revisions)
Change import/export:
......@@ -486,8 +488,10 @@ Testing -h/--help:
resolve redo merges or set/view the merge status of files
revert restore files to their checkout state
root print the root (top) of the current working directory
shelve save and set aside changes from the working directory
status show changed files in the working directory
summary summarize working directory state
unshelve restore a shelved change to the working directory
update update working directory (or switch revisions)
Change import/export:
......
......@@ -60,8 +60,10 @@ Test hiding some commands (which also happens to hide an entire category).
resolve redo merges or set/view the merge status of files
revert restore files to their checkout state
root print the root (top) of the current working directory
shelve save and set aside changes from the working directory
status show changed files in the working directory
summary summarize working directory state
unshelve restore a shelved change to the working directory
update update working directory (or switch revisions)
Change import/export:
......@@ -194,8 +196,10 @@ Test hiding some topics.
resolve redo merges or set/view the merge status of files
revert restore files to their checkout state
root print the root (top) of the current working directory
shelve save and set aside changes from the working directory
status show changed files in the working directory
summary summarize working directory state
unshelve restore a shelved change to the working directory
update update working directory (or switch revisions)
Change import/export:
......
......@@ -112,8 +112,10 @@ the extension is unknown.
resolve redo merges or set/view the merge status of files
revert restore files to their checkout state
root print the root (top) of the current working directory
shelve save and set aside changes from the working directory
status show changed files in the working directory
summary summarize working directory state
unshelve restore a shelved change to the working directory
update update working directory (or switch revisions)
Change import/export:
......@@ -238,8 +240,10 @@ the extension is unknown.
resolve redo merges or set/view the merge status of files
revert restore files to their checkout state
root print the root (top) of the current working directory
shelve save and set aside changes from the working directory
status show changed files in the working directory
summary summarize working directory state
unshelve restore a shelved change to the working directory
update update working directory (or switch revisions)
Change import/export:
......@@ -375,7 +379,6 @@ Test extension help:
relink recreates hardlinks between repository clones
schemes extend schemes with shortcuts to repository swarms
share share a common history between several working directories
shelve save and restore changes to the working directory
strip strip changesets and their descendants from history
transplant command to transplant changesets from another branch
win32mbcs allow the use of MBCS paths with problematic encodings
......@@ -2705,6 +2708,13 @@ Dish up an empty repo; serve it cold.
(no help text available)
</td></tr>
<tr><td>
<a href="/help/shelve">
shelve
</a>
</td><td>
save and set aside changes from the working directory
</td></tr>
<tr><td>
<a href="/help/tag">
tag
</a>
......@@ -2726,6 +2736,13 @@ Dish up an empty repo; serve it cold.
apply one or more bundle files
</td></tr>
<tr><td>
<a href="/help/unshelve">
unshelve
</a>
</td><td>
restore a shelved change to the working directory
</td></tr>
<tr><td>
<a href="/help/verify">
verify
</a>
......
......@@ -2056,6 +2056,10 @@ help/ shows help topics
"summary": "print the root (top) of the current working directory",
"topic": "root"
},
{
"summary": "save and set aside changes from the working directory",