Show More
@@ -28,6 +28,7 import itertools | |||
|
28 | 28 | |
|
29 | 29 | from mercurial.i18n import _ |
|
30 | 30 | from mercurial import ( |
|
31 | bookmarks, | |
|
31 | 32 | bundle2, |
|
32 | 33 | bundlerepo, |
|
33 | 34 | changegroup, |
@@ -170,6 +171,8 class shelvedstate(object): | |||
|
170 | 171 | _filename = 'shelvedstate' |
|
171 | 172 | _keep = 'keep' |
|
172 | 173 | _nokeep = 'nokeep' |
|
174 | # colon is essential to differentiate from a real bookmark name | |
|
175 | _noactivebook = ':no-active-bookmark' | |
|
173 | 176 | |
|
174 | 177 | @classmethod |
|
175 | 178 | def load(cls, repo): |
@@ -187,6 +190,7 class shelvedstate(object): | |||
|
187 | 190 | nodestoprune = [nodemod.bin(h) for h in fp.readline().split()] |
|
188 | 191 | branchtorestore = fp.readline().strip() |
|
189 | 192 | keep = fp.readline().strip() == cls._keep |
|
193 | activebook = fp.readline().strip() | |
|
190 | 194 | except (ValueError, TypeError) as err: |
|
191 | 195 | raise error.CorruptedState(str(err)) |
|
192 | 196 | finally: |
@@ -201,6 +205,9 class shelvedstate(object): | |||
|
201 | 205 | obj.nodestoprune = nodestoprune |
|
202 | 206 | obj.branchtorestore = branchtorestore |
|
203 | 207 | obj.keep = keep |
|
208 | obj.activebookmark = '' | |
|
209 | if activebook != cls._noactivebook: | |
|
210 | obj.activebookmark = activebook | |
|
204 | 211 | except error.RepoLookupError as err: |
|
205 | 212 | raise error.CorruptedState(str(err)) |
|
206 | 213 | |
@@ -208,7 +215,7 class shelvedstate(object): | |||
|
208 | 215 | |
|
209 | 216 | @classmethod |
|
210 | 217 | def save(cls, repo, name, originalwctx, pendingctx, nodestoprune, |
|
211 | branchtorestore, keep=False): | |
|
218 | branchtorestore, keep=False, activebook=''): | |
|
212 | 219 | fp = repo.vfs(cls._filename, 'wb') |
|
213 | 220 | fp.write('%i\n' % cls._version) |
|
214 | 221 | fp.write('%s\n' % name) |
@@ -220,6 +227,7 class shelvedstate(object): | |||
|
220 | 227 | ' '.join([nodemod.hex(n) for n in nodestoprune])) |
|
221 | 228 | fp.write('%s\n' % branchtorestore) |
|
222 | 229 | fp.write('%s\n' % (cls._keep if keep else cls._nokeep)) |
|
230 | fp.write('%s\n' % (activebook or cls._noactivebook)) | |
|
223 | 231 | fp.close() |
|
224 | 232 | |
|
225 | 233 | @classmethod |
@@ -244,6 +252,16 def cleanupoldbackups(repo): | |||
|
244 | 252 | for ext in shelvefileextensions: |
|
245 | 253 | vfs.tryunlink(base + '.' + ext) |
|
246 | 254 | |
|
255 | def _backupactivebookmark(repo): | |
|
256 | activebookmark = repo._activebookmark | |
|
257 | if activebookmark: | |
|
258 | bookmarks.deactivate(repo) | |
|
259 | return activebookmark | |
|
260 | ||
|
261 | def _restoreactivebookmark(repo, mark): | |
|
262 | if mark: | |
|
263 | bookmarks.activate(repo, mark) | |
|
264 | ||
|
247 | 265 | def _aborttransaction(repo): |
|
248 | 266 | '''Abort current transaction for shelve/unshelve, but keep dirstate |
|
249 | 267 | ''' |
@@ -377,7 +395,7 def _docreatecmd(ui, repo, pats, opts): | |||
|
377 | 395 | if not opts.get('message'): |
|
378 | 396 | opts['message'] = desc |
|
379 | 397 | |
|
380 | lock = tr = None | |
|
398 | lock = tr = activebookmark = None | |
|
381 | 399 | try: |
|
382 | 400 | lock = repo.lock() |
|
383 | 401 | |
@@ -390,6 +408,7 def _docreatecmd(ui, repo, pats, opts): | |||
|
390 | 408 | not opts.get('addremove', False)) |
|
391 | 409 | |
|
392 | 410 | name = getshelvename(repo, parent, opts) |
|
411 | activebookmark = _backupactivebookmark(repo) | |
|
393 | 412 | extra = {} |
|
394 | 413 | if includeunknown: |
|
395 | 414 | _includeunknownfiles(repo, pats, opts, extra) |
@@ -404,7 +423,8 def _docreatecmd(ui, repo, pats, opts): | |||
|
404 | 423 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
405 | 424 | else: |
|
406 | 425 | node = cmdutil.dorecord(ui, repo, commitfunc, None, |
|
407 |
False, cmdutil.recordfilter, *pats, |
|
|
426 | False, cmdutil.recordfilter, *pats, | |
|
427 | **opts) | |
|
408 | 428 | if not node: |
|
409 | 429 | _nothingtoshelvemessaging(ui, repo, pats, opts) |
|
410 | 430 | return 1 |
@@ -420,6 +440,7 def _docreatecmd(ui, repo, pats, opts): | |||
|
420 | 440 | |
|
421 | 441 | _finishshelve(repo) |
|
422 | 442 | finally: |
|
443 | _restoreactivebookmark(repo, activebookmark) | |
|
423 | 444 | lockmod.release(tr, lock) |
|
424 | 445 | |
|
425 | 446 | def _isbareshelve(pats, opts): |
@@ -639,6 +660,7 def unshelvecontinue(ui, repo, state, op | |||
|
639 | 660 | restorebranch(ui, repo, state.branchtorestore) |
|
640 | 661 | |
|
641 | 662 | repair.strip(ui, repo, state.nodestoprune, backup=False, topic='shelve') |
|
663 | _restoreactivebookmark(repo, state.activebookmark) | |
|
642 | 664 | shelvedstate.clear(repo) |
|
643 | 665 | unshelvecleanup(ui, repo, state.name, opts) |
|
644 | 666 | ui.status(_("unshelve of '%s' complete\n") % state.name) |
@@ -672,7 +694,8 def _unshelverestorecommit(ui, repo, bas | |||
|
672 | 694 | return repo, shelvectx |
|
673 | 695 | |
|
674 | 696 | def _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, basename, pctx, |
|
675 |
tmpwctx, shelvectx, branchtorestore |
|
|
697 | tmpwctx, shelvectx, branchtorestore, | |
|
698 | activebookmark): | |
|
676 | 699 | """Rebase restored commit from its original location to a destination""" |
|
677 | 700 | # If the shelve is not immediately on top of the commit |
|
678 | 701 | # we'll be merging with, rebase it to be on top. |
@@ -693,7 +716,7 def _rebaserestoredcommit(ui, repo, opts | |||
|
693 | 716 | nodestoprune = [repo.changelog.node(rev) |
|
694 | 717 | for rev in xrange(oldtiprev, len(repo))] |
|
695 | 718 | shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoprune, |
|
696 | branchtorestore, opts.get('keep')) | |
|
719 | branchtorestore, opts.get('keep'), activebookmark) | |
|
697 | 720 | |
|
698 | 721 | repo.vfs.rename('rebasestate', 'unshelverebasestate') |
|
699 | 722 | raise error.InterventionRequired( |
@@ -719,7 +742,8 def _forgetunknownfiles(repo, shelvectx, | |||
|
719 | 742 | toforget = (addedafter & shelveunknown) - addedbefore |
|
720 | 743 | repo[None].forget(toforget) |
|
721 | 744 | |
|
722 | def _finishunshelve(repo, oldtiprev, tr): | |
|
745 | def _finishunshelve(repo, oldtiprev, tr, activebookmark): | |
|
746 | _restoreactivebookmark(repo, activebookmark) | |
|
723 | 747 | # The transaction aborting will strip all the commits for us, |
|
724 | 748 | # but it doesn't update the inmemory structures, so addchangegroup |
|
725 | 749 | # hooks still fire and try to operate on the missing commits. |
@@ -865,6 +889,7 def _dounshelve(ui, repo, *shelved, **op | |||
|
865 | 889 | # and shelvectx is the unshelved changes. Then we merge it all down |
|
866 | 890 | # to the original pctx. |
|
867 | 891 | |
|
892 | activebookmark = _backupactivebookmark(repo) | |
|
868 | 893 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
|
869 | 894 | with ui.configoverride(overrides, 'unshelve'): |
|
870 | 895 | tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts, |
@@ -879,13 +904,14 def _dounshelve(ui, repo, *shelved, **op | |||
|
879 | 904 | |
|
880 | 905 | shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, |
|
881 | 906 | basename, pctx, tmpwctx, |
|
882 |
shelvectx, branchtorestore |
|
|
907 | shelvectx, branchtorestore, | |
|
908 | activebookmark) | |
|
883 | 909 | mergefiles(ui, repo, pctx, shelvectx) |
|
884 | 910 | restorebranch(ui, repo, branchtorestore) |
|
885 | 911 | _forgetunknownfiles(repo, shelvectx, addedbefore) |
|
886 | 912 | |
|
887 | 913 | shelvedstate.clear(repo) |
|
888 | _finishunshelve(repo, oldtiprev, tr) | |
|
914 | _finishunshelve(repo, oldtiprev, tr, activebookmark) | |
|
889 | 915 | unshelvecleanup(ui, repo, basename, opts) |
|
890 | 916 | finally: |
|
891 | 917 | ui.quiet = oldquiet |
General Comments 0
You need to be logged in to leave comments.
Login now