Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/graphmod.py @ 16131:6f236c8bdc01
graphmod: rewrite graph config validation
Our goal is not to strictly disallow _invalid_ input, simply disallow _hostile_ input.
Avoid using re
Avoid creating empty dicts when no branch parameters are recognized
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 17 Feb 2012 13:53:19 -0600 |
parents | 33f702e52906 |
children | 41fc1e078d68 |
comparison
equal
deleted
inserted
replaced
16130:33f702e52906 | 16131:6f236c8bdc01 |
---|---|
16 context of the graph returned. Type is a constant specifying the node type. | 16 context of the graph returned. Type is a constant specifying the node type. |
17 Data depends on type. | 17 Data depends on type. |
18 """ | 18 """ |
19 | 19 |
20 from mercurial.node import nullrev | 20 from mercurial.node import nullrev |
21 import re | |
22 | 21 |
23 CHANGESET = 'C' | 22 CHANGESET = 'C' |
24 | 23 |
25 def dagwalker(repo, revs): | 24 def dagwalker(repo, revs): |
26 """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples | 25 """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
85 colors = {} | 84 colors = {} |
86 newcolor = 1 | 85 newcolor = 1 |
87 config = {} | 86 config = {} |
88 | 87 |
89 for key, val in repo.ui.configitems('graph'): | 88 for key, val in repo.ui.configitems('graph'): |
90 if '.' not in key: | 89 if '.' in key: |
91 continue | 90 branch, setting = key.rsplit('.', 1) |
92 branch, setting = key.rsplit('.', 1) | 91 # Validation |
93 gdict = config.setdefault(branch, {}) | 92 if setting == "width" and val.isdigit(): |
93 config.setdefault(branch, {})[setting] = val | |
94 elif setting == "color" and val.isalnum(): | |
95 config.setdefault(branch, {})[setting] = val | |
94 | 96 |
95 # Validation | |
96 if ((setting == "width" and val.isdigit() and 0 < int(val) < 30) or | |
97 (setting == "color" and re.match('^[0-9a-fA-F]{6}$', val))): | |
98 gdict[setting] = val | |
99 else: | |
100 continue | |
101 | 97 |
102 for (cur, type, data, parents) in dag: | 98 for (cur, type, data, parents) in dag: |
103 | 99 |
104 # Compute seen and next | 100 # Compute seen and next |
105 if cur not in seen: | 101 if cur not in seen: |