diff --git a/contrib/win32/mercurial.ini b/contrib/win32/mercurial.ini --- a/contrib/win32/mercurial.ini +++ b/contrib/win32/mercurial.ini @@ -64,7 +64,6 @@ ;relink = ;schemes = ;share = -;shelve = ;transplant = ;win32mbcs = ;zeroconf = diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -3296,6 +3296,9 @@ unfinishedstates = [ ('graftstate', True, False, _('graft in progress'), _("use 'hg graft --continue' or 'hg graft --stop' to stop")), + ('shelvedstate', False, False, + _('unshelve already in progress'), + _("use 'hg unshelve --continue' or 'hg unshelve --abort'")), ('updatestate', True, False, _('last update was interrupted'), _("use 'hg update' to get a consistent checkout")) ] @@ -3333,6 +3336,8 @@ afterresolvedstates = [ ('graftstate', _('hg graft --continue')), + ('shelvedstate', + _('hg unshelve --continue')), ] def howtocontinue(repo): diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -58,6 +58,7 @@ rewriteutil, scmutil, server, + shelve as shelvemod, state as statemod, streamclone, tags as tagsmod, @@ -5307,6 +5308,106 @@ 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', @@ -6035,6 +6136,59 @@ 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')), diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -1082,6 +1082,9 @@ coreconfigitem('share', 'poolnaming', default='identity', ) +coreconfigitem('shelve','maxbackups', + default=10, +) coreconfigitem('smtp', 'host', default=None, ) diff --git a/hgext/shelve.py b/mercurial/shelve.py rename from hgext/shelve.py rename to mercurial/shelve.py --- a/hgext/shelve.py +++ b/mercurial/shelve.py @@ -27,8 +27,8 @@ import itertools import stat -from mercurial.i18n import _ -from mercurial import ( +from .i18n import _ +from . import ( bookmarks, bundle2, bundlerepo, @@ -45,37 +45,17 @@ patch, phases, pycompat, - registrar, repair, scmutil, templatefilters, util, vfs as vfsmod, ) - -from . import ( - rebase, -) -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'] @@ -313,6 +293,15 @@ for ext in shelvefileextensions: vfs.tryunlink(base + '.' + ext) +# duplicate of rebase.clearstatus to avoid importing rebase +def clearstatus(repo): + 'Remove the status files' + # Make sure the active transaction won't write the state file + tr = repo.currenttransaction() + if tr: + tr.removefilegenerator('rebasestate') + repo.vfs.unlinkpath("rebasestate", ignoremissing=True) + def _backupactivebookmark(repo): activebookmark = repo._activebookmark if activebookmark: @@ -659,7 +648,7 @@ if repo.vfs.exists('unshelverebasestate'): repo.vfs.rename('unshelverebasestate', 'rebasestate') - rebase.clearstatus(repo) + clearstatus(repo) mergefiles(ui, repo, state.wctx, state.pendingctx) if not phases.supportinternal(repo): @@ -742,7 +731,7 @@ if repo.vfs.exists('unshelverebasestate'): repo.vfs.rename('unshelverebasestate', 'rebasestate') - rebase.clearstatus(repo) + clearstatus(repo) mergefiles(ui, repo, state.wctx, shelvectx) restorebranch(ui, repo, state.branchtorestore) @@ -877,59 +866,6 @@ 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') @@ -1037,111 +973,3 @@ 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): - cmdutil.unfinishedstates.append( - [shelvedstate._filename, False, False, - _('unshelve already in progress'), - _("use 'hg unshelve --continue' or 'hg unshelve --abort'")]) - cmdutil.afterresolvedstates.append( - [shelvedstate._filename, _('hg unshelve --continue')]) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -102,7 +102,6 @@ # # histedit = # rebase = -# shelve = # uncommit = """, diff --git a/tests/test-bookflow.t b/tests/test-bookflow.t --- a/tests/test-bookflow.t +++ b/tests/test-bookflow.t @@ -215,11 +215,11 @@ $ 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 diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -45,12 +45,14 @@ rollback root serve + shelve status summary tag tags tip unbundle + unshelve update verify version @@ -228,7 +230,7 @@ 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 @@ rollback: dry-run, force root: 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 diff --git a/tests/test-copytrace-heuristics.t b/tests/test-copytrace-heuristics.t --- a/tests/test-copytrace-heuristics.t +++ b/tests/test-copytrace-heuristics.t @@ -15,7 +15,6 @@ $ 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' diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t --- a/tests/test-globalopts.t +++ b/tests/test-globalopts.t @@ -356,8 +356,10 @@ 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 @@ 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: diff --git a/tests/test-help-hide.t b/tests/test-help-hide.t --- a/tests/test-help-hide.t +++ b/tests/test-help-hide.t @@ -60,8 +60,10 @@ 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 @@ 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: diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -112,8 +112,10 @@ 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 @@ 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 @@ 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 @@ -2690,6 +2693,13 @@ (no help text available)