##// END OF EJS Templates
shelve: move commitfunc creation to a separate function...
Kostia Balytskyi -
r30381:caba6193 default
parent child Browse files
Show More
@@ -64,6 +64,10 b" backupdir = 'shelve-backup'"
64 64 shelvedir = 'shelved'
65 65 shelvefileextensions = ['hg', 'patch']
66 66
67 # we never need the user, so we use a
68 # generic user for all shelve operations
69 shelveuser = 'shelve@localhost'
70
67 71 class shelvedfile(object):
68 72 """Helper for the file storing a single shelve
69 73
@@ -290,6 +294,32 b' def mutableancestors(ctx):'
290 294 if parent.mutable():
291 295 visit.append(parent)
292 296
297 def getcommitfunc(extra, interactive, editor=False):
298 def commitfunc(ui, repo, message, match, opts):
299 hasmq = util.safehasattr(repo, 'mq')
300 if hasmq:
301 saved, repo.mq.checkapplied = repo.mq.checkapplied, False
302 backup = repo.ui.backupconfig('phases', 'new-commit')
303 try:
304 repo.ui.setconfig('phases', 'new-commit', phases.secret)
305 editor_ = False
306 if editor:
307 editor_ = cmdutil.getcommiteditor(editform='shelve.shelve',
308 **opts)
309 return repo.commit(message, shelveuser, opts.get('date'), match,
310 editor=editor_, extra=extra)
311 finally:
312 repo.ui.restoreconfig(backup)
313 if hasmq:
314 repo.mq.checkapplied = saved
315
316 def interactivecommitfunc(ui, repo, *pats, **opts):
317 match = scmutil.match(repo['.'], pats, {})
318 message = opts['message']
319 return commitfunc(ui, repo, message, match, opts)
320
321 return interactivecommitfunc if interactive else commitfunc
322
293 323 def _docreatecmd(ui, repo, pats, opts):
294 324 wctx = repo[None]
295 325 parents = wctx.parents()
@@ -298,9 +328,6 b' def _docreatecmd(ui, repo, pats, opts):'
298 328 parent = parents[0]
299 329 origbranch = wctx.branch()
300 330
301 # we never need the user, so we use a generic user for all shelve operations
302 user = 'shelve@localhost'
303
304 331 if parent.node() != nodemod.nullid:
305 332 desc = "changes to: %s" % parent.description().split('\n', 1)[0]
306 333 else:
@@ -335,30 +362,11 b' def _docreatecmd(ui, repo, pats, opts):'
335 362 # at bundled commit
336 363 repo.dirstate.setbranch(repo['.'].branch())
337 364
338 def commitfunc(ui, repo, message, match, opts):
339 hasmq = util.safehasattr(repo, 'mq')
340 if hasmq:
341 saved, repo.mq.checkapplied = repo.mq.checkapplied, False
342 backup = repo.ui.backupconfig('phases', 'new-commit')
343 try:
344 repo.ui. setconfig('phases', 'new-commit', phases.secret)
345 editor = cmdutil.getcommiteditor(editform='shelve.shelve',
346 **opts)
347 return repo.commit(message, user, opts.get('date'), match,
348 editor=editor, extra=extra)
349 finally:
350 repo.ui.restoreconfig(backup)
351 if hasmq:
352 repo.mq.checkapplied = saved
353
354 def interactivecommitfunc(ui, repo, *pats, **opts):
355 match = scmutil.match(repo['.'], pats, {})
356 message = opts['message']
357 return commitfunc(ui, repo, message, match, opts)
365 commitfunc = getcommitfunc(extra, interactive, editor=True)
358 366 if not interactive:
359 367 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
360 368 else:
361 node = cmdutil.dorecord(ui, repo, interactivecommitfunc, None,
369 node = cmdutil.dorecord(ui, repo, commitfunc, None,
362 370 False, cmdutil.recordfilter, *pats, **opts)
363 371 if not node:
364 372 stat = repo.status(match=scmutil.match(repo[None], pats, opts))
@@ -741,21 +749,8 b' def _dounshelve(ui, repo, *shelved, **op'
741 749 if s.modified or s.added or s.removed or s.deleted:
742 750 ui.status(_("temporarily committing pending changes "
743 751 "(restore with 'hg unshelve --abort')\n"))
744 def commitfunc(ui, repo, message, match, opts):
745 hasmq = util.safehasattr(repo, 'mq')
746 if hasmq:
747 saved, repo.mq.checkapplied = repo.mq.checkapplied, False
748
749 backup = repo.ui.backupconfig('phases', 'new-commit')
750 try:
751 repo.ui.setconfig('phases', 'new-commit', phases.secret)
752 return repo.commit(message, 'shelve@localhost',
753 opts.get('date'), match)
754 finally:
755 repo.ui.restoreconfig(backup)
756 if hasmq:
757 repo.mq.checkapplied = saved
758
752 commitfunc = getcommitfunc(extra=None, interactive=False,
753 editor=False)
759 754 tempopts = {}
760 755 tempopts['message'] = "pending changes temporary commit"
761 756 tempopts['date'] = opts.get('date')
General Comments 0
You need to be logged in to leave comments. Login now