obsolete: add a high level function to create an obsolete marker
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Fri, 24 Aug 2012 21:16:23 +0200
changeset 17474 f85816af6294
parent 17473 9732473aa24b
child 17475 63e45aee46d4
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.
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
+
+    <relations> must be an iterable of (<old>, (<new>, ...)) 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()