Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 42541:3de4f17f4824
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
author | Navaneeth Suresh <navaneeths1998@gmail.com> |
---|---|
date | Fri, 28 Jun 2019 21:31:34 +0530 |
parents | 5f2f6912c9e6 |
children | 2e1d9414ff71 |
comparison
equal
deleted
inserted
replaced
42540:80e0ea08b55c | 42541:3de4f17f4824 |
---|---|
56 repair, | 56 repair, |
57 revsetlang, | 57 revsetlang, |
58 rewriteutil, | 58 rewriteutil, |
59 scmutil, | 59 scmutil, |
60 server, | 60 server, |
61 shelve as shelvemod, | |
61 state as statemod, | 62 state as statemod, |
62 streamclone, | 63 streamclone, |
63 tags as tagsmod, | 64 tags as tagsmod, |
64 ui as uimod, | 65 ui as uimod, |
65 util, | 66 util, |
5322 s.serve_forever() | 5323 s.serve_forever() |
5323 | 5324 |
5324 service = server.createservice(ui, repo, opts) | 5325 service = server.createservice(ui, repo, opts) |
5325 return server.runservice(opts, initfn=service.init, runfn=service.run) | 5326 return server.runservice(opts, initfn=service.init, runfn=service.run) |
5326 | 5327 |
5328 @command('shelve', | |
5329 [('A', 'addremove', None, | |
5330 _('mark new/missing files as added/removed before shelving')), | |
5331 ('u', 'unknown', None, | |
5332 _('store unknown files in the shelve')), | |
5333 ('', 'cleanup', None, | |
5334 _('delete all shelved changes')), | |
5335 ('', 'date', '', | |
5336 _('shelve with the specified commit date'), _('DATE')), | |
5337 ('d', 'delete', None, | |
5338 _('delete the named shelved change(s)')), | |
5339 ('e', 'edit', False, | |
5340 _('invoke editor on commit messages')), | |
5341 ('k', 'keep', False, | |
5342 _('shelve, but keep changes in the working directory')), | |
5343 ('l', 'list', None, | |
5344 _('list current shelves')), | |
5345 ('m', 'message', '', | |
5346 _('use text as shelve message'), _('TEXT')), | |
5347 ('n', 'name', '', | |
5348 _('use the given name for the shelved commit'), _('NAME')), | |
5349 ('p', 'patch', None, | |
5350 _('output patches for changes (provide the names of the shelved ' | |
5351 'changes as positional arguments)')), | |
5352 ('i', 'interactive', None, | |
5353 _('interactive mode, only works while creating a shelve')), | |
5354 ('', 'stat', None, | |
5355 _('output diffstat-style summary of changes (provide the names of ' | |
5356 'the shelved changes as positional arguments)') | |
5357 )] + cmdutil.walkopts, | |
5358 _('hg shelve [OPTION]... [FILE]...'), | |
5359 helpcategory=command.CATEGORY_WORKING_DIRECTORY) | |
5360 def shelve(ui, repo, *pats, **opts): | |
5361 '''save and set aside changes from the working directory | |
5362 | |
5363 Shelving takes files that "hg status" reports as not clean, saves | |
5364 the modifications to a bundle (a shelved change), and reverts the | |
5365 files so that their state in the working directory becomes clean. | |
5366 | |
5367 To restore these changes to the working directory, using "hg | |
5368 unshelve"; this will work even if you switch to a different | |
5369 commit. | |
5370 | |
5371 When no files are specified, "hg shelve" saves all not-clean | |
5372 files. If specific files or directories are named, only changes to | |
5373 those files are shelved. | |
5374 | |
5375 In bare shelve (when no files are specified, without interactive, | |
5376 include and exclude option), shelving remembers information if the | |
5377 working directory was on newly created branch, in other words working | |
5378 directory was on different branch than its first parent. In this | |
5379 situation unshelving restores branch information to the working directory. | |
5380 | |
5381 Each shelved change has a name that makes it easier to find later. | |
5382 The name of a shelved change defaults to being based on the active | |
5383 bookmark, or if there is no active bookmark, the current named | |
5384 branch. To specify a different name, use ``--name``. | |
5385 | |
5386 To see a list of existing shelved changes, use the ``--list`` | |
5387 option. For each shelved change, this will print its name, age, | |
5388 and description; use ``--patch`` or ``--stat`` for more details. | |
5389 | |
5390 To delete specific shelved changes, use ``--delete``. To delete | |
5391 all shelved changes, use ``--cleanup``. | |
5392 ''' | |
5393 opts = pycompat.byteskwargs(opts) | |
5394 allowables = [ | |
5395 ('addremove', {'create'}), # 'create' is pseudo action | |
5396 ('unknown', {'create'}), | |
5397 ('cleanup', {'cleanup'}), | |
5398 # ('date', {'create'}), # ignored for passing '--date "0 0"' in tests | |
5399 ('delete', {'delete'}), | |
5400 ('edit', {'create'}), | |
5401 ('keep', {'create'}), | |
5402 ('list', {'list'}), | |
5403 ('message', {'create'}), | |
5404 ('name', {'create'}), | |
5405 ('patch', {'patch', 'list'}), | |
5406 ('stat', {'stat', 'list'}), | |
5407 ] | |
5408 def checkopt(opt): | |
5409 if opts.get(opt): | |
5410 for i, allowable in allowables: | |
5411 if opts[i] and opt not in allowable: | |
5412 raise error.Abort(_("options '--%s' and '--%s' may not be " | |
5413 "used together") % (opt, i)) | |
5414 return True | |
5415 if checkopt('cleanup'): | |
5416 if pats: | |
5417 raise error.Abort(_("cannot specify names when using '--cleanup'")) | |
5418 return shelvemod.cleanupcmd(ui, repo) | |
5419 elif checkopt('delete'): | |
5420 return shelvemod.deletecmd(ui, repo, pats) | |
5421 elif checkopt('list'): | |
5422 return shelvemod.listcmd(ui, repo, pats, opts) | |
5423 elif checkopt('patch') or checkopt('stat'): | |
5424 return shelvemod.patchcmds(ui, repo, pats, opts) | |
5425 else: | |
5426 return shelvemod.createcmd(ui, repo, pats, opts) | |
5427 | |
5327 _NOTTERSE = 'nothing' | 5428 _NOTTERSE = 'nothing' |
5328 | 5429 |
5329 @command('status|st', | 5430 @command('status|st', |
5330 [('A', 'all', None, _('show status of all files')), | 5431 [('A', 'all', None, _('show status of all files')), |
5331 ('m', 'modified', None, _('show only modified files')), | 5432 ('m', 'modified', None, _('show only modified files')), |
6050 "information")) | 6151 "information")) |
6051 modheads = bundle2.combinechangegroupresults(op) | 6152 modheads = bundle2.combinechangegroupresults(op) |
6052 | 6153 |
6053 return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) | 6154 return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) |
6054 | 6155 |
6156 @command('unshelve', | |
6157 [('a', 'abort', None, | |
6158 _('abort an incomplete unshelve operation')), | |
6159 ('c', 'continue', None, | |
6160 _('continue an incomplete unshelve operation')), | |
6161 ('k', 'keep', None, | |
6162 _('keep shelve after unshelving')), | |
6163 ('n', 'name', '', | |
6164 _('restore shelved change with given name'), _('NAME')), | |
6165 ('t', 'tool', '', _('specify merge tool')), | |
6166 ('', 'date', '', | |
6167 _('set date for temporary commits (DEPRECATED)'), _('DATE'))], | |
6168 _('hg unshelve [[-n] SHELVED]'), | |
6169 helpcategory=command.CATEGORY_WORKING_DIRECTORY) | |
6170 def unshelve(ui, repo, *shelved, **opts): | |
6171 """restore a shelved change to the working directory | |
6172 | |
6173 This command accepts an optional name of a shelved change to | |
6174 restore. If none is given, the most recent shelved change is used. | |
6175 | |
6176 If a shelved change is applied successfully, the bundle that | |
6177 contains the shelved changes is moved to a backup location | |
6178 (.hg/shelve-backup). | |
6179 | |
6180 Since you can restore a shelved change on top of an arbitrary | |
6181 commit, it is possible that unshelving will result in a conflict | |
6182 between your changes and the commits you are unshelving onto. If | |
6183 this occurs, you must resolve the conflict, then use | |
6184 ``--continue`` to complete the unshelve operation. (The bundle | |
6185 will not be moved until you successfully complete the unshelve.) | |
6186 | |
6187 (Alternatively, you can use ``--abort`` to abandon an unshelve | |
6188 that causes a conflict. This reverts the unshelved changes, and | |
6189 leaves the bundle in place.) | |
6190 | |
6191 If bare shelved change (when no files are specified, without interactive, | |
6192 include and exclude option) was done on newly created branch it would | |
6193 restore branch information to the working directory. | |
6194 | |
6195 After a successful unshelve, the shelved changes are stored in a | |
6196 backup directory. Only the N most recent backups are kept. N | |
6197 defaults to 10 but can be overridden using the ``shelve.maxbackups`` | |
6198 configuration option. | |
6199 | |
6200 .. container:: verbose | |
6201 | |
6202 Timestamp in seconds is used to decide order of backups. More | |
6203 than ``maxbackups`` backups are kept, if same timestamp | |
6204 prevents from deciding exact order of them, for safety. | |
6205 """ | |
6206 with repo.wlock(): | |
6207 return shelvemod._dounshelve(ui, repo, *shelved, **opts) | |
6208 | |
6055 @command('update|up|checkout|co', | 6209 @command('update|up|checkout|co', |
6056 [('C', 'clean', None, _('discard uncommitted changes (no backup)')), | 6210 [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
6057 ('c', 'check', None, _('require clean working directory')), | 6211 ('c', 'check', None, _('require clean working directory')), |
6058 ('m', 'merge', None, _('merge uncommitted changes')), | 6212 ('m', 'merge', None, _('merge uncommitted changes')), |
6059 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | 6213 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |