[PATCH 04 of 10 RFC v2] compat: module to handle different ui.compat settings

David Soria Parra davidsp at fb.com
Sun Mar 12 18:40:27 EDT 2017


# HG changeset patch
# User David Soria Parra <davidsp at fb.com>
# Date 1489349206 25200
#      Sun Mar 12 13:06:46 2017 -0700
# Node ID 0986fb7be0f584f5169f93377f9d013f87381ea7
# Parent  ef5ce5325596fe5fef014a320abae0f0d5980f3d
compat: module to handle different ui.compat settings

We are introducing ui.compat. It defaults to 'compat' which means Mercurial is
supposed to behave backwards compatible. At the moment it supports another mode
called 'latest' which can enable bc-breaking configurations to change the
default behavior of commands. The layer provides an ordered list of
compatibility levels and returns a combined list of configurations up to a given
compatibility level. For example, given settings 'compat', 'hg4.2',
'hg4.3', 'latest', a request for 'hg4.3' will return the combined settings for
'compat', 'hg4.2' and 'hg4.3' with later levels overwrriten existing
configurations.

diff --git a/mercurial/compat.py b/mercurial/compat.py
new file mode 100644
--- /dev/null
+++ b/mercurial/compat.py
@@ -0,0 +1,40 @@
+# compat.py - handlign compatibility settings
+#
+# Copyright 2005-2017 Mercurial Steering Committee
+#
+# 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
+
+import collections
+from . import (
+    util,
+)
+
+# The initialization msut be done with a list and not a dict, as a list
+# is sorted while a dictionary is not.
+COMPAT = util.sortdict([
+    ('compat', {}),
+    ('latest', {})],
+)
+
+def modernize(ui):
+    compats = compatlevel(ui)
+    for section, d in compats.items():
+        for key, value in d.items():
+            ui._cfg['defaults'].set(section, key, value)
+
+def compatlevel(ui):
+    if ui.plain('compat'):
+        requested = 'compat'
+    else:
+        requested = ui.config('ui', 'compat', 'compat')
+
+    result = {}
+    for level, configs in COMPAT.items():
+        result.update(configs)
+        if level == requested:
+            # defaults is sorted. We can abort once we reached
+            # the requested level.
+            break
+    return result


More information about the Mercurial-devel mailing list