[PATCH] graphmod: shorten graph
Martijn Pieters
mj at zopatista.com
Tue Apr 5 14:56:13 EDT 2016
On 3 April 2016 at 15:47, Santiago PayĆ Miralta <santiagopim at gmail.com> wrote:
> # HG changeset patch
> # User santiagopim <santiagopim at gmail.com>
> # Date 1459691053 -7200
> # Sun Apr 03 15:44:13 2016 +0200
> # Node ID ab6383126f07288571e627857a6a92ce44273491
> # Parent ff0d3b6b287f89594bd8d0308fe2810d2a18ea01
> graphmod: shorten graph
>
> Shorten the graph cutting the all vertical (not oblique) edges rows.
> Example graph:
>
> $ hg log --graph --template '{rev} {desc|firstline}' --rev 1035:1015
> o 1035 Merge with BOS
> |\
> | o 1034 Fix help output, and a few broken tests.
> | o 1033 Merge with MPM.
> | |\
> | | o 1032 Get patchbomb working with tip again.
> | | o 1031 Rewrite log command. New version is faster and more featureful.
> | | o 1030 Merge with MPM.
> | | |\
> | | | o 1029 Emacs: implement hg-incoming, hg-outgoing and hg-push.
> | | | o 1028 Add commands.debugconfig.
> | | | o 1027 Emacs: fix up hg-log and hg-diff to operate more uniformly.
> | | | o 1026 Merge with MPM.
> | | | |\
> | | | | o 1025 Merge with MPM.
> | | | | |
> | | | | ~
> | | | o 1024 Sync buffers prior to doing a diff.
> | | | |
> | | | ~
> o | | 1023 Minor tweak to the revgen algorithm
> |/ /
> o | 1022 Minor hgwebdir tweaks
> o | 1021 Add Makefile to the manifest
> o | 1020 Add default make rule
> o | 1019 Create helper functions for I/O to files in the working directory
> o | 1018 Add some aliases
> o | 1017 Fix up help for binary options
> |/
> o 1016 Teach annotate about binary files
> o 1015 Add automatic binary file detection to diff and export
> |
> ~
>
> diff -r ff0d3b6b287f -r ab6383126f07 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py Tue Mar 29 12:29:00 2016 -0500
> +++ b/mercurial/cmdutil.py Sun Apr 03 15:44:13 2016 +0200
> @@ -2232,6 +2232,10 @@
> styles[key])
> if not styles[key]:
> styles[key] = None
> +
> + # experimental config: experimental.graphshorten
> + state['graphshorten'] = ui.configbool('experimental', 'graphshorten')
> +
> for rev, type, ctx, parents in dag:
> char = formatnode(repo, ctx)
> copies = None
> diff -r ff0d3b6b287f -r ab6383126f07 mercurial/graphmod.py
> --- a/mercurial/graphmod.py Tue Mar 29 12:29:00 2016 -0500
> +++ b/mercurial/graphmod.py Sun Apr 03 15:44:13 2016 +0200
> @@ -543,6 +543,7 @@
> 'lastcoldiff': 0,
> 'lastindex': 0,
> 'styles': EDGES.copy(),
> + 'graphshorten': 0,
Can this be set to False instead, to signal that it's a flag?
> }
>
> def ascii(ui, state, type, char, text, coldata):
> @@ -630,7 +631,15 @@
> lines = [nodeline]
> if add_padding_line:
> lines.append(_getpaddingline(echars, idx, ncols, edges))
> - lines.append(shift_interline)
> +
> + # If 'graphshorten' config, only draw shift_interline
> + # when there is any non vertical flow in graph.
> + if state['graphshorten']:
> + if any(str(c) in '\/' for c in shift_interline):
Why the `str()` call? If this is to handle the `None` values, why not
test for truthy items instead?
if any(c in '\/' for c in shift_interline if c):
If the whole shift_interline consists of `None` values, then the
generator will be empty and `any()` will return False.
> + lines.append(shift_interline)
> + # Else, no 'graphshorten' config so draw shift_interline.
> + else:
> + lines.append(shift_interline)
>
> # make sure that there are as many graph lines as there are
> # log strings
> diff -r ff0d3b6b287f -r ab6383126f07 tests/test-glog.t
> --- a/tests/test-glog.t Tue Mar 29 12:29:00 2016 -0500
> +++ b/tests/test-glog.t Sun Apr 03 15:44:13 2016 +0200
> @@ -2632,5 +2632,106 @@
> date: Thu Jan 01 00:00:04 1970 +0000
> summary: (4) merge two known; one immediate left, one immediate right
>
> + $ cd ..
>
> +Change graph shorten, test better with graphstyle.missing not none
> +
> + $ cd repo
> + $ cat << EOF >> $HGRCPATH
> + > [experimental]
> + > graphstyle.parent = |
> + > graphstyle.grandparent = :
> + > graphstyle.missing = '
> + > graphshorten = true
> + > EOF
> + $ hg log -G -r 'file("a")' -m -T '{rev} {desc}'
> + @ 36 (36) buggy merge: identical parents
> + o 32 (32) expand
> + |\
> + o : 31 (31) expand
> + |\:
> + o : 30 (30) expand
> + |\ \
> + o \ \ 28 (28) merge zero known
> + |\ \ \
> + o \ \ \ 26 (26) merge one known; far right
> + |\ \ \ \
> + | o-----+ 25 (25) merge one known; far left
> + | o ' ' : 24 (24) merge one known; immediate right
> + | |\ \ \ \
> + | o---+ ' : 23 (23) merge one known; immediate left
> + | o-------+ 22 (22) merge two known; one far left, one far right
> + |/ / / / /
> + | ' ' ' o 21 (21) expand
> + | ' ' ' |\
> + +-+-------o 20 (20) merge two known; two far right
> + | ' ' ' o 19 (19) expand
> + | ' ' ' |\
> + o---+---+ | 18 (18) merge two known; two far left
> + / / / / /
> + ' ' ' | o 17 (17) expand
> + ' ' ' | |\
> + +-+-------o 16 (16) merge two known; one immediate right, one near right
> + ' ' ' o | 15 (15) expand
> + ' ' ' |\ \
> + +-------o | 14 (14) merge two known; one immediate right, one far right
> + ' ' ' | |/
> + ' ' ' o | 13 (13) expand
> + ' ' ' |\ \
> + ' +---+---o 12 (12) merge two known; one immediate right, one far left
> + ' ' ' | o 11 (11) expand
> + ' ' ' | |\
> + +---------o 10 (10) merge two known; one immediate left, one near right
> + ' ' ' | |/
> + ' ' ' o | 9 (9) expand
> + ' ' ' |\ \
> + +-------o | 8 (8) merge two known; one immediate left, one far right
> + ' ' ' |/ /
> + ' ' ' o | 7 (7) expand
> + ' ' ' |\ \
> + ' ' ' +---o 6 (6) merge two known; one immediate left, one far left
> + ' ' ' | '/
> + ' ' ' o ' 5 (5) expand
> + ' ' ' |\ \
> + ' +---o ' ' 4 (4) merge two known; one immediate left, one immediate right
> + ' ' ' '/ /
> +
> +behavior with newlines
> +
> + $ hg log -G -r ::2 -T '{rev} {desc}'
> + o 2 (2) collapse
> + o 1 (1) collapse
> + o 0 (0) root
> +
> + $ hg log -G -r ::2 -T '{rev} {desc}\n'
> + o 2 (2) collapse
> + o 1 (1) collapse
> + o 0 (0) root
> +
> + $ hg log -G -r ::2 -T '{rev} {desc}\n\n'
> + o 2 (2) collapse
> + |
> + o 1 (1) collapse
> + |
> + o 0 (0) root
> +
> +
> + $ hg log -G -r ::2 -T '\n{rev} {desc}'
> + o
> + | 2 (2) collapse
> + o
> + | 1 (1) collapse
> + o
> + 0 (0) root
> +
> + $ hg log -G -r ::2 -T '{rev} {desc}\n\n\n'
> + o 2 (2) collapse
> + |
> + |
> + o 1 (1) collapse
> + |
> + |
> + o 0 (0) root
> +
> +
> $ cd ..
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
--
Martijn Pieters
More information about the Mercurial-devel
mailing list