[PATCH 3 of 3 RFC] templater: add 'transplant_source' keyword

Dan Villiom Podlaski Christiansen danchr at gmail.com
Sun Sep 19 16:20:54 CDT 2010


On 19 Sep 2010, at 22:56, Mads Kiilerich wrote:

>> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
>> --- a/mercurial/templatekw.py
>> +++ b/mercurial/templatekw.py
>> @@ -239,6 +239,44 @@ def showrev(repo, ctx, templ, **args):
>>  def showtags(**args):
>>      return showlist('tag', args['ctx'].tags(), **args)
>>
>> +def showextra(repo, ctx, templ, **args):
>> +    def isbinary(s):
>> +        '''
>> +        Improved, UTF-8-aware heuristic for short strings.
>> +
>> +        The usual heuristic (does the string contain '\0'?) is  
>> insufficient for
>> +        short strings. Instead, we use the following:
>> +
>> +        - Is the string valid UTF-8?
>
> AFAIK people and extensions are free to put stuff in extra fields  
> that are neither utf-8 nor "binary".
>
>> +        - If so, does it contain any of the 32 ASCII control  
>> characters?
>> +
>> +        Combined, the two make false negatives reasonably unlikely.
>
> Can you quantify this claim?

I tried it on the 400k unique changesets in repositories on my  
computer, and I didn't find any.

> For the record: I don't like this heuristic. We don't know the type  
> of these values and we can't guess them reliably, so we shouldn't  
> try to.
>
> I think it would be better to add a hex/short filters and use them  
> explicitly in the templates when necessary.

I'm beginning to agree with you; there's nothing that could make the  
heuristic be good enough :-/

> Besides that:
>
> convert_revision is stored hexified, while transplant_source is  
> binary. Isn't the latter a bug that just should be fixed?

It could be, but I see two problems with that: 1) it'd break backwards  
compatibility and 2) it won't fix the N+1 changesets out there that  
are already binary.

> hg log -v --debug (and {extras}) will show the extra fields too.  
> Whatever the solution is, isn't the same solution needed there?

It appears the string is simply escaped. Not terribly useful IMO. An  
example:

changeset:   3983:c22251414b46b41c65407f9bba17f0be4f6175a0
parent:      3938:20f1c8440c53d7cbd98a7a440c6acf66412615a4
parent:      -1:0000000000000000000000000000000000000000
manifest:    3982:4611c27c1aaed7ba7aa4d04f593aa8cf304ee7e7
user:        Benoit Boissinot <benoit.boissinot at ens-lyon.org>
date:        Thu Dec 14 00:41:11 2006 +0100
files:       setup.py
extra:       branch=default
extra:       transplant_source=_\x05\x15{\xf9\xbe\x87k\xfa2\xe6\xdbd 
\xe3\x83 \xb
5\t\x94\x05
description:
spelling fix

--

Dan Villiom Podlaski Christiansen
danchr at gmail.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1943 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20100919/6e708451/attachment.bin>


More information about the Mercurial-devel mailing list