obsolete: extract high level marker creation in a dedicated util function
This prepare the dooms of repo based method.
--- a/hgext/obsolete.py Tue Aug 07 16:02:50 2012 +0200
+++ b/hgext/obsolete.py Tue Aug 07 18:17:13 2012 +0200
@@ -557,6 +557,40 @@
newer.add(())
return sorted(newer)
+def createmarkers(repo, relations, metadata=None, flag=0):
+ """Add obsolete markers between changeset in a repo
+
+ <relations> must be an iterable of (<old>, (<new>, ...)) tuple.
+ `old` and `news` are changectx.
+
+ Current user and date are used except if specified otherwise in the
+ metadata attribute.
+
+ /!\ assume the repo have been locked byt the user /!\
+ """
+ # 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()
+ # check future marker
+ 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)
+ repo._clearobsoletecache()
+ tr.close()
+ finally:
+ tr.release()
+
@eh.reposetup
def _repoobsutilsetup(ui, repo):
if not repo.local():
@@ -567,31 +601,11 @@
# XXX kill me
def addobsolete(self, sub, obj):
"""Add a relation marking that node <sub> is a new version of <obj>"""
- assert sub != obj
- if not repo[obj].phase():
- if sub is None:
- self.ui.warn(
- _("trying to kill immutable changeset %(obj)s\n")
- % {'obj': short(obj)})
- if sub is not None:
- self.ui.warn(
- _("%(sub)s try to obsolete immutable changeset %(obj)s\n")
- % {'sub': short(sub), 'obj': short(obj)})
+ prec = repo[obj]
+ sucs = (sub == nullid) and [] or [repo[sub]]
lock = self.lock()
try:
- tr = self.transaction('add-obsolete')
- try:
- meta = {
- 'date': '%i %i' % util.makedate(),
- 'user': ui.username(),
- }
- subs = (sub == nullid) and [] or [sub]
- mid = self.obsstore.create(tr, obj, subs, 0, meta)
- tr.close()
- self._clearobsoletecache()
- return mid
- finally:
- tr.release()
+ createmarkers(self, [(prec, sucs)])
finally:
lock.release()