hgext/obsolete.py
changeset 359 43f79983f638
parent 353 8feb73f733cb
parent 356 56d4c6207ef9
child 360 6390ab3aea93
equal deleted inserted replaced
353:8feb73f733cb 359:43f79983f638
   149         return False
   149         return False
   150     return ctx.rev() in ctx._repo._latecomerset
   150     return ctx.rev() in ctx._repo._latecomerset
   151 
   151 
   152 context.changectx.latecomer = latecomer
   152 context.changectx.latecomer = latecomer
   153 
   153 
       
   154 def conflicting(ctx):
       
   155     """is the changeset conflicting (Try to succeed to public change)"""
       
   156     if ctx.node() is None:
       
   157         return False
       
   158     return ctx.rev() in ctx._repo._conflictingset
       
   159 
       
   160 context.changectx.conflicting = conflicting
       
   161 
   154 
   162 
   155 ### revset
   163 ### revset
   156 #############################
   164 #############################
   157 
   165 
   158 def revsethidden(repo, subset, x):
   166 def revsethidden(repo, subset, x):
   189 
   197 
   190 def revsetlatecomer(repo, subset, x):
   198 def revsetlatecomer(repo, subset, x):
   191     """latecomer, Try to succeed to public change"""
   199     """latecomer, Try to succeed to public change"""
   192     args = revset.getargs(x, 0, 0, 'latecomer takes no arguments')
   200     args = revset.getargs(x, 0, 0, 'latecomer takes no arguments')
   193     return [r for r in subset if r in repo._latecomerset]
   201     return [r for r in subset if r in repo._latecomerset]
       
   202 
       
   203 def revsetconflicting(repo, subset, x):
       
   204     """conflicting, Try to succeed to public change"""
       
   205     args = revset.getargs(x, 0, 0, 'conflicting takes no arguments')
       
   206     return [r for r in subset if r in repo._conflictingset]
   194 
   207 
   195 def _precursors(repo, s):
   208 def _precursors(repo, s):
   196     """Precursor of a changeset"""
   209     """Precursor of a changeset"""
   197     cs = set()
   210     cs = set()
   198     nm = repo.changelog.nodemap
   211     nm = repo.changelog.nodemap
   388     revset.symbols["obsolete"] = revsetobsolete
   401     revset.symbols["obsolete"] = revsetobsolete
   389     revset.symbols["unstable"] = revsetunstable
   402     revset.symbols["unstable"] = revsetunstable
   390     revset.symbols["suspended"] = revsetsuspended
   403     revset.symbols["suspended"] = revsetsuspended
   391     revset.symbols["extinct"] = revsetextinct
   404     revset.symbols["extinct"] = revsetextinct
   392     revset.symbols["latecomer"] = revsetlatecomer
   405     revset.symbols["latecomer"] = revsetlatecomer
       
   406     revset.symbols["conflicting"] = revsetconflicting
   393     revset.symbols["obsparents"] = revsetprecursors  # DEPR
   407     revset.symbols["obsparents"] = revsetprecursors  # DEPR
   394     revset.symbols["precursors"] = revsetprecursors
   408     revset.symbols["precursors"] = revsetprecursors
   395     revset.symbols["obsancestors"] = revsetallprecursors  # DEPR
   409     revset.symbols["obsancestors"] = revsetallprecursors  # DEPR
   396     revset.symbols["allprecursors"] = revsetallprecursors  # bad name
   410     revset.symbols["allprecursors"] = revsetallprecursors  # bad name
   397     revset.symbols["successors"] = revsetsuccessors
   411     revset.symbols["successors"] = revsetsuccessors
   398     revset.symbols["allsuccessors"] = revsetallsuccessors  # bad name
   412     revset.symbols["allsuccessors"] = revsetallsuccessors  # bad name
   399 
   413 
   400     templatekw.keywords['obsolete'] = obsoletekw
   414     templatekw.keywords['obsolete'] = obsoletekw
   401 
   415 
       
   416     # warning about more obsolete
       
   417     for cmd in ['commit', 'push', 'pull', 'graft', 'phase', 'unbundle']:
       
   418         entry = extensions.wrapcommand(commands.table, cmd, warnobserrors)
   402     try:
   419     try:
   403         rebase = extensions.find('rebase')
   420         rebase = extensions.find('rebase')
   404         if rebase:
   421         if rebase:
       
   422             entry = extensions.wrapcommand(rebase.cmdtable, 'rebase', warnobserrors)
   405             extensions.wrapfunction(rebase, 'buildstate', buildstate)
   423             extensions.wrapfunction(rebase, 'buildstate', buildstate)
   406             extensions.wrapfunction(rebase, 'defineparents', defineparents)
   424             extensions.wrapfunction(rebase, 'defineparents', defineparents)
   407             extensions.wrapfunction(rebase, 'concludenode', concludenode)
   425             extensions.wrapfunction(rebase, 'concludenode', concludenode)
   408             extensions.wrapcommand(rebase.cmdtable, "rebase", cmdrebase)
   426             extensions.wrapcommand(rebase.cmdtable, "rebase", cmdrebase)
   409     except KeyError:
   427     except KeyError:
   451         if ctx.obsolete():
   469         if ctx.obsolete():
   452             raise util.Abort(_("Trying to push obsolete changeset: %s!") % ctx,
   470             raise util.Abort(_("Trying to push obsolete changeset: %s!") % ctx,
   453                              hint=hint)
   471                              hint=hint)
   454         if ctx.latecomer():
   472         if ctx.latecomer():
   455             raise util.Abort(_("Trying to push latecomer changeset: %s!") % ctx,
   473             raise util.Abort(_("Trying to push latecomer changeset: %s!") % ctx,
       
   474                              hint=hint)
       
   475         if ctx.conflicting():
       
   476             raise util.Abort(_("Trying to push conflicting changeset: %s!") % ctx,
   456                              hint=hint)
   477                              hint=hint)
   457     ### patch remote branch map
   478     ### patch remote branch map
   458     # do not read it this burn eyes
   479     # do not read it this burn eyes
   459     try:
   480     try:
   460         if 'oldbranchmap' not in vars(remote):
   481         if 'oldbranchmap' not in vars(remote):
   638         repo._turn_extinct_secret()
   659         repo._turn_extinct_secret()
   639     finally:
   660     finally:
   640         lock.release()
   661         lock.release()
   641     return res
   662     return res
   642 
   663 
       
   664 def warnobserrors(orig, ui, repo, *args, **kwargs):
       
   665     """display warning is the command resulted in more instable changeset"""
       
   666     priorunstables = len(repo.revs('unstable()'))
       
   667     priorlatecomers = len(repo.revs('latecomer()'))
       
   668     priorconflictings = len(repo.revs('conflicting()'))
       
   669     #print orig, priorunstables
       
   670     #print len(repo.revs('secret() - obsolete()'))
       
   671     try:
       
   672         return orig(ui, repo, *args, **kwargs)
       
   673     finally:
       
   674         newunstables = len(repo.revs('unstable()')) - priorunstables
       
   675         newlatecomers = len(repo.revs('latecomer()')) - priorlatecomers
       
   676         newconflictings = len(repo.revs('conflicting()')) - priorconflictings
       
   677         #print orig, newunstables
       
   678         #print len(repo.revs('secret() - obsolete()'))
       
   679         if newunstables > 0:
       
   680             ui.warn(_('%i new unstables changesets\n') % newunstables)
       
   681         if newlatecomers > 0:
       
   682             ui.warn(_('%i new latecomers changesets\n') % newlatecomers)
       
   683         if newconflictings > 0:
       
   684             ui.warn(_('%i new conflictings changesets\n') % newconflictings)
       
   685 
   643 def noextinctsvisibleheads(orig, repo):
   686 def noextinctsvisibleheads(orig, repo):
   644     repo._turn_extinct_secret()
   687     repo._turn_extinct_secret()
   645     return orig(repo)
   688     return orig(repo)
   646 
   689 
   647 def wrapcmdutilamend(orig, ui, repo, commitfunc, old, *args, **kwargs):
   690 def wrapcmdutilamend(orig, ui, repo, commitfunc, old, *args, **kwargs):
   804         def _latecomerset(self):
   847         def _latecomerset(self):
   805             """the set of rev trying to obsolete public revision"""
   848             """the set of rev trying to obsolete public revision"""
   806             query = 'allsuccessors(public()) - obsolete() - public()'
   849             query = 'allsuccessors(public()) - obsolete() - public()'
   807             return set(self.revs(query))
   850             return set(self.revs(query))
   808 
   851 
       
   852         @util.propertycache
       
   853         def _conflictingset(self):
       
   854             """the set of rev trying to obsolete public revision"""
       
   855             conflicting = set()
       
   856             obsstore = self.obsstore
       
   857             newermap = {}
       
   858             for ctx in self.set('(not public()) - obsolete()'):
       
   859                 prec = obsstore.successors.get(ctx.node(), ())
       
   860                 toprocess = set(prec)
       
   861                 while toprocess:
       
   862                     prec = toprocess.pop()[0]
       
   863                     if prec not in newermap:
       
   864                         newermap[prec] = newerversion(self, prec)
       
   865                     newer = [n for n in newermap[prec] if n] # filter kill
       
   866                     if len(newer) > 1:
       
   867                         conflicting.add(ctx.rev())
       
   868                         break
       
   869                 toprocess.update(obsstore.successors.get(prec, ()))
       
   870             return conflicting
       
   871 
   809         def _clearobsoletecache(self):
   872         def _clearobsoletecache(self):
   810             if '_obsoleteset' in vars(self):
   873             if '_obsoleteset' in vars(self):
   811                 del self._obsoleteset
   874                 del self._obsoleteset
   812             self._clearunstablecache()
   875             self._clearunstablecache()
   813 
   876 
   822                 del self._suspendedset
   885                 del self._suspendedset
   823             if '_extinctset' in vars(self):
   886             if '_extinctset' in vars(self):
   824                 del self._extinctset
   887                 del self._extinctset
   825             if '_latecomerset' in vars(self):
   888             if '_latecomerset' in vars(self):
   826                 del self._latecomerset
   889                 del self._latecomerset
       
   890             if '_conflictingset' in vars(self):
       
   891                 del self._conflictingset
   827 
   892 
   828         def addobsolete(self, sub, obj):
   893         def addobsolete(self, sub, obj):
   829             """Add a relation marking that node <sub> is a new version of <obj>"""
   894             """Add a relation marking that node <sub> is a new version of <obj>"""
   830             assert sub != obj
   895             assert sub != obj
   831             if not repo[obj].phase():
   896             if not repo[obj].phase():