evolve: introduce function to create a obsmarker relation even for public cset
authorSushil khanchi <sushilkhanchi97@gmail.com>
Sun, 13 Jan 2019 19:33:19 +0530
changeset 4382 e6ba7e324015
parent 4381 5f1d0cff514d
child 4383 3343eac099ec
evolve: introduce function to create a obsmarker relation even for public cset To create obsmarkers we use obsolete.createmarkers() function, but because of security reasons this function refuses to create obsmarkers for public cset. And we need to create obsmarkers for a public cset while solving public content divergence. So introducing this function which create a obsmarker relation even for immutable cset. Currently this function create obsmarker for a single relation, in contrast of obsolete.createmarkers() which create markers for multiple relations. Upcoming pathces will be using this function.
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Tue Jan 29 20:45:14 2019 +0800
+++ b/hgext3rd/evolve/evolvecmd.py	Sun Jan 13 19:33:19 2019 +0530
@@ -18,6 +18,7 @@
     context,
     copies,
     error,
+    encoding,
     hg,
     merge,
     mergeutil,
@@ -579,6 +580,46 @@
     finally:
         repo.ui.restoreconfig(emtpycommitallowed)
 
+def bypassphase(repo, relation, flag=0, metadata=None, operation='evolve'):
+    """function to create a single obsmarker relation even for public csets
+    where relation should be a single pair (prec, succ)"""
+
+    # prepare metadata
+    if metadata is None:
+        metadata = {}
+    if 'user' not in metadata:
+        luser = repo.ui.config('devel', 'user.obsmarker') or repo.ui.username()
+        metadata['user'] = encoding.fromlocal(luser)
+    # Operation metadata handling
+    useoperation = repo.ui.configbool('experimental',
+                                      'evolution.track-operation')
+    if useoperation and operation:
+        metadata['operation'] = operation
+
+    # Effect flag metadata handling
+    saveeffectflag = repo.ui.configbool('experimental',
+                                        'evolution.effect-flags')
+    with repo.transaction('add-obsolescence-marker') as tr:
+        prec, succ = relation
+        nprec = prec.node()
+        npare = None
+        nsucs = [succ.node()]
+        if not nsucs:
+            npare = tuple(p.node() for p in prec.parents())
+        if nprec in nsucs:
+            raise error.Abort(_("changeset %s cannot obsolete itself") % prec)
+
+        if saveeffectflag:
+            # The effect flag is saved in a versioned field name for
+            # future evolution
+            effectflag = obsutil.geteffectflag(prec, (succ,))
+            metadata[obsutil.EFFECTFLAGFIELD] = "%d" % effectflag
+
+        # create markers
+        repo.obsstore.create(tr, nprec, nsucs, flag, parents=npare,
+                             metadata=metadata, ui=repo.ui)
+        repo.filteredrevcache.clear()
+
 def dirstatedance(repo, oldparent, newparent, match):
     """utility function to fix the dirstate when we change parents from
     oldparent to newparent with a directory working directory using