# HG changeset patch # User Pierre-Yves David # Date 1345835783 -7200 # Node ID f85816af62943e435235812f2d37c900428e6d17 # Parent 9732473aa24bff5696f8bd761b546022ee4f6e2b obsolete: add a high level function to create an obsolete marker This function is designed to be used by all code that creates new obsolete markers in the local repository. It is not used by debugobsolete because debugobsolete allows the use of an unknown hash as argument. diff -r 9732473aa24b -r f85816af6294 mercurial/obsolete.py --- a/mercurial/obsolete.py Sat Aug 25 16:20:41 2012 +0200 +++ b/mercurial/obsolete.py Fri Aug 24 21:16:23 2012 +0200 @@ -395,3 +395,39 @@ def _computeextinctset(repo): """the set of obsolete parents without non obsolete descendants""" return set(repo.revs('obsolete() - obsolete()::unstable()')) + +def createmarkers(repo, relations, flag=0, metadata=None): + """Add obsolete markers between changesets in a repo + + must be an iterable of (, (, ...)) tuple. + `old` and `news` are changectx. + + Trying to obsolete a public changeset will raise an exception. + + Current user and date are used except if specified otherwise in the + metadata attribute. + + This function operates within a transaction of its own, but does + not take any lock on the repo. + """ + # prepare metadata + if metadata is None: + metadata = {} + if 'date' not in metadata: + metadata['date'] = '%i %i' % util.makedate() + if 'user' not in metadata: + metadata['user'] = repo.ui.username() + tr = repo.transaction('add-obsolescence-marker') + try: + for prec, sucs in relations: + if not prec.mutable(): + raise util.Abort("cannot obsolete immutable changeset: %s" + % prec) + nprec = prec.node() + nsucs = tuple(s.node() for s in sucs) + if nprec in nsucs: + raise util.Abort("changeset %s cannot obsolete itself" % prec) + repo.obsstore.create(tr, nprec, nsucs, flag, metadata) + tr.close() + finally: + tr.release()