comparison hgext3rd/topic/__init__.py @ 2711:8c938e9af113

topics: wrap the update function to check if either t0 or b0 is passed as rev t0 or b0, seriously, what's that. Do they even exist? Hold on and look for the next commits what we are trying to do.
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 04 Jul 2017 00:15:36 +0530
parents 5d54de9cf50f
children f19b314d8475
comparison
equal deleted inserted replaced
2710:e22de367fc74 2711:8c938e9af113
174 entry[1].append(('t', 'topic', '', 174 entry[1].append(('t', 'topic', '',
175 _("use specified topic"), _('TOPIC'))) 175 _("use specified topic"), _('TOPIC')))
176 176
177 extensions.wrapfunction(cmdutil, 'buildcommittext', committextwrap) 177 extensions.wrapfunction(cmdutil, 'buildcommittext', committextwrap)
178 extensions.wrapfunction(merge, 'update', mergeupdatewrap) 178 extensions.wrapfunction(merge, 'update', mergeupdatewrap)
179 # We need to check whether t0 or b0 is passed to override the default update
180 # behaviour of changing topic and I can't find a better way
181 # to do that as scmutil.revsingle returns the rev number and hence we can't
182 # plug into logic for this into mergemod.update().
183 extensions.wrapcommand(commands.table, 'update', checkt0)
179 184
180 try: 185 try:
181 evolve = extensions.find('evolve') 186 evolve = extensions.find('evolve')
182 extensions.wrapfunction(evolve, "presplitupdate", presplitupdatetopic) 187 extensions.wrapfunction(evolve, "presplitupdate", presplitupdatetopic)
183 except (KeyError, AttributeError): 188 except (KeyError, AttributeError):
489 def mergeupdatewrap(orig, repo, node, branchmerge, force, *args, **kwargs): 494 def mergeupdatewrap(orig, repo, node, branchmerge, force, *args, **kwargs):
490 matcher = kwargs.get('matcher') 495 matcher = kwargs.get('matcher')
491 partial = not (matcher is None or matcher.always()) 496 partial = not (matcher is None or matcher.always())
492 wlock = repo.wlock() 497 wlock = repo.wlock()
493 isrebase = False 498 isrebase = False
499 ist0 = False
494 try: 500 try:
495 ret = orig(repo, node, branchmerge, force, *args, **kwargs) 501 ret = orig(repo, node, branchmerge, force, *args, **kwargs)
496 # The mergeupdatewrap function makes the destination's topic as the 502 # The mergeupdatewrap function makes the destination's topic as the
497 # current topic. This is right for merge but wrong for rebase. We check 503 # current topic. This is right for merge but wrong for rebase. We check
498 # if rebase is running and update the currenttopic to topic of new 504 # if rebase is running and update the currenttopic to topic of new
499 # rebased commit. We have explicitly stored in config if rebase is 505 # rebased commit. We have explicitly stored in config if rebase is
500 # running. 506 # running.
501 if repo.ui.hasconfig('experimental', 'topicrebase'): 507 if repo.ui.hasconfig('experimental', 'topicrebase'):
502 isrebase = True 508 isrebase = True
503 if (not partial and not branchmerge) or isrebase: 509 if repo.ui.configbool('_internal', 'updating-to-t0'):
510 ist0 = True
511 if ((not partial and not branchmerge) or isrebase) and not ist0:
504 ot = repo.currenttopic 512 ot = repo.currenttopic
505 t = '' 513 t = ''
506 pctx = repo[node] 514 pctx = repo[node]
507 if pctx.phase() > phases.public: 515 if pctx.phase() > phases.public:
508 t = pctx.topic() 516 t = pctx.topic()
509 with repo.vfs.open('topic', 'w') as f: 517 with repo.vfs.open('topic', 'w') as f:
510 f.write(t) 518 f.write(t)
511 if t and t != ot: 519 if t and t != ot:
512 repo.ui.status(_("switching to topic %s\n") % t) 520 repo.ui.status(_("switching to topic %s\n") % t)
521 elif ist0:
522 repo.ui.status(_("preserving the current topic '%s'\n") %
523 repo.currenttopic)
513 return ret 524 return ret
514 finally: 525 finally:
515 wlock.release() 526 wlock.release()
527
528 def checkt0(orig, ui, repo, node=None, rev=None, clean=False, date=None,
529 check=False, merge=None, tool=None):
530
531 thezeros = set(['t0', 'b0'])
532 overrides = {}
533 if node in thezeros or rev in thezeros:
534 overrides[('_internal', 'updating-to-t0')] = 'yes'
535 with repo.ui.configoverride(overrides, source='topic-extension'):
536 return orig(ui, repo, node, rev, clean, date, check, merge, tool)
516 537
517 def _fixrebase(loaded): 538 def _fixrebase(loaded):
518 if not loaded: 539 if not loaded:
519 return 540 return
520 541