Mercurial > hg
comparison tests/test-grep.t @ 29858:33461139c31c
grep: add formatter support
Several fields are renamed to be consistent with the annotate command, which
doesn't mean the last call for the name unification [1]. Actually, I'd rather
rename line_number to linenumber, linenum, lineno or line, but I want to
port the grep command to formatter first.
[1]: https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary
I don't have any better name for the list of matched/unmatched texts, so
they are just called as "texts".
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 18 Aug 2016 15:13:56 +0900 |
parents | b842b1adfea2 |
children | eafd380fe1b8 |
comparison
equal
deleted
inserted
replaced
29857:0418cdf67efb | 29858:33461139c31c |
---|---|
38 > --color=always port port | 38 > --color=always port port |
39 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc) | 39 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc) |
40 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc) | 40 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc) |
41 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc) | 41 \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc) |
42 | 42 |
43 simple templated | |
44 | |
45 $ hg grep port \ | |
46 > -T '{file}:{rev}:{node|short}:{texts % "{if(matched, text|upper, text)}"}\n' | |
47 port:4:914fa752cdea:exPORT | |
48 port:4:914fa752cdea:vaPORTight | |
49 port:4:914fa752cdea:imPORT/exPORT | |
50 | |
51 simple JSON (no "change" field) | |
52 | |
53 $ hg grep -Tjson port | |
54 [ | |
55 { | |
56 "date": [4.0, 0], | |
57 "file": "port", | |
58 "line_number": 1, | |
59 "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", | |
60 "rev": 4, | |
61 "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}], | |
62 "user": "spam" | |
63 }, | |
64 { | |
65 "date": [4.0, 0], | |
66 "file": "port", | |
67 "line_number": 2, | |
68 "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", | |
69 "rev": 4, | |
70 "texts": [{"matched": false, "text": "va"}, {"matched": true, "text": "port"}, {"matched": false, "text": "ight"}], | |
71 "user": "spam" | |
72 }, | |
73 { | |
74 "date": [4.0, 0], | |
75 "file": "port", | |
76 "line_number": 3, | |
77 "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", | |
78 "rev": 4, | |
79 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}], | |
80 "user": "spam" | |
81 } | |
82 ] | |
83 | |
84 simple JSON without matching lines | |
85 | |
86 $ hg grep -Tjson -l port | |
87 [ | |
88 { | |
89 "date": [4.0, 0], | |
90 "file": "port", | |
91 "line_number": 1, | |
92 "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", | |
93 "rev": 4, | |
94 "user": "spam" | |
95 } | |
96 ] | |
97 | |
43 all | 98 all |
44 | 99 |
45 $ hg grep --traceback --all -nu port port | 100 $ hg grep --traceback --all -nu port port |
46 port:4:4:-:spam:import/export | 101 port:4:4:-:spam:import/export |
47 port:3:4:+:eggs:import/export | 102 port:3:4:+:eggs:import/export |
50 port:2:1:+:spam:export | 105 port:2:1:+:spam:export |
51 port:2:2:+:spam:vaportight | 106 port:2:2:+:spam:vaportight |
52 port:2:3:+:spam:import/export | 107 port:2:3:+:spam:import/export |
53 port:1:2:+:eggs:export | 108 port:1:2:+:eggs:export |
54 port:0:1:+:spam:import | 109 port:0:1:+:spam:import |
110 | |
111 all JSON | |
112 | |
113 $ hg grep --all -Tjson port port | |
114 [ | |
115 { | |
116 "change": "-", | |
117 "date": [4.0, 0], | |
118 "file": "port", | |
119 "line_number": 4, | |
120 "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c", | |
121 "rev": 4, | |
122 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}], | |
123 "user": "spam" | |
124 }, | |
125 { | |
126 "change": "+", | |
127 "date": [3.0, 0], | |
128 "file": "port", | |
129 "line_number": 4, | |
130 "node": "95040cfd017d658c536071c6290230a613c4c2a6", | |
131 "rev": 3, | |
132 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}], | |
133 "user": "eggs" | |
134 }, | |
135 { | |
136 "change": "-", | |
137 "date": [2.0, 0], | |
138 "file": "port", | |
139 "line_number": 1, | |
140 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", | |
141 "rev": 2, | |
142 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}], | |
143 "user": "spam" | |
144 }, | |
145 { | |
146 "change": "-", | |
147 "date": [2.0, 0], | |
148 "file": "port", | |
149 "line_number": 2, | |
150 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", | |
151 "rev": 2, | |
152 "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}], | |
153 "user": "spam" | |
154 }, | |
155 { | |
156 "change": "+", | |
157 "date": [2.0, 0], | |
158 "file": "port", | |
159 "line_number": 1, | |
160 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", | |
161 "rev": 2, | |
162 "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}], | |
163 "user": "spam" | |
164 }, | |
165 { | |
166 "change": "+", | |
167 "date": [2.0, 0], | |
168 "file": "port", | |
169 "line_number": 2, | |
170 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", | |
171 "rev": 2, | |
172 "texts": [{"matched": false, "text": "va"}, {"matched": true, "text": "port"}, {"matched": false, "text": "ight"}], | |
173 "user": "spam" | |
174 }, | |
175 { | |
176 "change": "+", | |
177 "date": [2.0, 0], | |
178 "file": "port", | |
179 "line_number": 3, | |
180 "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", | |
181 "rev": 2, | |
182 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}, {"matched": false, "text": "/ex"}, {"matched": true, "text": "port"}], | |
183 "user": "spam" | |
184 }, | |
185 { | |
186 "change": "+", | |
187 "date": [1.0, 0], | |
188 "file": "port", | |
189 "line_number": 2, | |
190 "node": "8b20f75c158513ff5ac80bd0e5219bfb6f0eb587", | |
191 "rev": 1, | |
192 "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}], | |
193 "user": "eggs" | |
194 }, | |
195 { | |
196 "change": "+", | |
197 "date": [0.0, 0], | |
198 "file": "port", | |
199 "line_number": 1, | |
200 "node": "f31323c9217050ba245ee8b537c713ec2e8ab226", | |
201 "rev": 0, | |
202 "texts": [{"matched": false, "text": "im"}, {"matched": true, "text": "port"}], | |
203 "user": "spam" | |
204 } | |
205 ] | |
55 | 206 |
56 other | 207 other |
57 | 208 |
58 $ hg grep -l port port | 209 $ hg grep -l port port |
59 port:4 | 210 port:4 |