Show More
@@ -1,65 +1,64 b'' | |||||
1 |
|
1 | |||
2 | $ cat > engine.py << EOF |
|
2 | $ cat > engine.py << EOF | |
3 | > |
|
3 | > | |
4 | > from mercurial import ( |
|
4 | > from mercurial import ( | |
5 | > pycompat, |
|
5 | > pycompat, | |
6 | > templater, |
|
6 | > templater, | |
7 | > templateutil, |
|
7 | > templateutil, | |
8 | > ) |
|
8 | > ) | |
9 | > |
|
9 | > | |
10 | > class mytemplater(templater.engine): |
|
10 | > class mytemplater(templater.engine): | |
11 | > def _load(self, t): |
|
11 | > def _load(self, t): | |
12 | > return self._loader(t) |
|
12 | > return self._loader(t) | |
13 | > |
|
13 | > | |
14 | > def process(self, t, map): |
|
14 | > def process(self, t, map): | |
15 | > tmpl = self._load(t) |
|
15 | > tmpl = self._load(t) | |
16 | > props = self._defaults.copy() |
|
16 | > props = self._defaults.copy() | |
17 | > props.update(map) |
|
17 | > props.update(map) | |
18 | > for k, v in props.items(): |
|
18 | > for k, v in props.items(): | |
19 | > if k in (b'templ', b'ctx', b'repo', b'revcache', b'cache', |
|
19 | > if b'{{%s}}' % k not in tmpl: | |
20 | > b'troubles'): |
|
|||
21 | > continue |
|
20 | > continue | |
22 | > if callable(v) and getattr(v, '_requires', None) is None: |
|
21 | > if callable(v) and getattr(v, '_requires', None) is None: | |
23 | > props = self._resources.copy() |
|
22 | > props = self._resources.copy() | |
24 | > props.update(map) |
|
23 | > props.update(map) | |
25 | > v = v(**pycompat.strkwargs(props)) |
|
24 | > v = v(**pycompat.strkwargs(props)) | |
26 | > elif callable(v): |
|
25 | > elif callable(v): | |
27 | > v = v(self, props) |
|
26 | > v = v(self, props) | |
28 | > v = templateutil.stringify(v) |
|
27 | > v = templateutil.stringify(v) | |
29 | > tmpl = tmpl.replace(b'{{%s}}' % k, v) |
|
28 | > tmpl = tmpl.replace(b'{{%s}}' % k, v) | |
30 |
|
|
29 | > yield tmpl | |
31 | > |
|
30 | > | |
32 | > templater.engines[b'my'] = mytemplater |
|
31 | > templater.engines[b'my'] = mytemplater | |
33 | > EOF |
|
32 | > EOF | |
34 | $ hg init test |
|
33 | $ hg init test | |
35 | $ echo '[extensions]' > test/.hg/hgrc |
|
34 | $ echo '[extensions]' > test/.hg/hgrc | |
36 | $ echo "engine = `pwd`/engine.py" >> test/.hg/hgrc |
|
35 | $ echo "engine = `pwd`/engine.py" >> test/.hg/hgrc | |
37 | $ cd test |
|
36 | $ cd test | |
38 | $ cat > mymap << EOF |
|
37 | $ cat > mymap << EOF | |
39 | > changeset = my:changeset.txt |
|
38 | > changeset = my:changeset.txt | |
40 | > EOF |
|
39 | > EOF | |
41 | $ cat > changeset.txt << EOF |
|
40 | $ cat > changeset.txt << EOF | |
42 | > {{rev}} {{node}} {{author}} |
|
41 | > {{rev}} {{node}} {{author}} | |
43 | > EOF |
|
42 | > EOF | |
44 | $ hg ci -Ama |
|
43 | $ hg ci -Ama | |
45 | adding changeset.txt |
|
44 | adding changeset.txt | |
46 | adding mymap |
|
45 | adding mymap | |
47 | $ hg log --style=./mymap |
|
46 | $ hg log --style=./mymap | |
48 | 0 97e5f848f0936960273bbf75be6388cd0350a32b test |
|
47 | 0 97e5f848f0936960273bbf75be6388cd0350a32b test | |
49 |
|
48 | |||
50 | $ cat > changeset.txt << EOF |
|
49 | $ cat > changeset.txt << EOF | |
51 | > {{p1rev}} {{p1node}} {{p2rev}} {{p2node}} |
|
50 | > {{p1rev}} {{p1node}} {{p2rev}} {{p2node}} | |
52 | > EOF |
|
51 | > EOF | |
53 | $ hg ci -Ama |
|
52 | $ hg ci -Ama | |
54 | $ hg log --style=./mymap |
|
53 | $ hg log --style=./mymap | |
55 | 0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000 |
|
54 | 0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000 | |
56 | -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000 |
|
55 | -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000 | |
57 |
|
56 | |||
58 | invalid engine type: |
|
57 | invalid engine type: | |
59 |
|
58 | |||
60 | $ echo 'changeset = unknown:changeset.txt' > unknownenginemap |
|
59 | $ echo 'changeset = unknown:changeset.txt' > unknownenginemap | |
61 | $ hg log --style=./unknownenginemap |
|
60 | $ hg log --style=./unknownenginemap | |
62 | abort: invalid template engine: unknown |
|
61 | abort: invalid template engine: unknown | |
63 | [255] |
|
62 | [255] | |
64 |
|
63 | |||
65 | $ cd .. |
|
64 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now