Mercurial > hg
view hgext/beautifygraph.py @ 40056:324b4b10351e
revlog: rewrite censoring logic
I was able to corrupt a revlog relatively easily with the existing
censoring code. The underlying problem is that the existing code
doesn't fully take delta chains into account. When copying revisions
that occur after the censored revision, the delta base can refer
to a censored revision. Then at read time, things blow up due to the
revision data not being a compressed delta.
This commit rewrites the revlog censoring code to take a higher-level
approach. We now create a new revlog instance pointing at temp files.
We iterate through each revision in the source revlog and insert
those revisions into the new revlog, replacing the censored revision's
data along the way.
The new implementation isn't as efficient as the old one. This is
because it will fully engage delta computation on insertion. But I
don't think it matters.
The new implementation is a bit hacky because it attempts to reload
the revlog instance with a new revlog index/data file. This is fragile.
But this is needed because the index (which could be backed by C) would
have a cached copy of the old, possibly changed data and that could
lead to problems accessing index or revision data later.
One benefit of the new approach is that we integrate with the
transaction. The old revlog is backed up and if the transaction is
rolled back, the original revlog is restored.
As part of this, we had to teach the transaction about the store
vfs. I'm not super keen about this. But this was the easiest way
to hook things up to the transaction. We /could/ just ignore the
transaction like we were doing before. But any file mutation should
be governed by transaction semantics, including undo during rollback.
Differential Revision: https://phab.mercurial-scm.org/D4869
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 02 Oct 2018 17:34:34 -0700 |
parents | 5b9f116104f9 |
children | c2a0bc6412db |
line wrap: on
line source
# -*- 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, pycompat, 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. testedwith = 'ships-with-hg-core' def prettyedge(before, edge, after): if edge == '~': return '\xE2\x95\xA7' # U+2567 ╧ if edge == 'X': return '\xE2\x95\xB3' # U+2573 ╳ if edge == '/': return '\xE2\x95\xB1' # U+2571 ╱ if edge == '-': return '\xE2\x94\x80' # U+2500 ─ if edge == '|': return '\xE2\x94\x82' # U+2502 │ if edge == ':': return '\xE2\x94\x86' # U+2506 ┆ if edge == '\\': return '\xE2\x95\xB2' # U+2572 ╲ if edge == '+': if before == ' ' and not after == ' ': return '\xE2\x94\x9C' # U+251C ├ if after == ' ' and not before == ' ': return '\xE2\x94\xA4' # U+2524 ┤ return '\xE2\x94\xBC' # U+253C ┼ return edge def convertedges(line): line = ' %s ' % line pretty = [] for idx in pycompat.xrange(len(line) - 2): pretty.append(prettyedge(line[idx:idx + 1], line[idx + 1:idx + 2], line[idx + 2:idx + 3])) return ''.join(pretty) def getprettygraphnode(orig, *args, **kwargs): node = orig(*args, **kwargs) if node == 'o': return '\xE2\x97\x8B' # U+25CB ○ if node == '@': return '\xE2\x97\x8D' # U+25CD ◍ if node == '*': return '\xE2\x88\x97' # U+2217 ∗ if node == 'x': return '\xE2\x97\x8C' # U+25CC ◌ if node == '_': return '\xE2\x95\xA4' # U+2564 ╤ return node 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) def extsetup(ui): if ui.plain('graph'): return if encoding.encoding != 'UTF-8': ui.warn(_('beautifygraph: unsupported encoding, UTF-8 required\n')) return if r'A' in encoding._wide: ui.warn(_('beautifygraph: unsupported terminal settings, ' 'monospace narrow text required\n')) return extensions.wrapfunction(graphmod, 'outputgraph', outputprettygraph) extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode)