##// END OF EJS Templates
formatter: add support for docheader and docfooter templates...
Yuya Nishihara -
r32949:13eebc18 default
parent child Browse files
Show More
@@ -1,497 +1,516 b''
1 # formatter.py - generic output formatting for mercurial
1 # formatter.py - generic output formatting for mercurial
2 #
2 #
3 # Copyright 2012 Matt Mackall <mpm@selenic.com>
3 # Copyright 2012 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 """Generic output formatting for Mercurial
8 """Generic output formatting for Mercurial
9
9
10 The formatter provides API to show data in various ways. The following
10 The formatter provides API to show data in various ways. The following
11 functions should be used in place of ui.write():
11 functions should be used in place of ui.write():
12
12
13 - fm.write() for unconditional output
13 - fm.write() for unconditional output
14 - fm.condwrite() to show some extra data conditionally in plain output
14 - fm.condwrite() to show some extra data conditionally in plain output
15 - fm.context() to provide changectx to template output
15 - fm.context() to provide changectx to template output
16 - fm.data() to provide extra data to JSON or template output
16 - fm.data() to provide extra data to JSON or template output
17 - fm.plain() to show raw text that isn't provided to JSON or template output
17 - fm.plain() to show raw text that isn't provided to JSON or template output
18
18
19 To show structured data (e.g. date tuples, dicts, lists), apply fm.format*()
19 To show structured data (e.g. date tuples, dicts, lists), apply fm.format*()
20 beforehand so the data is converted to the appropriate data type. Use
20 beforehand so the data is converted to the appropriate data type. Use
21 fm.isplain() if you need to convert or format data conditionally which isn't
21 fm.isplain() if you need to convert or format data conditionally which isn't
22 supported by the formatter API.
22 supported by the formatter API.
23
23
24 To build nested structure (i.e. a list of dicts), use fm.nested().
24 To build nested structure (i.e. a list of dicts), use fm.nested().
25
25
26 See also https://www.mercurial-scm.org/wiki/GenericTemplatingPlan
26 See also https://www.mercurial-scm.org/wiki/GenericTemplatingPlan
27
27
28 fm.condwrite() vs 'if cond:':
28 fm.condwrite() vs 'if cond:':
29
29
30 In most cases, use fm.condwrite() so users can selectively show the data
30 In most cases, use fm.condwrite() so users can selectively show the data
31 in template output. If it's costly to build data, use plain 'if cond:' with
31 in template output. If it's costly to build data, use plain 'if cond:' with
32 fm.write().
32 fm.write().
33
33
34 fm.nested() vs fm.formatdict() (or fm.formatlist()):
34 fm.nested() vs fm.formatdict() (or fm.formatlist()):
35
35
36 fm.nested() should be used to form a tree structure (a list of dicts of
36 fm.nested() should be used to form a tree structure (a list of dicts of
37 lists of dicts...) which can be accessed through template keywords, e.g.
37 lists of dicts...) which can be accessed through template keywords, e.g.
38 "{foo % "{bar % {...}} {baz % {...}}"}". On the other hand, fm.formatdict()
38 "{foo % "{bar % {...}} {baz % {...}}"}". On the other hand, fm.formatdict()
39 exports a dict-type object to template, which can be accessed by e.g.
39 exports a dict-type object to template, which can be accessed by e.g.
40 "{get(foo, key)}" function.
40 "{get(foo, key)}" function.
41
41
42 Doctest helper:
42 Doctest helper:
43
43
44 >>> def show(fn, verbose=False, **opts):
44 >>> def show(fn, verbose=False, **opts):
45 ... import sys
45 ... import sys
46 ... from . import ui as uimod
46 ... from . import ui as uimod
47 ... ui = uimod.ui()
47 ... ui = uimod.ui()
48 ... ui.fout = sys.stdout # redirect to doctest
48 ... ui.fout = sys.stdout # redirect to doctest
49 ... ui.verbose = verbose
49 ... ui.verbose = verbose
50 ... return fn(ui, ui.formatter(fn.__name__, opts))
50 ... return fn(ui, ui.formatter(fn.__name__, opts))
51
51
52 Basic example:
52 Basic example:
53
53
54 >>> def files(ui, fm):
54 >>> def files(ui, fm):
55 ... files = [('foo', 123, (0, 0)), ('bar', 456, (1, 0))]
55 ... files = [('foo', 123, (0, 0)), ('bar', 456, (1, 0))]
56 ... for f in files:
56 ... for f in files:
57 ... fm.startitem()
57 ... fm.startitem()
58 ... fm.write('path', '%s', f[0])
58 ... fm.write('path', '%s', f[0])
59 ... fm.condwrite(ui.verbose, 'date', ' %s',
59 ... fm.condwrite(ui.verbose, 'date', ' %s',
60 ... fm.formatdate(f[2], '%Y-%m-%d %H:%M:%S'))
60 ... fm.formatdate(f[2], '%Y-%m-%d %H:%M:%S'))
61 ... fm.data(size=f[1])
61 ... fm.data(size=f[1])
62 ... fm.plain('\\n')
62 ... fm.plain('\\n')
63 ... fm.end()
63 ... fm.end()
64 >>> show(files)
64 >>> show(files)
65 foo
65 foo
66 bar
66 bar
67 >>> show(files, verbose=True)
67 >>> show(files, verbose=True)
68 foo 1970-01-01 00:00:00
68 foo 1970-01-01 00:00:00
69 bar 1970-01-01 00:00:01
69 bar 1970-01-01 00:00:01
70 >>> show(files, template='json')
70 >>> show(files, template='json')
71 [
71 [
72 {
72 {
73 "date": [0, 0],
73 "date": [0, 0],
74 "path": "foo",
74 "path": "foo",
75 "size": 123
75 "size": 123
76 },
76 },
77 {
77 {
78 "date": [1, 0],
78 "date": [1, 0],
79 "path": "bar",
79 "path": "bar",
80 "size": 456
80 "size": 456
81 }
81 }
82 ]
82 ]
83 >>> show(files, template='path: {path}\\ndate: {date|rfc3339date}\\n')
83 >>> show(files, template='path: {path}\\ndate: {date|rfc3339date}\\n')
84 path: foo
84 path: foo
85 date: 1970-01-01T00:00:00+00:00
85 date: 1970-01-01T00:00:00+00:00
86 path: bar
86 path: bar
87 date: 1970-01-01T00:00:01+00:00
87 date: 1970-01-01T00:00:01+00:00
88
88
89 Nested example:
89 Nested example:
90
90
91 >>> def subrepos(ui, fm):
91 >>> def subrepos(ui, fm):
92 ... fm.startitem()
92 ... fm.startitem()
93 ... fm.write('repo', '[%s]\\n', 'baz')
93 ... fm.write('repo', '[%s]\\n', 'baz')
94 ... files(ui, fm.nested('files'))
94 ... files(ui, fm.nested('files'))
95 ... fm.end()
95 ... fm.end()
96 >>> show(subrepos)
96 >>> show(subrepos)
97 [baz]
97 [baz]
98 foo
98 foo
99 bar
99 bar
100 >>> show(subrepos, template='{repo}: {join(files % "{path}", ", ")}\\n')
100 >>> show(subrepos, template='{repo}: {join(files % "{path}", ", ")}\\n')
101 baz: foo, bar
101 baz: foo, bar
102 """
102 """
103
103
104 from __future__ import absolute_import
104 from __future__ import absolute_import
105
105
106 import collections
106 import collections
107 import contextlib
107 import contextlib
108 import itertools
108 import itertools
109 import os
109 import os
110
110
111 from .i18n import _
111 from .i18n import _
112 from .node import (
112 from .node import (
113 hex,
113 hex,
114 short,
114 short,
115 )
115 )
116
116
117 from . import (
117 from . import (
118 error,
118 error,
119 pycompat,
119 pycompat,
120 templatefilters,
120 templatefilters,
121 templatekw,
121 templatekw,
122 templater,
122 templater,
123 util,
123 util,
124 )
124 )
125
125
126 pickle = util.pickle
126 pickle = util.pickle
127
127
128 class _nullconverter(object):
128 class _nullconverter(object):
129 '''convert non-primitive data types to be processed by formatter'''
129 '''convert non-primitive data types to be processed by formatter'''
130 @staticmethod
130 @staticmethod
131 def formatdate(date, fmt):
131 def formatdate(date, fmt):
132 '''convert date tuple to appropriate format'''
132 '''convert date tuple to appropriate format'''
133 return date
133 return date
134 @staticmethod
134 @staticmethod
135 def formatdict(data, key, value, fmt, sep):
135 def formatdict(data, key, value, fmt, sep):
136 '''convert dict or key-value pairs to appropriate dict format'''
136 '''convert dict or key-value pairs to appropriate dict format'''
137 # use plain dict instead of util.sortdict so that data can be
137 # use plain dict instead of util.sortdict so that data can be
138 # serialized as a builtin dict in pickle output
138 # serialized as a builtin dict in pickle output
139 return dict(data)
139 return dict(data)
140 @staticmethod
140 @staticmethod
141 def formatlist(data, name, fmt, sep):
141 def formatlist(data, name, fmt, sep):
142 '''convert iterable to appropriate list format'''
142 '''convert iterable to appropriate list format'''
143 return list(data)
143 return list(data)
144
144
145 class baseformatter(object):
145 class baseformatter(object):
146 def __init__(self, ui, topic, opts, converter):
146 def __init__(self, ui, topic, opts, converter):
147 self._ui = ui
147 self._ui = ui
148 self._topic = topic
148 self._topic = topic
149 self._style = opts.get("style")
149 self._style = opts.get("style")
150 self._template = opts.get("template")
150 self._template = opts.get("template")
151 self._converter = converter
151 self._converter = converter
152 self._item = None
152 self._item = None
153 # function to convert node to string suitable for this output
153 # function to convert node to string suitable for this output
154 self.hexfunc = hex
154 self.hexfunc = hex
155 def __enter__(self):
155 def __enter__(self):
156 return self
156 return self
157 def __exit__(self, exctype, excvalue, traceback):
157 def __exit__(self, exctype, excvalue, traceback):
158 if exctype is None:
158 if exctype is None:
159 self.end()
159 self.end()
160 def _showitem(self):
160 def _showitem(self):
161 '''show a formatted item once all data is collected'''
161 '''show a formatted item once all data is collected'''
162 pass
162 pass
163 def startitem(self):
163 def startitem(self):
164 '''begin an item in the format list'''
164 '''begin an item in the format list'''
165 if self._item is not None:
165 if self._item is not None:
166 self._showitem()
166 self._showitem()
167 self._item = {}
167 self._item = {}
168 def formatdate(self, date, fmt='%a %b %d %H:%M:%S %Y %1%2'):
168 def formatdate(self, date, fmt='%a %b %d %H:%M:%S %Y %1%2'):
169 '''convert date tuple to appropriate format'''
169 '''convert date tuple to appropriate format'''
170 return self._converter.formatdate(date, fmt)
170 return self._converter.formatdate(date, fmt)
171 def formatdict(self, data, key='key', value='value', fmt='%s=%s', sep=' '):
171 def formatdict(self, data, key='key', value='value', fmt='%s=%s', sep=' '):
172 '''convert dict or key-value pairs to appropriate dict format'''
172 '''convert dict or key-value pairs to appropriate dict format'''
173 return self._converter.formatdict(data, key, value, fmt, sep)
173 return self._converter.formatdict(data, key, value, fmt, sep)
174 def formatlist(self, data, name, fmt='%s', sep=' '):
174 def formatlist(self, data, name, fmt='%s', sep=' '):
175 '''convert iterable to appropriate list format'''
175 '''convert iterable to appropriate list format'''
176 # name is mandatory argument for now, but it could be optional if
176 # name is mandatory argument for now, but it could be optional if
177 # we have default template keyword, e.g. {item}
177 # we have default template keyword, e.g. {item}
178 return self._converter.formatlist(data, name, fmt, sep)
178 return self._converter.formatlist(data, name, fmt, sep)
179 def context(self, **ctxs):
179 def context(self, **ctxs):
180 '''insert context objects to be used to render template keywords'''
180 '''insert context objects to be used to render template keywords'''
181 pass
181 pass
182 def data(self, **data):
182 def data(self, **data):
183 '''insert data into item that's not shown in default output'''
183 '''insert data into item that's not shown in default output'''
184 data = pycompat.byteskwargs(data)
184 data = pycompat.byteskwargs(data)
185 self._item.update(data)
185 self._item.update(data)
186 def write(self, fields, deftext, *fielddata, **opts):
186 def write(self, fields, deftext, *fielddata, **opts):
187 '''do default text output while assigning data to item'''
187 '''do default text output while assigning data to item'''
188 fieldkeys = fields.split()
188 fieldkeys = fields.split()
189 assert len(fieldkeys) == len(fielddata)
189 assert len(fieldkeys) == len(fielddata)
190 self._item.update(zip(fieldkeys, fielddata))
190 self._item.update(zip(fieldkeys, fielddata))
191 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
191 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
192 '''do conditional write (primarily for plain formatter)'''
192 '''do conditional write (primarily for plain formatter)'''
193 fieldkeys = fields.split()
193 fieldkeys = fields.split()
194 assert len(fieldkeys) == len(fielddata)
194 assert len(fieldkeys) == len(fielddata)
195 self._item.update(zip(fieldkeys, fielddata))
195 self._item.update(zip(fieldkeys, fielddata))
196 def plain(self, text, **opts):
196 def plain(self, text, **opts):
197 '''show raw text for non-templated mode'''
197 '''show raw text for non-templated mode'''
198 pass
198 pass
199 def isplain(self):
199 def isplain(self):
200 '''check for plain formatter usage'''
200 '''check for plain formatter usage'''
201 return False
201 return False
202 def nested(self, field):
202 def nested(self, field):
203 '''sub formatter to store nested data in the specified field'''
203 '''sub formatter to store nested data in the specified field'''
204 self._item[field] = data = []
204 self._item[field] = data = []
205 return _nestedformatter(self._ui, self._converter, data)
205 return _nestedformatter(self._ui, self._converter, data)
206 def end(self):
206 def end(self):
207 '''end output for the formatter'''
207 '''end output for the formatter'''
208 if self._item is not None:
208 if self._item is not None:
209 self._showitem()
209 self._showitem()
210
210
211 def nullformatter(ui, topic):
211 def nullformatter(ui, topic):
212 '''formatter that prints nothing'''
212 '''formatter that prints nothing'''
213 return baseformatter(ui, topic, opts={}, converter=_nullconverter)
213 return baseformatter(ui, topic, opts={}, converter=_nullconverter)
214
214
215 class _nestedformatter(baseformatter):
215 class _nestedformatter(baseformatter):
216 '''build sub items and store them in the parent formatter'''
216 '''build sub items and store them in the parent formatter'''
217 def __init__(self, ui, converter, data):
217 def __init__(self, ui, converter, data):
218 baseformatter.__init__(self, ui, topic='', opts={}, converter=converter)
218 baseformatter.__init__(self, ui, topic='', opts={}, converter=converter)
219 self._data = data
219 self._data = data
220 def _showitem(self):
220 def _showitem(self):
221 self._data.append(self._item)
221 self._data.append(self._item)
222
222
223 def _iteritems(data):
223 def _iteritems(data):
224 '''iterate key-value pairs in stable order'''
224 '''iterate key-value pairs in stable order'''
225 if isinstance(data, dict):
225 if isinstance(data, dict):
226 return sorted(data.iteritems())
226 return sorted(data.iteritems())
227 return data
227 return data
228
228
229 class _plainconverter(object):
229 class _plainconverter(object):
230 '''convert non-primitive data types to text'''
230 '''convert non-primitive data types to text'''
231 @staticmethod
231 @staticmethod
232 def formatdate(date, fmt):
232 def formatdate(date, fmt):
233 '''stringify date tuple in the given format'''
233 '''stringify date tuple in the given format'''
234 return util.datestr(date, fmt)
234 return util.datestr(date, fmt)
235 @staticmethod
235 @staticmethod
236 def formatdict(data, key, value, fmt, sep):
236 def formatdict(data, key, value, fmt, sep):
237 '''stringify key-value pairs separated by sep'''
237 '''stringify key-value pairs separated by sep'''
238 return sep.join(fmt % (k, v) for k, v in _iteritems(data))
238 return sep.join(fmt % (k, v) for k, v in _iteritems(data))
239 @staticmethod
239 @staticmethod
240 def formatlist(data, name, fmt, sep):
240 def formatlist(data, name, fmt, sep):
241 '''stringify iterable separated by sep'''
241 '''stringify iterable separated by sep'''
242 return sep.join(fmt % e for e in data)
242 return sep.join(fmt % e for e in data)
243
243
244 class plainformatter(baseformatter):
244 class plainformatter(baseformatter):
245 '''the default text output scheme'''
245 '''the default text output scheme'''
246 def __init__(self, ui, out, topic, opts):
246 def __init__(self, ui, out, topic, opts):
247 baseformatter.__init__(self, ui, topic, opts, _plainconverter)
247 baseformatter.__init__(self, ui, topic, opts, _plainconverter)
248 if ui.debugflag:
248 if ui.debugflag:
249 self.hexfunc = hex
249 self.hexfunc = hex
250 else:
250 else:
251 self.hexfunc = short
251 self.hexfunc = short
252 if ui is out:
252 if ui is out:
253 self._write = ui.write
253 self._write = ui.write
254 else:
254 else:
255 self._write = lambda s, **opts: out.write(s)
255 self._write = lambda s, **opts: out.write(s)
256 def startitem(self):
256 def startitem(self):
257 pass
257 pass
258 def data(self, **data):
258 def data(self, **data):
259 pass
259 pass
260 def write(self, fields, deftext, *fielddata, **opts):
260 def write(self, fields, deftext, *fielddata, **opts):
261 self._write(deftext % fielddata, **opts)
261 self._write(deftext % fielddata, **opts)
262 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
262 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
263 '''do conditional write'''
263 '''do conditional write'''
264 if cond:
264 if cond:
265 self._write(deftext % fielddata, **opts)
265 self._write(deftext % fielddata, **opts)
266 def plain(self, text, **opts):
266 def plain(self, text, **opts):
267 self._write(text, **opts)
267 self._write(text, **opts)
268 def isplain(self):
268 def isplain(self):
269 return True
269 return True
270 def nested(self, field):
270 def nested(self, field):
271 # nested data will be directly written to ui
271 # nested data will be directly written to ui
272 return self
272 return self
273 def end(self):
273 def end(self):
274 pass
274 pass
275
275
276 class debugformatter(baseformatter):
276 class debugformatter(baseformatter):
277 def __init__(self, ui, out, topic, opts):
277 def __init__(self, ui, out, topic, opts):
278 baseformatter.__init__(self, ui, topic, opts, _nullconverter)
278 baseformatter.__init__(self, ui, topic, opts, _nullconverter)
279 self._out = out
279 self._out = out
280 self._out.write("%s = [\n" % self._topic)
280 self._out.write("%s = [\n" % self._topic)
281 def _showitem(self):
281 def _showitem(self):
282 self._out.write(" " + repr(self._item) + ",\n")
282 self._out.write(" " + repr(self._item) + ",\n")
283 def end(self):
283 def end(self):
284 baseformatter.end(self)
284 baseformatter.end(self)
285 self._out.write("]\n")
285 self._out.write("]\n")
286
286
287 class pickleformatter(baseformatter):
287 class pickleformatter(baseformatter):
288 def __init__(self, ui, out, topic, opts):
288 def __init__(self, ui, out, topic, opts):
289 baseformatter.__init__(self, ui, topic, opts, _nullconverter)
289 baseformatter.__init__(self, ui, topic, opts, _nullconverter)
290 self._out = out
290 self._out = out
291 self._data = []
291 self._data = []
292 def _showitem(self):
292 def _showitem(self):
293 self._data.append(self._item)
293 self._data.append(self._item)
294 def end(self):
294 def end(self):
295 baseformatter.end(self)
295 baseformatter.end(self)
296 self._out.write(pickle.dumps(self._data))
296 self._out.write(pickle.dumps(self._data))
297
297
298 class jsonformatter(baseformatter):
298 class jsonformatter(baseformatter):
299 def __init__(self, ui, out, topic, opts):
299 def __init__(self, ui, out, topic, opts):
300 baseformatter.__init__(self, ui, topic, opts, _nullconverter)
300 baseformatter.__init__(self, ui, topic, opts, _nullconverter)
301 self._out = out
301 self._out = out
302 self._out.write("[")
302 self._out.write("[")
303 self._first = True
303 self._first = True
304 def _showitem(self):
304 def _showitem(self):
305 if self._first:
305 if self._first:
306 self._first = False
306 self._first = False
307 else:
307 else:
308 self._out.write(",")
308 self._out.write(",")
309
309
310 self._out.write("\n {\n")
310 self._out.write("\n {\n")
311 first = True
311 first = True
312 for k, v in sorted(self._item.items()):
312 for k, v in sorted(self._item.items()):
313 if first:
313 if first:
314 first = False
314 first = False
315 else:
315 else:
316 self._out.write(",\n")
316 self._out.write(",\n")
317 u = templatefilters.json(v, paranoid=False)
317 u = templatefilters.json(v, paranoid=False)
318 self._out.write(' "%s": %s' % (k, u))
318 self._out.write(' "%s": %s' % (k, u))
319 self._out.write("\n }")
319 self._out.write("\n }")
320 def end(self):
320 def end(self):
321 baseformatter.end(self)
321 baseformatter.end(self)
322 self._out.write("\n]\n")
322 self._out.write("\n]\n")
323
323
324 class _templateconverter(object):
324 class _templateconverter(object):
325 '''convert non-primitive data types to be processed by templater'''
325 '''convert non-primitive data types to be processed by templater'''
326 @staticmethod
326 @staticmethod
327 def formatdate(date, fmt):
327 def formatdate(date, fmt):
328 '''return date tuple'''
328 '''return date tuple'''
329 return date
329 return date
330 @staticmethod
330 @staticmethod
331 def formatdict(data, key, value, fmt, sep):
331 def formatdict(data, key, value, fmt, sep):
332 '''build object that can be evaluated as either plain string or dict'''
332 '''build object that can be evaluated as either plain string or dict'''
333 data = util.sortdict(_iteritems(data))
333 data = util.sortdict(_iteritems(data))
334 def f():
334 def f():
335 yield _plainconverter.formatdict(data, key, value, fmt, sep)
335 yield _plainconverter.formatdict(data, key, value, fmt, sep)
336 return templatekw.hybriddict(data, key=key, value=value, fmt=fmt,
336 return templatekw.hybriddict(data, key=key, value=value, fmt=fmt,
337 gen=f())
337 gen=f())
338 @staticmethod
338 @staticmethod
339 def formatlist(data, name, fmt, sep):
339 def formatlist(data, name, fmt, sep):
340 '''build object that can be evaluated as either plain string or list'''
340 '''build object that can be evaluated as either plain string or list'''
341 data = list(data)
341 data = list(data)
342 def f():
342 def f():
343 yield _plainconverter.formatlist(data, name, fmt, sep)
343 yield _plainconverter.formatlist(data, name, fmt, sep)
344 return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f())
344 return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f())
345
345
346 class templateformatter(baseformatter):
346 class templateformatter(baseformatter):
347 def __init__(self, ui, out, topic, opts):
347 def __init__(self, ui, out, topic, opts):
348 baseformatter.__init__(self, ui, topic, opts, _templateconverter)
348 baseformatter.__init__(self, ui, topic, opts, _templateconverter)
349 self._out = out
349 self._out = out
350 spec = lookuptemplate(ui, topic, opts.get('template', ''))
350 spec = lookuptemplate(ui, topic, opts.get('template', ''))
351 self._tref = spec.ref
351 self._tref = spec.ref
352 self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl)
352 self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl)
353 self._parts = templatepartsmap(spec, self._t,
354 ['docheader', 'docfooter'])
353 self._counter = itertools.count()
355 self._counter = itertools.count()
354 self._cache = {} # for templatekw/funcs to store reusable data
356 self._cache = {} # for templatekw/funcs to store reusable data
357 self._renderitem('docheader', {})
358
355 def context(self, **ctxs):
359 def context(self, **ctxs):
356 '''insert context objects to be used to render template keywords'''
360 '''insert context objects to be used to render template keywords'''
357 ctxs = pycompat.byteskwargs(ctxs)
361 ctxs = pycompat.byteskwargs(ctxs)
358 assert all(k == 'ctx' for k in ctxs)
362 assert all(k == 'ctx' for k in ctxs)
359 self._item.update(ctxs)
363 self._item.update(ctxs)
360
364
361 def _showitem(self):
365 def _showitem(self):
362 item = self._item.copy()
366 item = self._item.copy()
363 item['index'] = next(self._counter)
367 item['index'] = next(self._counter)
364 self._renderitem(self._tref, item)
368 self._renderitem(self._tref, item)
365
369
366 def _renderitem(self, ref, item):
370 def _renderitem(self, part, item):
371 if part not in self._parts:
372 return
373 ref = self._parts[part]
374
367 # TODO: add support for filectx. probably each template keyword or
375 # TODO: add support for filectx. probably each template keyword or
368 # function will have to declare dependent resources. e.g.
376 # function will have to declare dependent resources. e.g.
369 # @templatekeyword(..., requires=('ctx',))
377 # @templatekeyword(..., requires=('ctx',))
370 props = {}
378 props = {}
371 if 'ctx' in item:
379 if 'ctx' in item:
372 props.update(templatekw.keywords)
380 props.update(templatekw.keywords)
373 # explicitly-defined fields precede templatekw
381 # explicitly-defined fields precede templatekw
374 props.update(item)
382 props.update(item)
375 if 'ctx' in item:
383 if 'ctx' in item:
376 # but template resources must be always available
384 # but template resources must be always available
377 props['templ'] = self._t
385 props['templ'] = self._t
378 props['repo'] = props['ctx'].repo()
386 props['repo'] = props['ctx'].repo()
379 props['revcache'] = {}
387 props['revcache'] = {}
380 props = pycompat.strkwargs(props)
388 props = pycompat.strkwargs(props)
381 g = self._t(ref, ui=self._ui, cache=self._cache, **props)
389 g = self._t(ref, ui=self._ui, cache=self._cache, **props)
382 self._out.write(templater.stringify(g))
390 self._out.write(templater.stringify(g))
383
391
392 def end(self):
393 baseformatter.end(self)
394 self._renderitem('docfooter', {})
395
384 templatespec = collections.namedtuple(r'templatespec',
396 templatespec = collections.namedtuple(r'templatespec',
385 r'ref tmpl mapfile')
397 r'ref tmpl mapfile')
386
398
387 def lookuptemplate(ui, topic, tmpl):
399 def lookuptemplate(ui, topic, tmpl):
388 """Find the template matching the given -T/--template spec 'tmpl'
400 """Find the template matching the given -T/--template spec 'tmpl'
389
401
390 'tmpl' can be any of the following:
402 'tmpl' can be any of the following:
391
403
392 - a literal template (e.g. '{rev}')
404 - a literal template (e.g. '{rev}')
393 - a map-file name or path (e.g. 'changelog')
405 - a map-file name or path (e.g. 'changelog')
394 - a reference to [templates] in config file
406 - a reference to [templates] in config file
395 - a path to raw template file
407 - a path to raw template file
396
408
397 A map file defines a stand-alone template environment. If a map file
409 A map file defines a stand-alone template environment. If a map file
398 selected, all templates defined in the file will be loaded, and the
410 selected, all templates defined in the file will be loaded, and the
399 template matching the given topic will be rendered. No aliases will be
411 template matching the given topic will be rendered. No aliases will be
400 loaded from user config.
412 loaded from user config.
401
413
402 If no map file selected, all templates in [templates] section will be
414 If no map file selected, all templates in [templates] section will be
403 available as well as aliases in [templatealias].
415 available as well as aliases in [templatealias].
404 """
416 """
405
417
406 # looks like a literal template?
418 # looks like a literal template?
407 if '{' in tmpl:
419 if '{' in tmpl:
408 return templatespec('', tmpl, None)
420 return templatespec('', tmpl, None)
409
421
410 # perhaps a stock style?
422 # perhaps a stock style?
411 if not os.path.split(tmpl)[0]:
423 if not os.path.split(tmpl)[0]:
412 mapname = (templater.templatepath('map-cmdline.' + tmpl)
424 mapname = (templater.templatepath('map-cmdline.' + tmpl)
413 or templater.templatepath(tmpl))
425 or templater.templatepath(tmpl))
414 if mapname and os.path.isfile(mapname):
426 if mapname and os.path.isfile(mapname):
415 return templatespec(topic, None, mapname)
427 return templatespec(topic, None, mapname)
416
428
417 # perhaps it's a reference to [templates]
429 # perhaps it's a reference to [templates]
418 if ui.config('templates', tmpl):
430 if ui.config('templates', tmpl):
419 return templatespec(tmpl, None, None)
431 return templatespec(tmpl, None, None)
420
432
421 if tmpl == 'list':
433 if tmpl == 'list':
422 ui.write(_("available styles: %s\n") % templater.stylelist())
434 ui.write(_("available styles: %s\n") % templater.stylelist())
423 raise error.Abort(_("specify a template"))
435 raise error.Abort(_("specify a template"))
424
436
425 # perhaps it's a path to a map or a template
437 # perhaps it's a path to a map or a template
426 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
438 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
427 # is it a mapfile for a style?
439 # is it a mapfile for a style?
428 if os.path.basename(tmpl).startswith("map-"):
440 if os.path.basename(tmpl).startswith("map-"):
429 return templatespec(topic, None, os.path.realpath(tmpl))
441 return templatespec(topic, None, os.path.realpath(tmpl))
430 with util.posixfile(tmpl, 'rb') as f:
442 with util.posixfile(tmpl, 'rb') as f:
431 tmpl = f.read()
443 tmpl = f.read()
432 return templatespec('', tmpl, None)
444 return templatespec('', tmpl, None)
433
445
434 # constant string?
446 # constant string?
435 return templatespec('', tmpl, None)
447 return templatespec('', tmpl, None)
436
448
449 def templatepartsmap(spec, t, partnames):
450 """Create a mapping of {part: ref}"""
451 partsmap = {spec.ref: spec.ref} # initial ref must exist in t
452 if spec.mapfile:
453 partsmap.update((p, p) for p in partnames if p in t)
454 return partsmap
455
437 def loadtemplater(ui, spec, cache=None):
456 def loadtemplater(ui, spec, cache=None):
438 """Create a templater from either a literal template or loading from
457 """Create a templater from either a literal template or loading from
439 a map file"""
458 a map file"""
440 assert not (spec.tmpl and spec.mapfile)
459 assert not (spec.tmpl and spec.mapfile)
441 if spec.mapfile:
460 if spec.mapfile:
442 return templater.templater.frommapfile(spec.mapfile, cache=cache)
461 return templater.templater.frommapfile(spec.mapfile, cache=cache)
443 return maketemplater(ui, spec.tmpl, cache=cache)
462 return maketemplater(ui, spec.tmpl, cache=cache)
444
463
445 def maketemplater(ui, tmpl, cache=None):
464 def maketemplater(ui, tmpl, cache=None):
446 """Create a templater from a string template 'tmpl'"""
465 """Create a templater from a string template 'tmpl'"""
447 aliases = ui.configitems('templatealias')
466 aliases = ui.configitems('templatealias')
448 t = templater.templater(cache=cache, aliases=aliases)
467 t = templater.templater(cache=cache, aliases=aliases)
449 t.cache.update((k, templater.unquotestring(v))
468 t.cache.update((k, templater.unquotestring(v))
450 for k, v in ui.configitems('templates'))
469 for k, v in ui.configitems('templates'))
451 if tmpl:
470 if tmpl:
452 t.cache[''] = tmpl
471 t.cache[''] = tmpl
453 return t
472 return t
454
473
455 def formatter(ui, out, topic, opts):
474 def formatter(ui, out, topic, opts):
456 template = opts.get("template", "")
475 template = opts.get("template", "")
457 if template == "json":
476 if template == "json":
458 return jsonformatter(ui, out, topic, opts)
477 return jsonformatter(ui, out, topic, opts)
459 elif template == "pickle":
478 elif template == "pickle":
460 return pickleformatter(ui, out, topic, opts)
479 return pickleformatter(ui, out, topic, opts)
461 elif template == "debug":
480 elif template == "debug":
462 return debugformatter(ui, out, topic, opts)
481 return debugformatter(ui, out, topic, opts)
463 elif template != "":
482 elif template != "":
464 return templateformatter(ui, out, topic, opts)
483 return templateformatter(ui, out, topic, opts)
465 # developer config: ui.formatdebug
484 # developer config: ui.formatdebug
466 elif ui.configbool('ui', 'formatdebug'):
485 elif ui.configbool('ui', 'formatdebug'):
467 return debugformatter(ui, out, topic, opts)
486 return debugformatter(ui, out, topic, opts)
468 # deprecated config: ui.formatjson
487 # deprecated config: ui.formatjson
469 elif ui.configbool('ui', 'formatjson'):
488 elif ui.configbool('ui', 'formatjson'):
470 return jsonformatter(ui, out, topic, opts)
489 return jsonformatter(ui, out, topic, opts)
471 return plainformatter(ui, out, topic, opts)
490 return plainformatter(ui, out, topic, opts)
472
491
473 @contextlib.contextmanager
492 @contextlib.contextmanager
474 def openformatter(ui, filename, topic, opts):
493 def openformatter(ui, filename, topic, opts):
475 """Create a formatter that writes outputs to the specified file
494 """Create a formatter that writes outputs to the specified file
476
495
477 Must be invoked using the 'with' statement.
496 Must be invoked using the 'with' statement.
478 """
497 """
479 with util.posixfile(filename, 'wb') as out:
498 with util.posixfile(filename, 'wb') as out:
480 with formatter(ui, out, topic, opts) as fm:
499 with formatter(ui, out, topic, opts) as fm:
481 yield fm
500 yield fm
482
501
483 @contextlib.contextmanager
502 @contextlib.contextmanager
484 def _neverending(fm):
503 def _neverending(fm):
485 yield fm
504 yield fm
486
505
487 def maybereopen(fm, filename, opts):
506 def maybereopen(fm, filename, opts):
488 """Create a formatter backed by file if filename specified, else return
507 """Create a formatter backed by file if filename specified, else return
489 the given formatter
508 the given formatter
490
509
491 Must be invoked using the 'with' statement. This will never call fm.end()
510 Must be invoked using the 'with' statement. This will never call fm.end()
492 of the given formatter.
511 of the given formatter.
493 """
512 """
494 if filename:
513 if filename:
495 return openformatter(fm._ui, filename, fm._topic, opts)
514 return openformatter(fm._ui, filename, fm._topic, opts)
496 else:
515 else:
497 return _neverending(fm)
516 return _neverending(fm)
@@ -1,727 +1,740 b''
1 $ hg init a
1 $ hg init a
2 $ cd a
2 $ cd a
3
3
4 Verify checking branch of nullrev before the cache is created doesnt crash
4 Verify checking branch of nullrev before the cache is created doesnt crash
5 $ hg log -r 'branch(.)' -T '{branch}\n'
5 $ hg log -r 'branch(.)' -T '{branch}\n'
6
6
7 Basic test
7 Basic test
8 $ echo 'root' >root
8 $ echo 'root' >root
9 $ hg add root
9 $ hg add root
10 $ hg commit -d '0 0' -m "Adding root node"
10 $ hg commit -d '0 0' -m "Adding root node"
11
11
12 $ echo 'a' >a
12 $ echo 'a' >a
13 $ hg add a
13 $ hg add a
14 $ hg branch a
14 $ hg branch a
15 marked working directory as branch a
15 marked working directory as branch a
16 (branches are permanent and global, did you want a bookmark?)
16 (branches are permanent and global, did you want a bookmark?)
17 $ hg commit -d '1 0' -m "Adding a branch"
17 $ hg commit -d '1 0' -m "Adding a branch"
18
18
19 $ hg branch q
19 $ hg branch q
20 marked working directory as branch q
20 marked working directory as branch q
21 $ echo 'aa' >a
21 $ echo 'aa' >a
22 $ hg branch -C
22 $ hg branch -C
23 reset working directory to branch a
23 reset working directory to branch a
24 $ hg commit -d '2 0' -m "Adding to a branch"
24 $ hg commit -d '2 0' -m "Adding to a branch"
25
25
26 $ hg update -C 0
26 $ hg update -C 0
27 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
27 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
28 $ echo 'b' >b
28 $ echo 'b' >b
29 $ hg add b
29 $ hg add b
30 $ hg branch b
30 $ hg branch b
31 marked working directory as branch b
31 marked working directory as branch b
32 $ hg commit -d '2 0' -m "Adding b branch"
32 $ hg commit -d '2 0' -m "Adding b branch"
33
33
34 $ echo 'bh1' >bh1
34 $ echo 'bh1' >bh1
35 $ hg add bh1
35 $ hg add bh1
36 $ hg commit -d '3 0' -m "Adding b branch head 1"
36 $ hg commit -d '3 0' -m "Adding b branch head 1"
37
37
38 $ hg update -C 2
38 $ hg update -C 2
39 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
39 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
40 $ echo 'bh2' >bh2
40 $ echo 'bh2' >bh2
41 $ hg add bh2
41 $ hg add bh2
42 $ hg commit -d '4 0' -m "Adding b branch head 2"
42 $ hg commit -d '4 0' -m "Adding b branch head 2"
43
43
44 $ echo 'c' >c
44 $ echo 'c' >c
45 $ hg add c
45 $ hg add c
46 $ hg branch c
46 $ hg branch c
47 marked working directory as branch c
47 marked working directory as branch c
48 $ hg commit -d '5 0' -m "Adding c branch"
48 $ hg commit -d '5 0' -m "Adding c branch"
49
49
50 reserved names
50 reserved names
51
51
52 $ hg branch tip
52 $ hg branch tip
53 abort: the name 'tip' is reserved
53 abort: the name 'tip' is reserved
54 [255]
54 [255]
55 $ hg branch null
55 $ hg branch null
56 abort: the name 'null' is reserved
56 abort: the name 'null' is reserved
57 [255]
57 [255]
58 $ hg branch .
58 $ hg branch .
59 abort: the name '.' is reserved
59 abort: the name '.' is reserved
60 [255]
60 [255]
61
61
62 invalid characters
62 invalid characters
63
63
64 $ hg branch 'foo:bar'
64 $ hg branch 'foo:bar'
65 abort: ':' cannot be used in a name
65 abort: ':' cannot be used in a name
66 [255]
66 [255]
67
67
68 $ hg branch 'foo
68 $ hg branch 'foo
69 > bar'
69 > bar'
70 abort: '\n' cannot be used in a name
70 abort: '\n' cannot be used in a name
71 [255]
71 [255]
72
72
73 trailing or leading spaces should be stripped before testing duplicates
73 trailing or leading spaces should be stripped before testing duplicates
74
74
75 $ hg branch 'b '
75 $ hg branch 'b '
76 abort: a branch of the same name already exists
76 abort: a branch of the same name already exists
77 (use 'hg update' to switch to it)
77 (use 'hg update' to switch to it)
78 [255]
78 [255]
79
79
80 $ hg branch ' b'
80 $ hg branch ' b'
81 abort: a branch of the same name already exists
81 abort: a branch of the same name already exists
82 (use 'hg update' to switch to it)
82 (use 'hg update' to switch to it)
83 [255]
83 [255]
84
84
85 verify update will accept invalid legacy branch names
85 verify update will accept invalid legacy branch names
86
86
87 $ hg init test-invalid-branch-name
87 $ hg init test-invalid-branch-name
88 $ cd test-invalid-branch-name
88 $ cd test-invalid-branch-name
89 $ hg pull -u "$TESTDIR"/bundles/test-invalid-branch-name.hg
89 $ hg pull -u "$TESTDIR"/bundles/test-invalid-branch-name.hg
90 pulling from *test-invalid-branch-name.hg (glob)
90 pulling from *test-invalid-branch-name.hg (glob)
91 requesting all changes
91 requesting all changes
92 adding changesets
92 adding changesets
93 adding manifests
93 adding manifests
94 adding file changes
94 adding file changes
95 added 3 changesets with 3 changes to 2 files
95 added 3 changesets with 3 changes to 2 files
96 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
96 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
97
97
98 $ hg update '"colon:test"'
98 $ hg update '"colon:test"'
99 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
99 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
100 $ cd ..
100 $ cd ..
101
101
102 $ echo 'd' >d
102 $ echo 'd' >d
103 $ hg add d
103 $ hg add d
104 $ hg branch 'a branch name much longer than the default justification used by branches'
104 $ hg branch 'a branch name much longer than the default justification used by branches'
105 marked working directory as branch a branch name much longer than the default justification used by branches
105 marked working directory as branch a branch name much longer than the default justification used by branches
106 $ hg commit -d '6 0' -m "Adding d branch"
106 $ hg commit -d '6 0' -m "Adding d branch"
107
107
108 $ hg branches
108 $ hg branches
109 a branch name much longer than the default justification used by branches 7:10ff5895aa57
109 a branch name much longer than the default justification used by branches 7:10ff5895aa57
110 b 4:aee39cd168d0
110 b 4:aee39cd168d0
111 c 6:589736a22561 (inactive)
111 c 6:589736a22561 (inactive)
112 a 5:d8cbc61dbaa6 (inactive)
112 a 5:d8cbc61dbaa6 (inactive)
113 default 0:19709c5a4e75 (inactive)
113 default 0:19709c5a4e75 (inactive)
114
114
115 -------
115 -------
116
116
117 $ hg branches -a
117 $ hg branches -a
118 a branch name much longer than the default justification used by branches 7:10ff5895aa57
118 a branch name much longer than the default justification used by branches 7:10ff5895aa57
119 b 4:aee39cd168d0
119 b 4:aee39cd168d0
120
120
121 --- Branch a
121 --- Branch a
122
122
123 $ hg log -b a
123 $ hg log -b a
124 changeset: 5:d8cbc61dbaa6
124 changeset: 5:d8cbc61dbaa6
125 branch: a
125 branch: a
126 parent: 2:881fe2b92ad0
126 parent: 2:881fe2b92ad0
127 user: test
127 user: test
128 date: Thu Jan 01 00:00:04 1970 +0000
128 date: Thu Jan 01 00:00:04 1970 +0000
129 summary: Adding b branch head 2
129 summary: Adding b branch head 2
130
130
131 changeset: 2:881fe2b92ad0
131 changeset: 2:881fe2b92ad0
132 branch: a
132 branch: a
133 user: test
133 user: test
134 date: Thu Jan 01 00:00:02 1970 +0000
134 date: Thu Jan 01 00:00:02 1970 +0000
135 summary: Adding to a branch
135 summary: Adding to a branch
136
136
137 changeset: 1:dd6b440dd85a
137 changeset: 1:dd6b440dd85a
138 branch: a
138 branch: a
139 user: test
139 user: test
140 date: Thu Jan 01 00:00:01 1970 +0000
140 date: Thu Jan 01 00:00:01 1970 +0000
141 summary: Adding a branch
141 summary: Adding a branch
142
142
143
143
144 ---- Branch b
144 ---- Branch b
145
145
146 $ hg log -b b
146 $ hg log -b b
147 changeset: 4:aee39cd168d0
147 changeset: 4:aee39cd168d0
148 branch: b
148 branch: b
149 user: test
149 user: test
150 date: Thu Jan 01 00:00:03 1970 +0000
150 date: Thu Jan 01 00:00:03 1970 +0000
151 summary: Adding b branch head 1
151 summary: Adding b branch head 1
152
152
153 changeset: 3:ac22033332d1
153 changeset: 3:ac22033332d1
154 branch: b
154 branch: b
155 parent: 0:19709c5a4e75
155 parent: 0:19709c5a4e75
156 user: test
156 user: test
157 date: Thu Jan 01 00:00:02 1970 +0000
157 date: Thu Jan 01 00:00:02 1970 +0000
158 summary: Adding b branch
158 summary: Adding b branch
159
159
160
160
161 ---- going to test branch closing
161 ---- going to test branch closing
162
162
163 $ hg branches
163 $ hg branches
164 a branch name much longer than the default justification used by branches 7:10ff5895aa57
164 a branch name much longer than the default justification used by branches 7:10ff5895aa57
165 b 4:aee39cd168d0
165 b 4:aee39cd168d0
166 c 6:589736a22561 (inactive)
166 c 6:589736a22561 (inactive)
167 a 5:d8cbc61dbaa6 (inactive)
167 a 5:d8cbc61dbaa6 (inactive)
168 default 0:19709c5a4e75 (inactive)
168 default 0:19709c5a4e75 (inactive)
169 $ hg up -C b
169 $ hg up -C b
170 2 files updated, 0 files merged, 4 files removed, 0 files unresolved
170 2 files updated, 0 files merged, 4 files removed, 0 files unresolved
171 $ echo 'xxx1' >> b
171 $ echo 'xxx1' >> b
172 $ hg commit -d '7 0' -m 'adding cset to branch b'
172 $ hg commit -d '7 0' -m 'adding cset to branch b'
173 $ hg up -C aee39cd168d0
173 $ hg up -C aee39cd168d0
174 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
174 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
175 $ echo 'xxx2' >> b
175 $ echo 'xxx2' >> b
176 $ hg commit -d '8 0' -m 'adding head to branch b'
176 $ hg commit -d '8 0' -m 'adding head to branch b'
177 created new head
177 created new head
178 $ echo 'xxx3' >> b
178 $ echo 'xxx3' >> b
179 $ hg commit -d '9 0' -m 'adding another cset to branch b'
179 $ hg commit -d '9 0' -m 'adding another cset to branch b'
180 $ hg branches
180 $ hg branches
181 b 10:bfbe841b666e
181 b 10:bfbe841b666e
182 a branch name much longer than the default justification used by branches 7:10ff5895aa57
182 a branch name much longer than the default justification used by branches 7:10ff5895aa57
183 c 6:589736a22561 (inactive)
183 c 6:589736a22561 (inactive)
184 a 5:d8cbc61dbaa6 (inactive)
184 a 5:d8cbc61dbaa6 (inactive)
185 default 0:19709c5a4e75 (inactive)
185 default 0:19709c5a4e75 (inactive)
186 $ hg heads --closed
186 $ hg heads --closed
187 changeset: 10:bfbe841b666e
187 changeset: 10:bfbe841b666e
188 branch: b
188 branch: b
189 tag: tip
189 tag: tip
190 user: test
190 user: test
191 date: Thu Jan 01 00:00:09 1970 +0000
191 date: Thu Jan 01 00:00:09 1970 +0000
192 summary: adding another cset to branch b
192 summary: adding another cset to branch b
193
193
194 changeset: 8:eebb944467c9
194 changeset: 8:eebb944467c9
195 branch: b
195 branch: b
196 parent: 4:aee39cd168d0
196 parent: 4:aee39cd168d0
197 user: test
197 user: test
198 date: Thu Jan 01 00:00:07 1970 +0000
198 date: Thu Jan 01 00:00:07 1970 +0000
199 summary: adding cset to branch b
199 summary: adding cset to branch b
200
200
201 changeset: 7:10ff5895aa57
201 changeset: 7:10ff5895aa57
202 branch: a branch name much longer than the default justification used by branches
202 branch: a branch name much longer than the default justification used by branches
203 user: test
203 user: test
204 date: Thu Jan 01 00:00:06 1970 +0000
204 date: Thu Jan 01 00:00:06 1970 +0000
205 summary: Adding d branch
205 summary: Adding d branch
206
206
207 changeset: 6:589736a22561
207 changeset: 6:589736a22561
208 branch: c
208 branch: c
209 user: test
209 user: test
210 date: Thu Jan 01 00:00:05 1970 +0000
210 date: Thu Jan 01 00:00:05 1970 +0000
211 summary: Adding c branch
211 summary: Adding c branch
212
212
213 changeset: 5:d8cbc61dbaa6
213 changeset: 5:d8cbc61dbaa6
214 branch: a
214 branch: a
215 parent: 2:881fe2b92ad0
215 parent: 2:881fe2b92ad0
216 user: test
216 user: test
217 date: Thu Jan 01 00:00:04 1970 +0000
217 date: Thu Jan 01 00:00:04 1970 +0000
218 summary: Adding b branch head 2
218 summary: Adding b branch head 2
219
219
220 changeset: 0:19709c5a4e75
220 changeset: 0:19709c5a4e75
221 user: test
221 user: test
222 date: Thu Jan 01 00:00:00 1970 +0000
222 date: Thu Jan 01 00:00:00 1970 +0000
223 summary: Adding root node
223 summary: Adding root node
224
224
225 $ hg heads
225 $ hg heads
226 changeset: 10:bfbe841b666e
226 changeset: 10:bfbe841b666e
227 branch: b
227 branch: b
228 tag: tip
228 tag: tip
229 user: test
229 user: test
230 date: Thu Jan 01 00:00:09 1970 +0000
230 date: Thu Jan 01 00:00:09 1970 +0000
231 summary: adding another cset to branch b
231 summary: adding another cset to branch b
232
232
233 changeset: 8:eebb944467c9
233 changeset: 8:eebb944467c9
234 branch: b
234 branch: b
235 parent: 4:aee39cd168d0
235 parent: 4:aee39cd168d0
236 user: test
236 user: test
237 date: Thu Jan 01 00:00:07 1970 +0000
237 date: Thu Jan 01 00:00:07 1970 +0000
238 summary: adding cset to branch b
238 summary: adding cset to branch b
239
239
240 changeset: 7:10ff5895aa57
240 changeset: 7:10ff5895aa57
241 branch: a branch name much longer than the default justification used by branches
241 branch: a branch name much longer than the default justification used by branches
242 user: test
242 user: test
243 date: Thu Jan 01 00:00:06 1970 +0000
243 date: Thu Jan 01 00:00:06 1970 +0000
244 summary: Adding d branch
244 summary: Adding d branch
245
245
246 changeset: 6:589736a22561
246 changeset: 6:589736a22561
247 branch: c
247 branch: c
248 user: test
248 user: test
249 date: Thu Jan 01 00:00:05 1970 +0000
249 date: Thu Jan 01 00:00:05 1970 +0000
250 summary: Adding c branch
250 summary: Adding c branch
251
251
252 changeset: 5:d8cbc61dbaa6
252 changeset: 5:d8cbc61dbaa6
253 branch: a
253 branch: a
254 parent: 2:881fe2b92ad0
254 parent: 2:881fe2b92ad0
255 user: test
255 user: test
256 date: Thu Jan 01 00:00:04 1970 +0000
256 date: Thu Jan 01 00:00:04 1970 +0000
257 summary: Adding b branch head 2
257 summary: Adding b branch head 2
258
258
259 changeset: 0:19709c5a4e75
259 changeset: 0:19709c5a4e75
260 user: test
260 user: test
261 date: Thu Jan 01 00:00:00 1970 +0000
261 date: Thu Jan 01 00:00:00 1970 +0000
262 summary: Adding root node
262 summary: Adding root node
263
263
264 $ hg commit -d '9 0' --close-branch -m 'prune bad branch'
264 $ hg commit -d '9 0' --close-branch -m 'prune bad branch'
265 $ hg branches -a
265 $ hg branches -a
266 b 8:eebb944467c9
266 b 8:eebb944467c9
267 a branch name much longer than the default justification used by branches 7:10ff5895aa57
267 a branch name much longer than the default justification used by branches 7:10ff5895aa57
268 $ hg up -C b
268 $ hg up -C b
269 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
269 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
270 $ hg commit -d '9 0' --close-branch -m 'close this part branch too'
270 $ hg commit -d '9 0' --close-branch -m 'close this part branch too'
271 $ hg commit -d '9 0' --close-branch -m 're-closing this branch'
271 $ hg commit -d '9 0' --close-branch -m 're-closing this branch'
272 abort: can only close branch heads
272 abort: can only close branch heads
273 [255]
273 [255]
274
274
275 $ hg log -r tip --debug
275 $ hg log -r tip --debug
276 changeset: 12:e3d49c0575d8fc2cb1cd6859c747c14f5f6d499f
276 changeset: 12:e3d49c0575d8fc2cb1cd6859c747c14f5f6d499f
277 branch: b
277 branch: b
278 tag: tip
278 tag: tip
279 phase: draft
279 phase: draft
280 parent: 8:eebb944467c9fb9651ed232aeaf31b3c0a7fc6c1
280 parent: 8:eebb944467c9fb9651ed232aeaf31b3c0a7fc6c1
281 parent: -1:0000000000000000000000000000000000000000
281 parent: -1:0000000000000000000000000000000000000000
282 manifest: 8:6f9ed32d2b310e391a4f107d5f0f071df785bfee
282 manifest: 8:6f9ed32d2b310e391a4f107d5f0f071df785bfee
283 user: test
283 user: test
284 date: Thu Jan 01 00:00:09 1970 +0000
284 date: Thu Jan 01 00:00:09 1970 +0000
285 extra: branch=b
285 extra: branch=b
286 extra: close=1
286 extra: close=1
287 description:
287 description:
288 close this part branch too
288 close this part branch too
289
289
290
290
291 --- b branch should be inactive
291 --- b branch should be inactive
292
292
293 $ hg branches
293 $ hg branches
294 a branch name much longer than the default justification used by branches 7:10ff5895aa57
294 a branch name much longer than the default justification used by branches 7:10ff5895aa57
295 c 6:589736a22561 (inactive)
295 c 6:589736a22561 (inactive)
296 a 5:d8cbc61dbaa6 (inactive)
296 a 5:d8cbc61dbaa6 (inactive)
297 default 0:19709c5a4e75 (inactive)
297 default 0:19709c5a4e75 (inactive)
298 $ hg branches -c
298 $ hg branches -c
299 a branch name much longer than the default justification used by branches 7:10ff5895aa57
299 a branch name much longer than the default justification used by branches 7:10ff5895aa57
300 b 12:e3d49c0575d8 (closed)
300 b 12:e3d49c0575d8 (closed)
301 c 6:589736a22561 (inactive)
301 c 6:589736a22561 (inactive)
302 a 5:d8cbc61dbaa6 (inactive)
302 a 5:d8cbc61dbaa6 (inactive)
303 default 0:19709c5a4e75 (inactive)
303 default 0:19709c5a4e75 (inactive)
304 $ hg branches -a
304 $ hg branches -a
305 a branch name much longer than the default justification used by branches 7:10ff5895aa57
305 a branch name much longer than the default justification used by branches 7:10ff5895aa57
306 $ hg branches -q
306 $ hg branches -q
307 a branch name much longer than the default justification used by branches
307 a branch name much longer than the default justification used by branches
308 c
308 c
309 a
309 a
310 default
310 default
311 $ hg heads b
311 $ hg heads b
312 no open branch heads found on branches b
312 no open branch heads found on branches b
313 [1]
313 [1]
314 $ hg heads --closed b
314 $ hg heads --closed b
315 changeset: 12:e3d49c0575d8
315 changeset: 12:e3d49c0575d8
316 branch: b
316 branch: b
317 tag: tip
317 tag: tip
318 parent: 8:eebb944467c9
318 parent: 8:eebb944467c9
319 user: test
319 user: test
320 date: Thu Jan 01 00:00:09 1970 +0000
320 date: Thu Jan 01 00:00:09 1970 +0000
321 summary: close this part branch too
321 summary: close this part branch too
322
322
323 changeset: 11:d3f163457ebf
323 changeset: 11:d3f163457ebf
324 branch: b
324 branch: b
325 user: test
325 user: test
326 date: Thu Jan 01 00:00:09 1970 +0000
326 date: Thu Jan 01 00:00:09 1970 +0000
327 summary: prune bad branch
327 summary: prune bad branch
328
328
329 $ echo 'xxx4' >> b
329 $ echo 'xxx4' >> b
330 $ hg commit -d '9 0' -m 'reopen branch with a change'
330 $ hg commit -d '9 0' -m 'reopen branch with a change'
331 reopening closed branch head 12
331 reopening closed branch head 12
332
332
333 --- branch b is back in action
333 --- branch b is back in action
334
334
335 $ hg branches -a
335 $ hg branches -a
336 b 13:e23b5505d1ad
336 b 13:e23b5505d1ad
337 a branch name much longer than the default justification used by branches 7:10ff5895aa57
337 a branch name much longer than the default justification used by branches 7:10ff5895aa57
338
338
339 ---- test heads listings
339 ---- test heads listings
340
340
341 $ hg heads
341 $ hg heads
342 changeset: 13:e23b5505d1ad
342 changeset: 13:e23b5505d1ad
343 branch: b
343 branch: b
344 tag: tip
344 tag: tip
345 user: test
345 user: test
346 date: Thu Jan 01 00:00:09 1970 +0000
346 date: Thu Jan 01 00:00:09 1970 +0000
347 summary: reopen branch with a change
347 summary: reopen branch with a change
348
348
349 changeset: 7:10ff5895aa57
349 changeset: 7:10ff5895aa57
350 branch: a branch name much longer than the default justification used by branches
350 branch: a branch name much longer than the default justification used by branches
351 user: test
351 user: test
352 date: Thu Jan 01 00:00:06 1970 +0000
352 date: Thu Jan 01 00:00:06 1970 +0000
353 summary: Adding d branch
353 summary: Adding d branch
354
354
355 changeset: 6:589736a22561
355 changeset: 6:589736a22561
356 branch: c
356 branch: c
357 user: test
357 user: test
358 date: Thu Jan 01 00:00:05 1970 +0000
358 date: Thu Jan 01 00:00:05 1970 +0000
359 summary: Adding c branch
359 summary: Adding c branch
360
360
361 changeset: 5:d8cbc61dbaa6
361 changeset: 5:d8cbc61dbaa6
362 branch: a
362 branch: a
363 parent: 2:881fe2b92ad0
363 parent: 2:881fe2b92ad0
364 user: test
364 user: test
365 date: Thu Jan 01 00:00:04 1970 +0000
365 date: Thu Jan 01 00:00:04 1970 +0000
366 summary: Adding b branch head 2
366 summary: Adding b branch head 2
367
367
368 changeset: 0:19709c5a4e75
368 changeset: 0:19709c5a4e75
369 user: test
369 user: test
370 date: Thu Jan 01 00:00:00 1970 +0000
370 date: Thu Jan 01 00:00:00 1970 +0000
371 summary: Adding root node
371 summary: Adding root node
372
372
373
373
374 branch default
374 branch default
375
375
376 $ hg heads default
376 $ hg heads default
377 changeset: 0:19709c5a4e75
377 changeset: 0:19709c5a4e75
378 user: test
378 user: test
379 date: Thu Jan 01 00:00:00 1970 +0000
379 date: Thu Jan 01 00:00:00 1970 +0000
380 summary: Adding root node
380 summary: Adding root node
381
381
382
382
383 branch a
383 branch a
384
384
385 $ hg heads a
385 $ hg heads a
386 changeset: 5:d8cbc61dbaa6
386 changeset: 5:d8cbc61dbaa6
387 branch: a
387 branch: a
388 parent: 2:881fe2b92ad0
388 parent: 2:881fe2b92ad0
389 user: test
389 user: test
390 date: Thu Jan 01 00:00:04 1970 +0000
390 date: Thu Jan 01 00:00:04 1970 +0000
391 summary: Adding b branch head 2
391 summary: Adding b branch head 2
392
392
393 $ hg heads --active a
393 $ hg heads --active a
394 no open branch heads found on branches a
394 no open branch heads found on branches a
395 [1]
395 [1]
396
396
397 branch b
397 branch b
398
398
399 $ hg heads b
399 $ hg heads b
400 changeset: 13:e23b5505d1ad
400 changeset: 13:e23b5505d1ad
401 branch: b
401 branch: b
402 tag: tip
402 tag: tip
403 user: test
403 user: test
404 date: Thu Jan 01 00:00:09 1970 +0000
404 date: Thu Jan 01 00:00:09 1970 +0000
405 summary: reopen branch with a change
405 summary: reopen branch with a change
406
406
407 $ hg heads --closed b
407 $ hg heads --closed b
408 changeset: 13:e23b5505d1ad
408 changeset: 13:e23b5505d1ad
409 branch: b
409 branch: b
410 tag: tip
410 tag: tip
411 user: test
411 user: test
412 date: Thu Jan 01 00:00:09 1970 +0000
412 date: Thu Jan 01 00:00:09 1970 +0000
413 summary: reopen branch with a change
413 summary: reopen branch with a change
414
414
415 changeset: 11:d3f163457ebf
415 changeset: 11:d3f163457ebf
416 branch: b
416 branch: b
417 user: test
417 user: test
418 date: Thu Jan 01 00:00:09 1970 +0000
418 date: Thu Jan 01 00:00:09 1970 +0000
419 summary: prune bad branch
419 summary: prune bad branch
420
420
421 default branch colors:
421 default branch colors:
422
422
423 $ cat <<EOF >> $HGRCPATH
423 $ cat <<EOF >> $HGRCPATH
424 > [extensions]
424 > [extensions]
425 > color =
425 > color =
426 > [color]
426 > [color]
427 > mode = ansi
427 > mode = ansi
428 > EOF
428 > EOF
429
429
430 $ hg up -C c
430 $ hg up -C c
431 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
431 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
432 $ hg commit -d '9 0' --close-branch -m 'reclosing this branch'
432 $ hg commit -d '9 0' --close-branch -m 'reclosing this branch'
433 $ hg up -C b
433 $ hg up -C b
434 2 files updated, 0 files merged, 3 files removed, 0 files unresolved
434 2 files updated, 0 files merged, 3 files removed, 0 files unresolved
435 $ hg branches --color=always
435 $ hg branches --color=always
436 \x1b[0;32mb\x1b[0m\x1b[0;33m 13:e23b5505d1ad\x1b[0m (esc)
436 \x1b[0;32mb\x1b[0m\x1b[0;33m 13:e23b5505d1ad\x1b[0m (esc)
437 \x1b[0;0ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;33m 7:10ff5895aa57\x1b[0m (esc)
437 \x1b[0;0ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;33m 7:10ff5895aa57\x1b[0m (esc)
438 \x1b[0;0ma\x1b[0m\x1b[0;33m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
438 \x1b[0;0ma\x1b[0m\x1b[0;33m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
439 \x1b[0;0mdefault\x1b[0m\x1b[0;33m 0:19709c5a4e75\x1b[0m (inactive) (esc)
439 \x1b[0;0mdefault\x1b[0m\x1b[0;33m 0:19709c5a4e75\x1b[0m (inactive) (esc)
440
440
441 default closed branch color:
441 default closed branch color:
442
442
443 $ hg branches --color=always --closed
443 $ hg branches --color=always --closed
444 \x1b[0;32mb\x1b[0m\x1b[0;33m 13:e23b5505d1ad\x1b[0m (esc)
444 \x1b[0;32mb\x1b[0m\x1b[0;33m 13:e23b5505d1ad\x1b[0m (esc)
445 \x1b[0;0ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;33m 7:10ff5895aa57\x1b[0m (esc)
445 \x1b[0;0ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;33m 7:10ff5895aa57\x1b[0m (esc)
446 \x1b[0;30;1mc\x1b[0m\x1b[0;33m 14:f894c25619d3\x1b[0m (closed) (esc)
446 \x1b[0;30;1mc\x1b[0m\x1b[0;33m 14:f894c25619d3\x1b[0m (closed) (esc)
447 \x1b[0;0ma\x1b[0m\x1b[0;33m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
447 \x1b[0;0ma\x1b[0m\x1b[0;33m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
448 \x1b[0;0mdefault\x1b[0m\x1b[0;33m 0:19709c5a4e75\x1b[0m (inactive) (esc)
448 \x1b[0;0mdefault\x1b[0m\x1b[0;33m 0:19709c5a4e75\x1b[0m (inactive) (esc)
449
449
450 $ cat <<EOF >> $HGRCPATH
450 $ cat <<EOF >> $HGRCPATH
451 > [extensions]
451 > [extensions]
452 > color =
452 > color =
453 > [color]
453 > [color]
454 > branches.active = green
454 > branches.active = green
455 > branches.closed = blue
455 > branches.closed = blue
456 > branches.current = red
456 > branches.current = red
457 > branches.inactive = magenta
457 > branches.inactive = magenta
458 > log.changeset = cyan
458 > log.changeset = cyan
459 > EOF
459 > EOF
460
460
461 custom branch colors:
461 custom branch colors:
462
462
463 $ hg branches --color=always
463 $ hg branches --color=always
464 \x1b[0;31mb\x1b[0m\x1b[0;36m 13:e23b5505d1ad\x1b[0m (esc)
464 \x1b[0;31mb\x1b[0m\x1b[0;36m 13:e23b5505d1ad\x1b[0m (esc)
465 \x1b[0;32ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;36m 7:10ff5895aa57\x1b[0m (esc)
465 \x1b[0;32ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;36m 7:10ff5895aa57\x1b[0m (esc)
466 \x1b[0;35ma\x1b[0m\x1b[0;36m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
466 \x1b[0;35ma\x1b[0m\x1b[0;36m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
467 \x1b[0;35mdefault\x1b[0m\x1b[0;36m 0:19709c5a4e75\x1b[0m (inactive) (esc)
467 \x1b[0;35mdefault\x1b[0m\x1b[0;36m 0:19709c5a4e75\x1b[0m (inactive) (esc)
468
468
469 custom closed branch color:
469 custom closed branch color:
470
470
471 $ hg branches --color=always --closed
471 $ hg branches --color=always --closed
472 \x1b[0;31mb\x1b[0m\x1b[0;36m 13:e23b5505d1ad\x1b[0m (esc)
472 \x1b[0;31mb\x1b[0m\x1b[0;36m 13:e23b5505d1ad\x1b[0m (esc)
473 \x1b[0;32ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;36m 7:10ff5895aa57\x1b[0m (esc)
473 \x1b[0;32ma branch name much longer than the default justification used by branches\x1b[0m\x1b[0;36m 7:10ff5895aa57\x1b[0m (esc)
474 \x1b[0;34mc\x1b[0m\x1b[0;36m 14:f894c25619d3\x1b[0m (closed) (esc)
474 \x1b[0;34mc\x1b[0m\x1b[0;36m 14:f894c25619d3\x1b[0m (closed) (esc)
475 \x1b[0;35ma\x1b[0m\x1b[0;36m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
475 \x1b[0;35ma\x1b[0m\x1b[0;36m 5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
476 \x1b[0;35mdefault\x1b[0m\x1b[0;36m 0:19709c5a4e75\x1b[0m (inactive) (esc)
476 \x1b[0;35mdefault\x1b[0m\x1b[0;36m 0:19709c5a4e75\x1b[0m (inactive) (esc)
477
477
478 template output:
478 template output:
479
479
480 $ hg branches -Tjson --closed
480 $ hg branches -Tjson --closed
481 [
481 [
482 {
482 {
483 "active": true,
483 "active": true,
484 "branch": "b",
484 "branch": "b",
485 "closed": false,
485 "closed": false,
486 "current": true,
486 "current": true,
487 "node": "e23b5505d1ad24aab6f84fd8c7cb8cd8e5e93be0",
487 "node": "e23b5505d1ad24aab6f84fd8c7cb8cd8e5e93be0",
488 "rev": 13
488 "rev": 13
489 },
489 },
490 {
490 {
491 "active": true,
491 "active": true,
492 "branch": "a branch name much longer than the default justification used by branches",
492 "branch": "a branch name much longer than the default justification used by branches",
493 "closed": false,
493 "closed": false,
494 "current": false,
494 "current": false,
495 "node": "10ff5895aa5793bd378da574af8cec8ea408d831",
495 "node": "10ff5895aa5793bd378da574af8cec8ea408d831",
496 "rev": 7
496 "rev": 7
497 },
497 },
498 {
498 {
499 "active": false,
499 "active": false,
500 "branch": "c",
500 "branch": "c",
501 "closed": true,
501 "closed": true,
502 "current": false,
502 "current": false,
503 "node": "f894c25619d3f1484639d81be950e0a07bc6f1f6",
503 "node": "f894c25619d3f1484639d81be950e0a07bc6f1f6",
504 "rev": 14
504 "rev": 14
505 },
505 },
506 {
506 {
507 "active": false,
507 "active": false,
508 "branch": "a",
508 "branch": "a",
509 "closed": false,
509 "closed": false,
510 "current": false,
510 "current": false,
511 "node": "d8cbc61dbaa6dc817175d1e301eecb863f280832",
511 "node": "d8cbc61dbaa6dc817175d1e301eecb863f280832",
512 "rev": 5
512 "rev": 5
513 },
513 },
514 {
514 {
515 "active": false,
515 "active": false,
516 "branch": "default",
516 "branch": "default",
517 "closed": false,
517 "closed": false,
518 "current": false,
518 "current": false,
519 "node": "19709c5a4e75bf938f8e349aff97438539bb729e",
519 "node": "19709c5a4e75bf938f8e349aff97438539bb729e",
520 "rev": 0
520 "rev": 0
521 }
521 }
522 ]
522 ]
523
523
524 $ hg branches --closed -T '{if(closed, "{branch}\n")}'
524 $ hg branches --closed -T '{if(closed, "{branch}\n")}'
525 c
525 c
526
526
527 $ hg branches -T '{word(0, branch)}: {desc|firstline}\n'
527 $ hg branches -T '{word(0, branch)}: {desc|firstline}\n'
528 b: reopen branch with a change
528 b: reopen branch with a change
529 a: Adding d branch
529 a: Adding d branch
530 a: Adding b branch head 2
530 a: Adding b branch head 2
531 default: Adding root node
531 default: Adding root node
532
532
533 $ cat <<'EOF' > "$TESTTMP/map-myjson"
534 > docheader = '\{\n'
535 > docfooter = '\n}\n'
536 > branches = '{ifeq(index, 0, "", ",\n")} {dict(branch, node|short)|json}'
537 > EOF
538 $ hg branches -T "$TESTTMP/map-myjson"
539 {
540 {"branch": "b", "node": "e23b5505d1ad"},
541 {"branch": "a branch *", "node": "10ff5895aa57"}, (glob)
542 {"branch": "a", "node": "d8cbc61dbaa6"},
543 {"branch": "default", "node": "19709c5a4e75"}
544 }
545
533 Tests of revision branch name caching
546 Tests of revision branch name caching
534
547
535 We rev branch cache is updated automatically. In these tests we use a trick to
548 We rev branch cache is updated automatically. In these tests we use a trick to
536 trigger rebuilds. We remove the branch head cache and run 'hg head' to cause a
549 trigger rebuilds. We remove the branch head cache and run 'hg head' to cause a
537 rebuild that also will populate the rev branch cache.
550 rebuild that also will populate the rev branch cache.
538
551
539 revision branch cache is created when building the branch head cache
552 revision branch cache is created when building the branch head cache
540 $ rm -rf .hg/cache; hg head a -T '{rev}\n'
553 $ rm -rf .hg/cache; hg head a -T '{rev}\n'
541 5
554 5
542 $ f --hexdump --size .hg/cache/rbc-*
555 $ f --hexdump --size .hg/cache/rbc-*
543 .hg/cache/rbc-names-v1: size=87
556 .hg/cache/rbc-names-v1: size=87
544 0000: 64 65 66 61 75 6c 74 00 61 00 62 00 63 00 61 20 |default.a.b.c.a |
557 0000: 64 65 66 61 75 6c 74 00 61 00 62 00 63 00 61 20 |default.a.b.c.a |
545 0010: 62 72 61 6e 63 68 20 6e 61 6d 65 20 6d 75 63 68 |branch name much|
558 0010: 62 72 61 6e 63 68 20 6e 61 6d 65 20 6d 75 63 68 |branch name much|
546 0020: 20 6c 6f 6e 67 65 72 20 74 68 61 6e 20 74 68 65 | longer than the|
559 0020: 20 6c 6f 6e 67 65 72 20 74 68 61 6e 20 74 68 65 | longer than the|
547 0030: 20 64 65 66 61 75 6c 74 20 6a 75 73 74 69 66 69 | default justifi|
560 0030: 20 64 65 66 61 75 6c 74 20 6a 75 73 74 69 66 69 | default justifi|
548 0040: 63 61 74 69 6f 6e 20 75 73 65 64 20 62 79 20 62 |cation used by b|
561 0040: 63 61 74 69 6f 6e 20 75 73 65 64 20 62 79 20 62 |cation used by b|
549 0050: 72 61 6e 63 68 65 73 |ranches|
562 0050: 72 61 6e 63 68 65 73 |ranches|
550 .hg/cache/rbc-revs-v1: size=120
563 .hg/cache/rbc-revs-v1: size=120
551 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....|
564 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....|
552 0010: 88 1f e2 b9 00 00 00 01 ac 22 03 33 00 00 00 02 |.........".3....|
565 0010: 88 1f e2 b9 00 00 00 01 ac 22 03 33 00 00 00 02 |.........".3....|
553 0020: ae e3 9c d1 00 00 00 02 d8 cb c6 1d 00 00 00 01 |................|
566 0020: ae e3 9c d1 00 00 00 02 d8 cb c6 1d 00 00 00 01 |................|
554 0030: 58 97 36 a2 00 00 00 03 10 ff 58 95 00 00 00 04 |X.6.......X.....|
567 0030: 58 97 36 a2 00 00 00 03 10 ff 58 95 00 00 00 04 |X.6.......X.....|
555 0040: ee bb 94 44 00 00 00 02 5f 40 61 bb 00 00 00 02 |...D...._@a.....|
568 0040: ee bb 94 44 00 00 00 02 5f 40 61 bb 00 00 00 02 |...D...._@a.....|
556 0050: bf be 84 1b 00 00 00 02 d3 f1 63 45 80 00 00 02 |..........cE....|
569 0050: bf be 84 1b 00 00 00 02 d3 f1 63 45 80 00 00 02 |..........cE....|
557 0060: e3 d4 9c 05 80 00 00 02 e2 3b 55 05 00 00 00 02 |.........;U.....|
570 0060: e3 d4 9c 05 80 00 00 02 e2 3b 55 05 00 00 00 02 |.........;U.....|
558 0070: f8 94 c2 56 80 00 00 03 |...V....|
571 0070: f8 94 c2 56 80 00 00 03 |...V....|
559
572
560 no errors when revbranchcache is not writable
573 no errors when revbranchcache is not writable
561
574
562 $ echo >> .hg/cache/rbc-revs-v1
575 $ echo >> .hg/cache/rbc-revs-v1
563 $ mv .hg/cache/rbc-revs-v1 .hg/cache/rbc-revs-v1_
576 $ mv .hg/cache/rbc-revs-v1 .hg/cache/rbc-revs-v1_
564 $ mkdir .hg/cache/rbc-revs-v1
577 $ mkdir .hg/cache/rbc-revs-v1
565 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n'
578 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n'
566 5
579 5
567 $ rmdir .hg/cache/rbc-revs-v1
580 $ rmdir .hg/cache/rbc-revs-v1
568 $ mv .hg/cache/rbc-revs-v1_ .hg/cache/rbc-revs-v1
581 $ mv .hg/cache/rbc-revs-v1_ .hg/cache/rbc-revs-v1
569
582
570 no errors when wlock cannot be acquired
583 no errors when wlock cannot be acquired
571
584
572 #if unix-permissions
585 #if unix-permissions
573 $ mv .hg/cache/rbc-revs-v1 .hg/cache/rbc-revs-v1_
586 $ mv .hg/cache/rbc-revs-v1 .hg/cache/rbc-revs-v1_
574 $ rm -f .hg/cache/branch*
587 $ rm -f .hg/cache/branch*
575 $ chmod 555 .hg
588 $ chmod 555 .hg
576 $ hg head a -T '{rev}\n'
589 $ hg head a -T '{rev}\n'
577 5
590 5
578 $ chmod 755 .hg
591 $ chmod 755 .hg
579 $ mv .hg/cache/rbc-revs-v1_ .hg/cache/rbc-revs-v1
592 $ mv .hg/cache/rbc-revs-v1_ .hg/cache/rbc-revs-v1
580 #endif
593 #endif
581
594
582 recovery from invalid cache revs file with trailing data
595 recovery from invalid cache revs file with trailing data
583 $ echo >> .hg/cache/rbc-revs-v1
596 $ echo >> .hg/cache/rbc-revs-v1
584 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
597 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
585 5
598 5
586 truncating cache/rbc-revs-v1 to 120
599 truncating cache/rbc-revs-v1 to 120
587 $ f --size .hg/cache/rbc-revs*
600 $ f --size .hg/cache/rbc-revs*
588 .hg/cache/rbc-revs-v1: size=120
601 .hg/cache/rbc-revs-v1: size=120
589 recovery from invalid cache file with partial last record
602 recovery from invalid cache file with partial last record
590 $ mv .hg/cache/rbc-revs-v1 .
603 $ mv .hg/cache/rbc-revs-v1 .
591 $ f -qDB 119 rbc-revs-v1 > .hg/cache/rbc-revs-v1
604 $ f -qDB 119 rbc-revs-v1 > .hg/cache/rbc-revs-v1
592 $ f --size .hg/cache/rbc-revs*
605 $ f --size .hg/cache/rbc-revs*
593 .hg/cache/rbc-revs-v1: size=119
606 .hg/cache/rbc-revs-v1: size=119
594 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
607 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
595 5
608 5
596 truncating cache/rbc-revs-v1 to 112
609 truncating cache/rbc-revs-v1 to 112
597 $ f --size .hg/cache/rbc-revs*
610 $ f --size .hg/cache/rbc-revs*
598 .hg/cache/rbc-revs-v1: size=120
611 .hg/cache/rbc-revs-v1: size=120
599 recovery from invalid cache file with missing record - no truncation
612 recovery from invalid cache file with missing record - no truncation
600 $ mv .hg/cache/rbc-revs-v1 .
613 $ mv .hg/cache/rbc-revs-v1 .
601 $ f -qDB 112 rbc-revs-v1 > .hg/cache/rbc-revs-v1
614 $ f -qDB 112 rbc-revs-v1 > .hg/cache/rbc-revs-v1
602 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
615 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
603 5
616 5
604 $ f --size .hg/cache/rbc-revs*
617 $ f --size .hg/cache/rbc-revs*
605 .hg/cache/rbc-revs-v1: size=120
618 .hg/cache/rbc-revs-v1: size=120
606 recovery from invalid cache file with some bad records
619 recovery from invalid cache file with some bad records
607 $ mv .hg/cache/rbc-revs-v1 .
620 $ mv .hg/cache/rbc-revs-v1 .
608 $ f -qDB 8 rbc-revs-v1 > .hg/cache/rbc-revs-v1
621 $ f -qDB 8 rbc-revs-v1 > .hg/cache/rbc-revs-v1
609 $ f --size .hg/cache/rbc-revs*
622 $ f --size .hg/cache/rbc-revs*
610 .hg/cache/rbc-revs-v1: size=8
623 .hg/cache/rbc-revs-v1: size=8
611 $ f -qDB 112 rbc-revs-v1 >> .hg/cache/rbc-revs-v1
624 $ f -qDB 112 rbc-revs-v1 >> .hg/cache/rbc-revs-v1
612 $ f --size .hg/cache/rbc-revs*
625 $ f --size .hg/cache/rbc-revs*
613 .hg/cache/rbc-revs-v1: size=120
626 .hg/cache/rbc-revs-v1: size=120
614 $ hg log -r 'branch(.)' -T '{rev} ' --debug
627 $ hg log -r 'branch(.)' -T '{rev} ' --debug
615 history modification detected - truncating revision branch cache to revision 13
628 history modification detected - truncating revision branch cache to revision 13
616 history modification detected - truncating revision branch cache to revision 1
629 history modification detected - truncating revision branch cache to revision 1
617 3 4 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 8
630 3 4 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 8
618 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
631 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
619 5
632 5
620 truncating cache/rbc-revs-v1 to 104
633 truncating cache/rbc-revs-v1 to 104
621 $ f --size --hexdump --bytes=16 .hg/cache/rbc-revs*
634 $ f --size --hexdump --bytes=16 .hg/cache/rbc-revs*
622 .hg/cache/rbc-revs-v1: size=120
635 .hg/cache/rbc-revs-v1: size=120
623 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....|
636 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....|
624 cache is updated when committing
637 cache is updated when committing
625 $ hg branch i-will-regret-this
638 $ hg branch i-will-regret-this
626 marked working directory as branch i-will-regret-this
639 marked working directory as branch i-will-regret-this
627 $ hg ci -m regrets
640 $ hg ci -m regrets
628 $ f --size .hg/cache/rbc-*
641 $ f --size .hg/cache/rbc-*
629 .hg/cache/rbc-names-v1: size=106
642 .hg/cache/rbc-names-v1: size=106
630 .hg/cache/rbc-revs-v1: size=128
643 .hg/cache/rbc-revs-v1: size=128
631 update after rollback - the cache will be correct but rbc-names will will still
644 update after rollback - the cache will be correct but rbc-names will will still
632 contain the branch name even though it no longer is used
645 contain the branch name even though it no longer is used
633 $ hg up -qr '.^'
646 $ hg up -qr '.^'
634 $ hg rollback -qf
647 $ hg rollback -qf
635 $ f --size --hexdump .hg/cache/rbc-*
648 $ f --size --hexdump .hg/cache/rbc-*
636 .hg/cache/rbc-names-v1: size=106
649 .hg/cache/rbc-names-v1: size=106
637 0000: 64 65 66 61 75 6c 74 00 61 00 62 00 63 00 61 20 |default.a.b.c.a |
650 0000: 64 65 66 61 75 6c 74 00 61 00 62 00 63 00 61 20 |default.a.b.c.a |
638 0010: 62 72 61 6e 63 68 20 6e 61 6d 65 20 6d 75 63 68 |branch name much|
651 0010: 62 72 61 6e 63 68 20 6e 61 6d 65 20 6d 75 63 68 |branch name much|
639 0020: 20 6c 6f 6e 67 65 72 20 74 68 61 6e 20 74 68 65 | longer than the|
652 0020: 20 6c 6f 6e 67 65 72 20 74 68 61 6e 20 74 68 65 | longer than the|
640 0030: 20 64 65 66 61 75 6c 74 20 6a 75 73 74 69 66 69 | default justifi|
653 0030: 20 64 65 66 61 75 6c 74 20 6a 75 73 74 69 66 69 | default justifi|
641 0040: 63 61 74 69 6f 6e 20 75 73 65 64 20 62 79 20 62 |cation used by b|
654 0040: 63 61 74 69 6f 6e 20 75 73 65 64 20 62 79 20 62 |cation used by b|
642 0050: 72 61 6e 63 68 65 73 00 69 2d 77 69 6c 6c 2d 72 |ranches.i-will-r|
655 0050: 72 61 6e 63 68 65 73 00 69 2d 77 69 6c 6c 2d 72 |ranches.i-will-r|
643 0060: 65 67 72 65 74 2d 74 68 69 73 |egret-this|
656 0060: 65 67 72 65 74 2d 74 68 69 73 |egret-this|
644 .hg/cache/rbc-revs-v1: size=120
657 .hg/cache/rbc-revs-v1: size=120
645 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....|
658 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....|
646 0010: 88 1f e2 b9 00 00 00 01 ac 22 03 33 00 00 00 02 |.........".3....|
659 0010: 88 1f e2 b9 00 00 00 01 ac 22 03 33 00 00 00 02 |.........".3....|
647 0020: ae e3 9c d1 00 00 00 02 d8 cb c6 1d 00 00 00 01 |................|
660 0020: ae e3 9c d1 00 00 00 02 d8 cb c6 1d 00 00 00 01 |................|
648 0030: 58 97 36 a2 00 00 00 03 10 ff 58 95 00 00 00 04 |X.6.......X.....|
661 0030: 58 97 36 a2 00 00 00 03 10 ff 58 95 00 00 00 04 |X.6.......X.....|
649 0040: ee bb 94 44 00 00 00 02 5f 40 61 bb 00 00 00 02 |...D...._@a.....|
662 0040: ee bb 94 44 00 00 00 02 5f 40 61 bb 00 00 00 02 |...D...._@a.....|
650 0050: bf be 84 1b 00 00 00 02 d3 f1 63 45 80 00 00 02 |..........cE....|
663 0050: bf be 84 1b 00 00 00 02 d3 f1 63 45 80 00 00 02 |..........cE....|
651 0060: e3 d4 9c 05 80 00 00 02 e2 3b 55 05 00 00 00 02 |.........;U.....|
664 0060: e3 d4 9c 05 80 00 00 02 e2 3b 55 05 00 00 00 02 |.........;U.....|
652 0070: f8 94 c2 56 80 00 00 03 |...V....|
665 0070: f8 94 c2 56 80 00 00 03 |...V....|
653 cache is updated/truncated when stripping - it is thus very hard to get in a
666 cache is updated/truncated when stripping - it is thus very hard to get in a
654 situation where the cache is out of sync and the hash check detects it
667 situation where the cache is out of sync and the hash check detects it
655 $ hg --config extensions.strip= strip -r tip --nob
668 $ hg --config extensions.strip= strip -r tip --nob
656 $ f --size .hg/cache/rbc-revs*
669 $ f --size .hg/cache/rbc-revs*
657 .hg/cache/rbc-revs-v1: size=112
670 .hg/cache/rbc-revs-v1: size=112
658
671
659 cache is rebuilt when corruption is detected
672 cache is rebuilt when corruption is detected
660 $ echo > .hg/cache/rbc-names-v1
673 $ echo > .hg/cache/rbc-names-v1
661 $ hg log -r '5:&branch(.)' -T '{rev} ' --debug
674 $ hg log -r '5:&branch(.)' -T '{rev} ' --debug
662 referenced branch names not found - rebuilding revision branch cache from scratch
675 referenced branch names not found - rebuilding revision branch cache from scratch
663 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 40
676 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 40
664 $ f --size --hexdump .hg/cache/rbc-*
677 $ f --size --hexdump .hg/cache/rbc-*
665 .hg/cache/rbc-names-v1: size=79
678 .hg/cache/rbc-names-v1: size=79
666 0000: 62 00 61 00 63 00 61 20 62 72 61 6e 63 68 20 6e |b.a.c.a branch n|
679 0000: 62 00 61 00 63 00 61 20 62 72 61 6e 63 68 20 6e |b.a.c.a branch n|
667 0010: 61 6d 65 20 6d 75 63 68 20 6c 6f 6e 67 65 72 20 |ame much longer |
680 0010: 61 6d 65 20 6d 75 63 68 20 6c 6f 6e 67 65 72 20 |ame much longer |
668 0020: 74 68 61 6e 20 74 68 65 20 64 65 66 61 75 6c 74 |than the default|
681 0020: 74 68 61 6e 20 74 68 65 20 64 65 66 61 75 6c 74 |than the default|
669 0030: 20 6a 75 73 74 69 66 69 63 61 74 69 6f 6e 20 75 | justification u|
682 0030: 20 6a 75 73 74 69 66 69 63 61 74 69 6f 6e 20 75 | justification u|
670 0040: 73 65 64 20 62 79 20 62 72 61 6e 63 68 65 73 |sed by branches|
683 0040: 73 65 64 20 62 79 20 62 72 61 6e 63 68 65 73 |sed by branches|
671 .hg/cache/rbc-revs-v1: size=112
684 .hg/cache/rbc-revs-v1: size=112
672 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
685 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
673 0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
686 0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
674 0020: 00 00 00 00 00 00 00 00 d8 cb c6 1d 00 00 00 01 |................|
687 0020: 00 00 00 00 00 00 00 00 d8 cb c6 1d 00 00 00 01 |................|
675 0030: 58 97 36 a2 00 00 00 02 10 ff 58 95 00 00 00 03 |X.6.......X.....|
688 0030: 58 97 36 a2 00 00 00 02 10 ff 58 95 00 00 00 03 |X.6.......X.....|
676 0040: ee bb 94 44 00 00 00 00 5f 40 61 bb 00 00 00 00 |...D...._@a.....|
689 0040: ee bb 94 44 00 00 00 00 5f 40 61 bb 00 00 00 00 |...D...._@a.....|
677 0050: bf be 84 1b 00 00 00 00 d3 f1 63 45 80 00 00 00 |..........cE....|
690 0050: bf be 84 1b 00 00 00 00 d3 f1 63 45 80 00 00 00 |..........cE....|
678 0060: e3 d4 9c 05 80 00 00 00 e2 3b 55 05 00 00 00 00 |.........;U.....|
691 0060: e3 d4 9c 05 80 00 00 00 e2 3b 55 05 00 00 00 00 |.........;U.....|
679
692
680 Test that cache files are created and grows correctly:
693 Test that cache files are created and grows correctly:
681
694
682 $ rm .hg/cache/rbc*
695 $ rm .hg/cache/rbc*
683 $ hg log -r "5 & branch(5)" -T "{rev}\n"
696 $ hg log -r "5 & branch(5)" -T "{rev}\n"
684 5
697 5
685 $ f --size --hexdump .hg/cache/rbc-*
698 $ f --size --hexdump .hg/cache/rbc-*
686 .hg/cache/rbc-names-v1: size=1
699 .hg/cache/rbc-names-v1: size=1
687 0000: 61 |a|
700 0000: 61 |a|
688 .hg/cache/rbc-revs-v1: size=112
701 .hg/cache/rbc-revs-v1: size=112
689 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
702 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
690 0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
703 0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
691 0020: 00 00 00 00 00 00 00 00 d8 cb c6 1d 00 00 00 00 |................|
704 0020: 00 00 00 00 00 00 00 00 d8 cb c6 1d 00 00 00 00 |................|
692 0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
705 0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
693 0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
706 0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
694 0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
707 0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
695 0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
708 0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
696
709
697 $ cd ..
710 $ cd ..
698
711
699 Test for multiple incorrect branch cache entries:
712 Test for multiple incorrect branch cache entries:
700
713
701 $ hg init b
714 $ hg init b
702 $ cd b
715 $ cd b
703 $ touch f
716 $ touch f
704 $ hg ci -Aqmf
717 $ hg ci -Aqmf
705 $ echo >> f
718 $ echo >> f
706 $ hg ci -Amf
719 $ hg ci -Amf
707 $ hg branch -q branch
720 $ hg branch -q branch
708 $ hg ci -Amf
721 $ hg ci -Amf
709
722
710 $ f --size --hexdump .hg/cache/rbc-*
723 $ f --size --hexdump .hg/cache/rbc-*
711 .hg/cache/rbc-names-v1: size=14
724 .hg/cache/rbc-names-v1: size=14
712 0000: 64 65 66 61 75 6c 74 00 62 72 61 6e 63 68 |default.branch|
725 0000: 64 65 66 61 75 6c 74 00 62 72 61 6e 63 68 |default.branch|
713 .hg/cache/rbc-revs-v1: size=24
726 .hg/cache/rbc-revs-v1: size=24
714 0000: 66 e5 f5 aa 00 00 00 00 fa 4c 04 e5 00 00 00 00 |f........L......|
727 0000: 66 e5 f5 aa 00 00 00 00 fa 4c 04 e5 00 00 00 00 |f........L......|
715 0010: 56 46 78 69 00 00 00 01 |VFxi....|
728 0010: 56 46 78 69 00 00 00 01 |VFxi....|
716 $ : > .hg/cache/rbc-revs-v1
729 $ : > .hg/cache/rbc-revs-v1
717
730
718 No superfluous rebuilding of cache:
731 No superfluous rebuilding of cache:
719 $ hg log -r "branch(null)&branch(branch)" --debug
732 $ hg log -r "branch(null)&branch(branch)" --debug
720 $ f --size --hexdump .hg/cache/rbc-*
733 $ f --size --hexdump .hg/cache/rbc-*
721 .hg/cache/rbc-names-v1: size=14
734 .hg/cache/rbc-names-v1: size=14
722 0000: 64 65 66 61 75 6c 74 00 62 72 61 6e 63 68 |default.branch|
735 0000: 64 65 66 61 75 6c 74 00 62 72 61 6e 63 68 |default.branch|
723 .hg/cache/rbc-revs-v1: size=24
736 .hg/cache/rbc-revs-v1: size=24
724 0000: 66 e5 f5 aa 00 00 00 00 fa 4c 04 e5 00 00 00 00 |f........L......|
737 0000: 66 e5 f5 aa 00 00 00 00 fa 4c 04 e5 00 00 00 00 |f........L......|
725 0010: 56 46 78 69 00 00 00 01 |VFxi....|
738 0010: 56 46 78 69 00 00 00 01 |VFxi....|
726
739
727 $ cd ..
740 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now