[PATCH 2 of 2] createmarkers: allow to pass metadata for a marker only

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Fri Feb 14 17:47:53 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1392341649 28800
#      Thu Feb 13 17:34:09 2014 -0800
# Node ID 9e01ab2a3ba9cd5df2bb3da8efa28df92e7b5ab5
# Parent  1bfd796fc968827d75b20abb7ef9d8d27d7d8e68
createmarkers: allow to pass metadata for a marker only

The `metadata` argument only allow to specify metadata for all new markers. We
extension the format of the `relations` argument to support optional metadata
argument.

The first user of this should be the evolve extension who want to store parent
information of pruned changeset in extra (until we make a second version of the
format)

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -809,12 +809,14 @@ def _computedivergentset(repo):
 
 
 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.
+    <relations> must be an iterable of (<old>, (<new>, ...)[,{metadata}])
+    tuple. `old` and `news` are changectx. metadata is an optional dictionnary
+    containing metadata for this marker only. It is merged with the global
+    metadata specified through the `metadata` argument of this function,
 
     Trying to obsolete a public changeset will raise an exception.
 
     Current user and date are used except if specified otherwise in the
     metadata attribute.
@@ -829,18 +831,24 @@ def createmarkers(repo, relations, flag=
         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:
+        for rel in relations:
+            prec = rel[0]
+            sucs = rel[1]
+            localmetadata = metadata.copy()
+            if 2 < len(rel):
+                localmetadata.update(rel[2])
+
             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)
+            repo.obsstore.create(tr, nprec, nsucs, flag, localmetadata)
             repo.filteredrevcache.clear()
         tr.close()
     finally:
         tr.release()


More information about the Mercurial-devel mailing list