topic: fix up change logic a little and add debug logging
frommercurialimporterrorfrommercurialimportutilfrommercurialimportdestutilfrommercurialimportextensionsfrommercurial.i18nimport_def_destmergebranch(orig,repo):p1=repo['.']top=p1.topic()iftop:heads=repo.revs('heads(topic(.)::topic(.))')ifp1.rev()notinheads:raiseerror.Abort(_("not at topic head, update or explicit"))elif1==len(heads):# should look at all branch involved but... laterbhead=ngtip(repo,p1.branch(),all=True)ifnotbhead:raiseerror.Abort(_("nothing to merge"))elif1==len(bhead):returnbhead.first()else:raiseerror.Abort(_("branch '%s' has %d heads - ""please merge with an explicit rev")%(p1.branch(),len(bhead)),hint=_("run 'hg heads .' to see heads"))elif2==len(heads):heads=[rforrinheadsifr!=p1.rev()]# XXX: bla bla bla bla blaif1<len(heads):raiseerror.Abort(_('working directory not at a head revision'),hint=_("use 'hg update' or merge with an ""explicit revision"))returnheads[0]elif2<len(heads):raiseerror.Abort(_("topic '%s' has %d heads - ""please merge with an explicit rev")%(top,len(heads)))else:assertFalse# that's impossiblereturnorig(repo)defsetupdest():ifutil.safehasattr(destutil,'_destmergebranch'):extensions.wrapfunction(destutil,'_destmergebranch',_destmergebranch)defngtip(repo,branch,all=False):"""tip new generation"""## search for untopiced heads of branch# could be heads((::branch(x) - topic()))# but that is expensive## we should write plain code insteadsubquery='''heads( parents( ancestor( (head() and branch(%s) or (topic() and branch(%s))))) ::(head() and branch(%s)) - topic())'''ifnotall:subquery='max(%s)'%subqueryreturnrepo.revs(subquery,branch,branch,branch)