##// END OF EJS Templates
git: skeleton of a new extension to _directly_ operate on git repos...
git: skeleton of a new extension to _directly_ operate on git repos This is based in part of work I did years ago in hgit, but it's mostly new code since I'm using pygit2 instead of dulwich and the hg storage interfaces have improved. Some cleanup of old hgit code by Pulkit, which I greatly appreciate. test-git-interop.t does not cover a whole lot of cases, but it passes. It includes status, diff, making a new commit, and `hg annotate` working on the git repository. This is _not_ (yet) production quality code: this is an experiment. Known technical debt lurking in this implementation: * Writing bookmarks just totally ignores transactions. * The way progress is threaded down into the gitstore is awful. * Ideally we'd find a way to incrementally reindex DAGs. I'm not sure how to do that efficiently, so we might need a "known only fast-forwards" mode on the DAG indexer for use on `hg commit` and friends. * We don't even _try_ to do anything reasonable for `hg pull` or `hg push`. * Mercurial need an interface for the changelog type. Tests currently require git 2.24 as far as I'm aware: `git status` has some changed output that I didn't try and handle in a compatible way. This patch has produced some interesting cleanups, most recently on the manifest type. I expect continuing down this road will produce other meritorious cleanups throughout our code. Differential Revision: https://phab.mercurial-scm.org/D6734

File last commit:

r44819:14d0e895 default
r44961:ad718271 default
Show More
beautifygraph.py
109 lines | 3.1 KiB | text/x-python | PythonLexer
# -*- 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 = b'ships-with-hg-core'
def prettyedge(before, edge, after):
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 ┼
return edge
def convertedges(line):
line = b' %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 b''.join(pretty)
def getprettygraphnode(orig, *args, **kwargs):
node = orig(*args, **kwargs)
if node == b'o':
return b'\xE2\x97\x8B' # U+25CB ○
if node == b'@':
return b'\xE2\x97\x8D' # U+25CD ◍
if node == b'%':
return b'\xE2\x97\x8D' # U+25CE ◎
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 ╤
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(b'graph'):
return
if encoding.encoding != b'UTF-8':
ui.warn(_(b'beautifygraph: unsupported encoding, UTF-8 required\n'))
return
if 'A' in encoding._wide:
ui.warn(
_(
b'beautifygraph: unsupported terminal settings, '
b'monospace narrow text required\n'
)
)
return
extensions.wrapfunction(graphmod, b'outputgraph', outputprettygraph)
extensions.wrapfunction(templatekw, b'getgraphnode', getprettygraphnode)