##// END OF EJS Templates
procutil: make stream detection in make_line_buffered more correct and strict...
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.

File last commit:

r50179:d44e3c45 default
r50273:094a5fa3 6.2 stable
Show More
beautifygraph.py
107 lines | 3.1 KiB | text/x-python | PythonLexer
John Stiles
graph: improve graph output by using Unicode characters...
r38359 # -*- coding: UTF-8 -*-
# beautifygraph.py - improve graph output by using Unicode characters
#
# Copyright 2018 John Stiles <johnstiles@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
'''beautify log -G output by using Unicode characters (EXPERIMENTAL)
A terminal with UTF-8 support and monospace narrow text are required.
'''
from mercurial.i18n import _
from mercurial import (
encoding,
extensions,
graphmod,
templatekw,
)
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 testedwith = b'ships-with-hg-core'
John Stiles
graph: improve graph output by using Unicode characters...
r38359
Augie Fackler
formatting: blacken the codebase...
r43346
John Stiles
graph: improve graph output by using Unicode characters...
r38359 def prettyedge(before, edge, after):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if edge == b'~':
return b'\xE2\x95\xA7' # U+2567 ╧
if edge == b'/':
return b'\xE2\x95\xB1' # U+2571 ╱
if edge == b'-':
return b'\xE2\x94\x80' # U+2500 ─
if edge == b'|':
return b'\xE2\x94\x82' # U+2502 │
if edge == b':':
return b'\xE2\x94\x86' # U+2506 ┆
if edge == b'\\':
return b'\xE2\x95\xB2' # U+2572 ╲
if edge == b'+':
if before == b' ' and not after == b' ':
return b'\xE2\x94\x9C' # U+251C ├
if after == b' ' and not before == b' ':
return b'\xE2\x94\xA4' # U+2524 ┤
return b'\xE2\x94\xBC' # U+253C ┼
John Stiles
graph: improve graph output by using Unicode characters...
r38359 return edge
Augie Fackler
formatting: blacken the codebase...
r43346
John Stiles
graph: improve graph output by using Unicode characters...
r38359 def convertedges(line):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 line = b' %s ' % line
John Stiles
graph: improve graph output by using Unicode characters...
r38359 pretty = []
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 for idx in range(len(line) - 2):
Augie Fackler
formatting: blacken the codebase...
r43346 pretty.append(
prettyedge(
line[idx : idx + 1],
line[idx + 1 : idx + 2],
line[idx + 2 : idx + 3],
)
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(pretty)
John Stiles
graph: improve graph output by using Unicode characters...
r38359
Augie Fackler
formatting: blacken the codebase...
r43346
John Stiles
graph: improve graph output by using Unicode characters...
r38359 def getprettygraphnode(orig, *args, **kwargs):
node = orig(*args, **kwargs)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if node == b'o':
return b'\xE2\x97\x8B' # U+25CB ○
if node == b'@':
msuozzo@google.com
beautifygraph: change the current commit symbol...
r46821 return b'\xE2\x97\x89' # U+25C9 ◉
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819 if node == b'%':
return b'\xE2\x97\x8D' # U+25CE ◎
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if node == b'*':
return b'\xE2\x88\x97' # U+2217 ∗
if node == b'x':
return b'\xE2\x97\x8C' # U+25CC ◌
if node == b'_':
return b'\xE2\x95\xA4' # U+2564 ╤
John Stiles
graph: improve graph output by using Unicode characters...
r38359 return node
Augie Fackler
formatting: blacken the codebase...
r43346
John Stiles
graph: improve graph output by using Unicode characters...
r38359 def outputprettygraph(orig, ui, graph, *args, **kwargs):
(edges, text) = zip(*graph)
graph = zip([convertedges(e) for e in edges], text)
return orig(ui, graph, *args, **kwargs)
Augie Fackler
formatting: blacken the codebase...
r43346
John Stiles
graph: improve graph output by using Unicode characters...
r38359 def extsetup(ui):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.plain(b'graph'):
Augie Fackler
beautifygraph: don't warn about busted terminal if HGPLAIN is set...
r39249 return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if encoding.encoding != b'UTF-8':
ui.warn(_(b'beautifygraph: unsupported encoding, UTF-8 required\n'))
John Stiles
graph: improve graph output by using Unicode characters...
r38359 return
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if 'A' in encoding._wide:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.warn(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'beautifygraph: unsupported terminal settings, '
b'monospace narrow text required\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
John Stiles
graph: improve graph output by using Unicode characters...
r38359 return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 extensions.wrapfunction(graphmod, b'outputgraph', outputprettygraph)
extensions.wrapfunction(templatekw, b'getgraphnode', getprettygraphnode)