[PATCH RFC] HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT

Brodie Rao brodie at bitheap.org
Wed Jan 5 06:13:13 CST 2011


On Jan 5, 2011, at 3:55 AM, Erik Zielke wrote:

> Den 04-01-2011 14:21, Brodie Rao skrev:
>> # HG changeset patch
>> # User Brodie Rao<brodie at bitheap.org>
>> # Date 1294147116 -39600
>> # Node ID b653ec8e753a01653d46c70c56e72a37f5906f58
>> # Parent  f3058dd052819de75908599d93a29241ba69318f
>> HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT
>>
>> This makes it possible to gain the benefits of HGPLAIN for scripting
>> while preserving different behaviors like internationalization.
> I can definitiely see that people writing tools and scripts on top  
> of Mercurial can use feature like this.
>
>> diff --git a/mercurial/help/environment.txt b/mercurial/help/ 
>> environment.txt
>> --- a/mercurial/help/environment.txt
>> +++ b/mercurial/help/environment.txt
>> @@ -59,6 +59,14 @@ HGPLAIN
>>      Equivalent options set via command line flags or environment
>>      variables are not overridden.
>>
>> +HGPLAINEXCEPT
>> +    This is a comma-separated list of features to preserve when
>> +    HGPLAIN is enabled. Currently the only value supported is  
>> "i18n",
>> +    which preserves internationalization in plain mode.
>> +
>> +    Setting HGPLAINEXCEPT to anything (even an empty string) will
>> +    enable plain mode.
>> +
> Wouldn't it make sense to issue a warning, if an unsupported value  
> is in HGPLAINEXCEPT? This would of course mean that there should be  
> a way of specifying supported values.

I'm not sure. The current behavior is similar to how settings in hgrc  
work--Mercurial won't warn you about unknown settings. This makes the  
code somewhat simpler, and it moves the definition of plain modes onto  
their users.

I could see extensions using this feature to implement their own plain  
mode exceptions, much in the same way that they create their own  
settings simply by checking if they're set.

In the case of i18n, I think it would be easy to test if you're  
actually getting the desired result.

Also, I'm not entirely sure of the best way to actually test if the  
i18n exception works or not in test-hgrc.t. Are translations built  
before running tests? Is there a particularly stable translation I  
could use? Do we have a policy on tests depending or not depending on  
translations?

>>  HGUSER
>>      This is the string used as the author of a commit. If not set,
>>      available values will be considered in this order:
>> diff --git a/mercurial/i18n.py b/mercurial/i18n.py
>> --- a/mercurial/i18n.py
>> +++ b/mercurial/i18n.py
>> @@ -51,7 +51,13 @@ def gettext(message):
>>          # An unknown encoding results in a LookupError.
>>          return message
>>
>> -if 'HGPLAIN' in os.environ:
>> +def _plain():
>> +    if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in  
>> os.environ:
>> +        return False
>> +    exceptions = os.environ.get('HGPLAINEXCEPT', '').strip().split 
>> (',')
>> +    return 'i18n' not in exceptions
>> +
>> +if _plain():
>>      _ = lambda message: message
>>  else:
>>      _ = gettext
>> diff --git a/mercurial/ui.py b/mercurial/ui.py
>> --- a/mercurial/ui.py
>> +++ b/mercurial/ui.py
>> @@ -268,15 +268,22 @@ class ui(object):
>>      def plain(self):
>>          '''is plain mode active?
>>
>> -        Plain mode means that all configuration variables which  
>> affect the
>> -        behavior and output of Mercurial should be ignored.  
>> Additionally, the
>> -        output should be stable, reproducible and suitable for use  
>> in scripts or
>> -        applications.
>> +        Plain mode means that all configuration variables which  
>> affect
>> +        the behavior and output of Mercurial should be
>> +        ignored. Additionally, the output should be stable,
>> +        reproducible and suitable for use in scripts or  
>> applications.
>>
>> -        The only way to trigger plain mode is by setting the  
>> `HGPLAIN'
>> -        environment variable.
>> +        The only way to trigger plain mode is by setting either the
>> +        `HGPLAIN' or `HGPLAINEXCEPT' environment variables.
>> +
>> +        The return value can either be False, True, or a list of
>> +        features that plain mode should not apply to (e.g., i18n,
>> +        progress, etc).
>>          '''
>> -        return 'HGPLAIN' in os.environ
>> +        if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in  
>> os.environ:
>> +            return False
>> +        exceptions = os.environ.get('HGPLAINEXCEPT', '').strip 
>> ().split(',')
>> +        return exceptions or True
>>
>>      def username(self):
>>          """Return default username to be used in commits.
>> diff --git a/tests/test-hgrc.t b/tests/test-hgrc.t
>> --- a/tests/test-hgrc.t
>> +++ b/tests/test-hgrc.t
>> @@ -133,3 +133,39 @@ plain hgrc
>>    none: ui.verbose=False
>>    none: ui.debug=True
>>    none: ui.quiet=False
>> +
>> +plain mode with exceptions
>> +
>> +  $ cat>  plain.py<<EOF
>> +>  def uisetup(ui):
>> +>      ui.write('plain: %r\n' % ui.plain())
>> +>  EOF
>> +  $ echo "[extensions]">>  $HGRCPATH
>> +  $ echo "plain=./plain.py">>  $HGRCPATH
>> +  $ HGPLAINEXCEPT=; export HGPLAINEXCEPT
>> +  $ hg showconfig --config ui.traceback=True --debug
>> +  plain: ['']
>> +  read config from: $TESTTMP/hgrc
>> +  $TESTTMP/hgrc:15: extensions.plain=./plain.py
>> +  none: ui.traceback=True
>> +  none: ui.verbose=False
>> +  none: ui.debug=True
>> +  none: ui.quiet=False
>> +  $ unset HGPLAIN
>> +  $ hg showconfig --config ui.traceback=True --debug
>> +  plain: ['']
>> +  read config from: $TESTTMP/hgrc
>> +  $TESTTMP/hgrc:15: extensions.plain=./plain.py
>> +  none: ui.traceback=True
>> +  none: ui.verbose=False
>> +  none: ui.debug=True
>> +  none: ui.quiet=False
>> +  $ HGPLAINEXCEPT=i18n; export HGPLAINEXCEPT
>> +  $ hg showconfig --config ui.traceback=True --debug
>> +  plain: ['i18n']
>> +  read config from: $TESTTMP/hgrc
>> +  $TESTTMP/hgrc:15: extensions.plain=./plain.py
>> +  none: ui.traceback=True
>> +  none: ui.verbose=False
>> +  none: ui.debug=True
>> +  none: ui.quiet=False
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
>
>
> -- 
> Erik Zielke
> aragost Trifork ag
> http://aragost.com/mercurial/
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list