Patchwork [4,of,6,RFC] compat: module to handle different ui.compat settings

login
register
mail settings
Submitter David Soria Parra
Date March 12, 2017, 8:10 p.m.
Message ID <8efd04667ba8d2939a93.1489349444@davidsp-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/19234/
State Superseded
Headers show

Comments

David Soria Parra - March 12, 2017, 8:10 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1489349206 25200
#      Sun Mar 12 13:06:46 2017 -0700
# Node ID 8efd04667ba8d2939a937f549e803bc3b56f70a7
# 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.

Patch

diff --git a/mercurial/compat.py b/mercurial/compat.py
new file mode 100644
--- /dev/null
+++ b/mercurial/compat.py
@@ -0,0 +1,48 @@ 
+# 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([
+    ('latest', {
+        'diff': {
+            'git': 'True',
+            'showfunc': 'True',
+        },
+        'ui': {
+            'color': 'auto',
+            'interface': 'curses',
+        },
+    })],
+)
+
+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