##// END OF EJS Templates
revlog: add a mechanism to verify expected file position before appending...
revlog: add a mechanism to verify expected file position before appending If someone uses `hg debuglocks`, or some non-hg process writes to the .hg directory without respecting the locks, or if the repo's on a networked filesystem, it's possible for the revlog code to write out corrupted data. The form of this corruption can vary depending on what data was written and how that happened. We are in the "networked filesystem" case (though I've had users also do this to themselves with the "`hg debuglocks`" scenario), and most often see this with the changelog. What ends up happening is we produce two items (let's call them rev1 and rev2) in the .i file that have the same linkrev, baserev, and offset into the .d file, while the data in the .d file is appended properly. rev2's compressed_size is accurate for rev2, but when we go to decompress the data in the .d file, we use the offset that's recorded in the index file, which is the same as rev1, and attempt to decompress rev2.compressed_size bytes of rev1's data. This usually does not succeed. :) When using inline data, this also fails, though I haven't investigated why too closely. This shows up as a "patch decode" error. I believe what's happening there is that we're basically ignoring the offset field, getting the data properly, but since baserev != rev, it thinks this is a delta based on rev (instead of a full text) and can't actually apply it as such. For now, I'm going to make this an optional component and default it to entirely off. I may increase the default severity of this in the future, once I've enabled it for my users and we gain more experience with it. Luckily, most of my users have a versioned filesystem and can roll back to before the corruption has been written, it's just a hassle to do so and not everyone knows how (so it's a support burden). Users on other filesystems will not have that luxury, and this can cause them to have a corrupted repository that they are unlikely to know how to resolve, and they'll see this as a data-loss event. Refusing to create the corruption is a much better user experience. This mechanism is not perfect. There may be false-negatives (racy writes that are not detected). There should not be any false-positives (non-racy writes that are detected as such). This is not a mechanism that makes putting a repo on a networked filesystem "safe" or "supported", just *less* likely to cause corruption. Differential Revision: https://phab.mercurial-scm.org/D9952

File last commit:

r46821:36c05ab0 default
r47349:e9901d01 default
Show More
beautifygraph.py
109 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 __future__ import absolute_import
from mercurial.i18n import _
from mercurial import (
encoding,
extensions,
graphmod,
Gregory Szorc
global: use pycompat.xrange()...
r38806 pycompat,
John Stiles
graph: improve graph output by using Unicode characters...
r38359 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 = []
Gregory Szorc
global: use pycompat.xrange()...
r38806 for idx in pycompat.xrange(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)