rewriteutil: add utility function to check if we can create new unstable cset
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 24 Nov 2017 03:40:33 +0530
changeset 35242 27d5c2d2db2b
parent 35241 2a99c5bfea47
child 35243 490df753894d
rewriteutil: add utility function to check if we can create new unstable cset This patch adds a new file which will contain utility functions related to rewritting changesets. It also adds a utility function to check if the rewritting operation creates new unstable changesets and are we allowed to create them. This rewriteutil.py introduced in this patch and the utility functions added in the upcoming patches exists in the evolve extension are being ported from there. Differential Revision: https://phab.mercurial-scm.org/D1502
mercurial/rewriteutil.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/rewriteutil.py	Fri Nov 24 03:40:33 2017 +0530
@@ -0,0 +1,25 @@
+# rewriteutil.py - utility functions for rewriting changesets
+#
+# Copyright 2017 Octobus <contact@octobus.net>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+from . import (
+    obsolete,
+    revset,
+)
+
+def disallowednewunstable(repo, revs):
+    """Checks whether editing the revs will create new unstable changesets and
+    are we allowed to create them.
+
+    To allow new unstable changesets, set the config:
+        `experimental.evolution.allowunstable=True`
+    """
+    allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
+    if allowunstable:
+        return revset.baseset()
+    return repo.revs("(%ld::) - %ld", revs, revs)