[PATCH 2 of 2] setup: refactor the version string to a subset of tag+tagdist-hash+date

Gilles Moris gilles.moris at free.fr
Sat Oct 17 21:58:52 UTC 2009


On Saturday 17 October 2009 11:02:48 pm Gilles Moris wrote:
>  elif os.path.exists('.hg_archival.txt'):
>      hgarchival = open('.hg_archival.txt')
> +    node = tag = latesttag = latesttagdistance = ''
>      for line in hgarchival:
>          if line.startswith('node:'):
> -            version = line.split(':')[1].strip()[:12]
> -            break
> +            node = line.split(':')[1].strip()[:12]
> +        if line.startswith('tag:'):
> +            tag = line.split(':')[1].strip()
> +        if line.startswith('latesttag:'):
> +            latesttag = line.split(':')[1].strip()
> +        if line.startswith('latesttagdistance:'):
> +            latesttagdistance = line.split(':')[1].strip()
> +    if tag:
> +        version = tag
> +    elif latesttag and latesttagdistance != '0':
> +        version = '%s+%s-%s' % (latesttag, latesttagdistance, node)
> +    else:
> +        version = node

Or possibly the more pythonish:

elif os.path.exists('.hg_archival.txt'):
    hgarchival = open('.hg_archival.txt')
    kw = dict()
    for line in hgarchival:
        l = line.split(':', 1)
        kw[l[0]] = l[1].strip()
    if kw.get('tag'):
        version =  kw.get('tag')
    elif kw.get('latesttag') and kw.get('latesttagdistance', '0') != '0':
        version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
    else:
        version = kw.get('node', '')[:12]




More information about the Mercurial-devel mailing list