[PATCH 3 of 3] setup: improve tag retrieval for archives and fallback to lasttag otherwise

Mads Kiilerich mads at kiilerich.com
Sun Aug 9 18:19:21 CDT 2009


Gilles Moris wrote, On 08/09/2009 10:43 PM:
> On Sun August 9 2009 21:29:12 Mads Kiilerich wrote:
>    
>> If the working directory is dirty then we might want to include the
>> timestamp also in the next cas
> It is already not working for if we are on a tag.
> That's why I was thinking about an independent patch.
>    

Good idea. It might be better to put that patch first in the queue to 
avoid introducing yet another broken case which then has to be fixed.

>> (It could perhaps be convenient to also include the hash in the version
>> string in all cases, but that is a different story.)
>>
>>      
> That's not the case if we are on a tag, but in any other case we have a hash.
> You want to stick with that, right ?
>    

Tags can easily be moved to point to other changesets, so relying on 
them being unique and immutable is a bit risky. So I do think it would 
be nice to also show the hash when on a tag. I don't know how the bigger 
fishs in the pond feels.

>>> +        if line.startswith('lasttag:'):
>>> +            lasttag = line.split(':')[1].strip()
>>>
>>>        
>> lasttag = line.split(':', 1)[1].strip()
>>      
> Or may be even simpler:
>    line[9:].strip()
>    

Well ... yes. That is also how it is done in for example 
hgext/convert/cvs.py. But FWIW I don't like these magic numbers.
line[len('lasttag:') + 1:].strip() avoids the magic number at the cost 
of repeating the constant, which can be mitigated by introducing a 
variable.
Or perhaps line[line.index(':') + 1:].strip()

I have several times needed a good Python pattern for "if string starts 
with a given string then do something with the rest", but haven't found 
a good one.

> Another question about the format:
> # hg version -q
> Mercurial Distributed SCM (version f61394b23964 (1.3.1+81))
>
> Do we want to replace parenthesis by brace or bracket ?
> Spaces around the "+" ?
>    

My humble opinion:

First of all I would prefer to get rid of the outer paranthesis. That 
would change the output somehow, so I don't know if that is an option.

lasttag and distance says more about the version than the hash, so I 
would prefer to have them first and then (always) the hash in paranthesis.

I think the + looks fine.

So I suggest for example:
Mercurial Distributed SCM, version 1.3.1 (f61394b23964)
Mercurial Distributed SCM, version 1.3.1+81 (f61394b23964)
Mercurial Distributed SCM, version 1.3.1+20090809 (f61394b23964+)
Mercurial Distributed SCM, version 1.3.1+81+20090809 (f61394b23964+)
Mercurial Distributed SCM, version unknown (f61394b23964)

(But if you _really_ want a unambiguous notation for latest tag and 
distance you could use "1.3.1::81" ... but why should we want that ...)

/Mads


More information about the Mercurial-devel mailing list