# HG changeset patch # User Kostia Balytskyi # Date 1479036952 28800 # Node ID 2e736f01a710635c88db8bc8dc270058c07fae45 # Parent 932b18c95e114cd2dd73dbf401f6a4ddf94280ec shelve: move temporary commit creation to a separate function Committing working copy changes before rebasing a shelved commit on top of them is an independent piece of behavior, which fits into its own function. Similar to the previous series, this and a couple of following patches are for unshelve refactoring. diff -r 932b18c95e11 -r 2e736f01a710 hgext/shelve.py --- a/hgext/shelve.py Thu Nov 17 20:30:00 2016 -0800 +++ b/hgext/shelve.py Sun Nov 13 03:35:52 2016 -0800 @@ -630,6 +630,26 @@ unshelvecleanup(ui, repo, state.name, opts) ui.status(_("unshelve of '%s' complete\n") % state.name) +def _commitworkingcopychanges(ui, repo, opts, tmpwctx): + """Temporarily commit working copy changes before moving unshelve commit""" + # Store pending changes in a commit and remember added in case a shelve + # contains unknown files that are part of the pending change + s = repo.status() + addedbefore = frozenset(s.added) + if not (s.modified or s.added or s.removed or s.deleted): + return tmpwctx, addedbefore + ui.status(_("temporarily committing pending changes " + "(restore with 'hg unshelve --abort')\n")) + commitfunc = getcommitfunc(extra=None, interactive=False, + editor=False) + tempopts = {} + tempopts['message'] = "pending changes temporary commit" + tempopts['date'] = opts.get('date') + ui.quiet = True + node = cmdutil.commit(ui, repo, commitfunc, [], tempopts) + tmpwctx = repo[node] + return tmpwctx, addedbefore + @command('unshelve', [('a', 'abort', None, _('abort an incomplete unshelve operation')), @@ -752,21 +772,8 @@ # and shelvectx is the unshelved changes. Then we merge it all down # to the original pctx. - # Store pending changes in a commit and remember added in case a shelve - # contains unknown files that are part of the pending change - s = repo.status() - addedbefore = frozenset(s.added) - if s.modified or s.added or s.removed or s.deleted: - ui.status(_("temporarily committing pending changes " - "(restore with 'hg unshelve --abort')\n")) - commitfunc = getcommitfunc(extra=None, interactive=False, - editor=False) - tempopts = {} - tempopts['message'] = "pending changes temporary commit" - tempopts['date'] = opts.get('date') - ui.quiet = True - node = cmdutil.commit(ui, repo, commitfunc, [], tempopts) - tmpwctx = repo[node] + tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts, + tmpwctx) ui.quiet = True shelvedfile(repo, basename, 'hg').applybundle()