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

2017-03-14 Thread Jun Wu
Excerpts from David Soria Parra's message of 2017-03-12 15:40:27 -0700:

[...]

> +# compat.py - handlign compatibility settings

spell: "handling"

> +#
> +# 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

spell: "must"

> +# is sorted while a dictionary is not.
> +COMPAT = util.sortdict([
> +('compat', {}),
> +('latest', {})],
> +)

The format looks a bit inconsistent, maybe:

  ('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)

Maybe set source, so "hg config --debug" shows where the configs come from.

> +
> +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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-03-12 Thread David Soria Parra
# HG changeset patch
# User David Soria Parra 
# 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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel