D2622: ui: adding a generic method to read config items with an arbitrary type

2020-01-24 Thread baymax (Baymax, Your Personal Patch-care Companion)
This revision now requires changes to proceed.
baymax added a comment.
baymax requested changes to this revision.


  There seems to have been no activities on this Diff for the past 3 Months.
  
  By policy, we are automatically moving it out of the `need-review` state.
  
  Please, move it back to `need-review` without hesitation if this diff should 
still be discussed.
  
  :baymax:need-review-idle:

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D2622/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D2622

To: rdamazio, #hg-reviewers, baymax
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2622: ui: adding a generic method to read config items with an arbitrary type

2018-03-03 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This can be used for reading many config options of various types where the
  type of each is known in some other structure (e.g. options matching command
  flags).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2622

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -545,6 +545,16 @@
 
 return main, sub
 
+def configtyped(self, section, name, itemtype, default=_unset, 
untrusted=False):
+"""Get a config item as the given type."""
+if itemtype is type(False) or itemtype is type(None):
+return self.configbool(section, name, default, untrusted)
+if itemtype is type(1):
+return self.configint(section, name, default, untrusted)
+if itemtype is type([]):
+return self.configlist(section, name, default, untrusted)
+return self.config(section, name, default, untrusted)
+
 def configpath(self, section, name, default=_unset, untrusted=False):
 'get a path config item, expanded relative to repo root or config file'
 v = self.config(section, name, default, untrusted)



To: rdamazio, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel