# HG changeset patch # User Pierre-Yves David # Date 1344368395 -7200 # Node ID 96c896f0180bfc26753b558f6dad3a07ba9ab0b3 # Parent fa85e7205e0bdfce85b08fd2dc1e14e4f2f750e3 obsolete: some more movement diff -r fa85e7205e0b -r 96c896f0180b hgext/obsolete.py --- a/hgext/obsolete.py Tue Aug 07 21:35:39 2012 +0200 +++ b/hgext/obsolete.py Tue Aug 07 21:39:55 2012 +0200 @@ -342,32 +342,6 @@ """the set of obsolete parent without non obsolete descendant""" return set(repo.revs('obsolete() - obsolete()::unstable()')) -@cachefor('latecomer') -def _computelatecomerset(repo): - """the set of rev trying to obsolete public revision""" - query = 'allsuccessors(public()) - obsolete() - public()' - return set(repo.revs(query)) - -@cachefor('conflicting') -def _computeconflictingset(repo): - """the set of rev trying to obsolete public revision""" - conflicting = set() - obsstore = repo.obsstore - newermap = {} - for ctx in repo.set('(not public()) - obsolete()'): - prec = obsstore.successors.get(ctx.node(), ()) - toprocess = set(prec) - while toprocess: - prec = toprocess.pop()[0] - if prec not in newermap: - newermap[prec] = newerversion(repo, prec) - newer = [n for n in newermap[prec] if n] # filter kill - if len(newer) > 1: - conflicting.add(ctx.rev()) - break - toprocess.update(obsstore.successors.get(prec, ())) - return conflicting - @eh.wrapfunction(obsolete.obsstore, '__init__') def _initobsstorecache(orig, obsstore, *args, **kwargs): """add a caches attributes to obsstore""" @@ -451,6 +425,32 @@ ### Complete troubles computation logic ### ##################################################################### +@cachefor('latecomer') +def _computelatecomerset(repo): + """the set of rev trying to obsolete public revision""" + query = 'allsuccessors(public()) - obsolete() - public()' + return set(repo.revs(query)) + +@cachefor('conflicting') +def _computeconflictingset(repo): + """the set of rev trying to obsolete public revision""" + conflicting = set() + obsstore = repo.obsstore + newermap = {} + for ctx in repo.set('(not public()) - obsolete()'): + prec = obsstore.successors.get(ctx.node(), ()) + toprocess = set(prec) + while toprocess: + prec = toprocess.pop()[0] + if prec not in newermap: + newermap[prec] = newerversion(repo, prec) + newer = [n for n in newermap[prec] if n] # filter kill + if len(newer) > 1: + conflicting.add(ctx.rev()) + break + toprocess.update(obsstore.successors.get(prec, ())) + return conflicting + @eh.addattr(context.changectx, 'latecomer') def latecomer(ctx): """is the changeset latecomer (Try to succeed to public change)""" @@ -465,6 +465,28 @@ return False return ctx.rev() in getobscache(ctx._repo, 'conflicting') +### Discovery wrapping + +@eh.wrapfunction(discovery, 'checkheads') +def wrapcheckheads(orig, repo, remote, outgoing, *args, **kwargs): + """wrap mercurial.discovery.checkheads + + * prevent unstability to be pushed + * patch remote to ignore obsolete heads on remote + """ + # do not push instability + for h in outgoing.missingheads: + # Checking heads is enough, obsolete descendants are either + # obsolete or unstable. + ctx = repo[h] + if ctx.latecomer(): + raise util.Abort(_("push includes a latecomer changeset: %s!") + % ctx) + if ctx.conflicting(): + raise util.Abort(_("push includes a conflicting changeset: %s!") + % ctx) + return orig(repo, remote, outgoing, *args, **kwargs) + ##################################################################### ### Additional Utilities ### @@ -707,27 +729,6 @@ ##################################################################### -### Discovery wrapping - -@eh.wrapfunction(discovery, 'checkheads') -def wrapcheckheads(orig, repo, remote, outgoing, *args, **kwargs): - """wrap mercurial.discovery.checkheads - - * prevent unstability to be pushed - * patch remote to ignore obsolete heads on remote - """ - # do not push instability - for h in outgoing.missingheads: - # Checking heads is enough, obsolete descendants are either - # obsolete or unstable. - ctx = repo[h] - if ctx.latecomer(): - raise util.Abort(_("push includes a latecomer changeset: %s!") - % ctx) - if ctx.conflicting(): - raise util.Abort(_("push includes a conflicting changeset: %s!") - % ctx) - return orig(repo, remote, outgoing, *args, **kwargs) @eh.wrapcommand("update") @eh.wrapcommand("pull")