[PATCH 4 of 5] obsolete: add an high level function to create obsolete marker
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Fri Aug 24 19:18:02 UTC 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1345835783 -7200
# Node ID 717744d9dbd35812c5d29d2c0ecae6acca633338
# Parent 15d13d5ee05a0f68e84741d79f4ed386b644bfb3
obsolete: add an high level function to create obsolete marker
This function is designed to be used by all logic that create new obsolete marker
in the local repository.
It is not used by debugobsolete because debugobsolete allows unknown hash as
argument.
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -329,3 +329,39 @@
if suc not in seen:
seen.add(suc)
remaining.add(suc)
+
+def createmarkers(repo, relations, flag=0, metadata=None):
+ """Add obsolete markers between changeset in a repo
+
+ <relations> must be an iterable of (<old>, (<new>, ...)) tuple.
+ `old` and `news` are changectx.
+
+ Trying to obsolete public changeset will raise an exception.
+
+ Current user and date are used except if specified otherwise in the
+ metadata attribute.
+
+ This function operated within it's own transaction 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 himself" % prec)
+ repo.obsstore.create(tr, nprec, nsucs, flag, metadata)
+ tr.close()
+ finally:
+ tr.release()
More information about the Mercurial-devel
mailing list