[PATCH 1 of 2] graph: in hgrc specify line width for main branch

Martin Geisler mg at aragost.com
Thu Feb 2 09:23:53 CST 2012


Constantine Linnick <theaspect at gmail.com> writes:

> # HG changeset patch
> # User Constantine Linnick <theaspect at gmail.com>
> # Date 1327235726 -25200
> # Node ID 537733973603cb4f974f01aecd51923da17e314f
> # Parent  878bc4a62a735a1624e9b69c672d5fb5074d4855
> graph: in hgrc specify line width for main branch
>
> You can specify width to visually distinguish main branch (trunk)
> on hgweb's graph page. Settings format is branch_name.width = value,
> where width in px e.g.:
> [graph]
> default.width = 3
>
> diff -r 878bc4a62a73 -r 537733973603 mercurial/graphmod.py
> --- a/mercurial/graphmod.py	Thu Jan 19 14:31:05 2012 -0600
> +++ b/mercurial/graphmod.py	Sun Jan 22 19:35:26 2012 +0700
> @@ -18,6 +18,7 @@
>  """
>  
>  from mercurial.node import nullrev
> +import re
>  
>  CHANGESET = 'C'
>  
> @@ -67,7 +68,7 @@
>          parents = set([p.rev() for p in ctx.parents() if p.node() in include])
>          yield (ctx.rev(), CHANGESET, ctx, sorted(parents))
>  
> -def colored(dag):
> +def colored(dag, repo):
>      """annotates a DAG with colored edge information
>  
>      For each DAG node this function emits tuples::
> @@ -83,6 +84,21 @@
>      seen = []
>      colors = {}
>      newcolor = 1
> +    config = dict()

There is another empty dict just above and it uses {}. I'm not sure
which I prefer myself, but it's important to be consistent. You should
therefore use {} here too so that you keep the coding style consistent.

> +    for key, val in repo.ui.configitems('graph'):
> +        if '.' not in key:
> +            continue
> +        branch, setting = key.rsplit('.',1)

We use PEP 8 formatting in Mercurial. Please remember to run the full
test suite before submitting patches -- test-check-code-hg.t should have
caught the missing spaces around ','.

> +        gdict = config.setdefault(branch, dict())
> +
> +        # Validation
> +        if ((setting not in ('width',)) or

I believe this is the same as

  if (setting != 'width'

right?

> +                (setting == "width" and not re.match('[0-9]{1,2}', val))):

Please don't use regular expressions for something that can be checked
with simpler string functions:

  http://docs.python.org/library/stdtypes.html#str.isdigit

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://www.aragost.com/mercurial/customer-projects/


More information about the Mercurial-devel mailing list