[PATCH 3 of 3] setup: improve tag retrieval for archives and fallback to lasttag otherwise
Gilles Moris
gilles.moris at free.fr
Mon Aug 10 02:38:45 CDT 2009
On Mon August 10 2009 01:19:21 Mads Kiilerich wrote:
> >>> + 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.
>
I will probably stick to something close to the original code to be consistent.
> > 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)
>
I'm afraid I do not adhere:
- removing the outer parenthesis could break scripts that parse the output to
get the version.
- putting the emphasis on the nearest tag leaves the impression that this is
a stable release when its not.
- all this is becoming a little cryptic. I would be more favorable to an
explicit output, translated, at the cost of not being parsable. This is
more optional information after all.
- we'd rather not use inner parenthesis as some scripts can be broken. As an
example, it breaks test-globalopts.
So in the order:
Mercurial Distributed SCM (version 1.3.1)
Mercurial Distributed SCM (version f61394b23964 [1.3.1 + 81 changes])
Mercurial Distributed SCM (version f61394b23964+ [1.3.1 with local changes of 20090809])
Mercurial Distributed SCM (version f61394b23964+ [1.3.1 + 81 changes with local changes of 20090809])
Mercurial Distributed SCM (version unknown)
# unknown is when we fail retrieving anything
# could be just the hash if lasttag does not work
Regards.
Gilles.
More information about the Mercurial-devel
mailing list