Repository: git-big-picture/git-big-picture (language: python)

Issue:
Request: vertical (sideways) graph
Thank you for this tool, which is very useful!  I have one repo with about 20 branches, so the graph is very wide.  Would it be possible to request a mode in which arrows to parents point left, and branches are stacked vertically?  That would give me a tall, skinny image instead of a short, wide image.  Text would still be left to right.  My apologies if this has already been implemented and I missed it in the documentation.  Thank you for considering this request!

One possible implementation in the shell is:

    git-big-picture --graphviz | sed -e '1arankdir=RL;' | dot -Tpng -o graph.png

This produces the style I am looking for.

A few interesting features added
added exclusion file
added inclusion file
added --horizontal option (vertical by default, but has no vertical explicit option…)
added json export (named jsonlt for json light, graphviz now supports exporting to json, but the current Windows version does not include it yet)

maybe you find interesting ideas in this

François
Request: vertical (sideways) graph
Thank you for this tool, which is very useful!  I have one repo with about 20 branches, so the graph is very wide.  Would it be possible to request a mode in which arrows to parents point left, and branches are stacked vertically?  That would give me a tall, skinny image instead of a short, wide image.  Text would still be left to right.  My apologies if this has already been implemented and I missed it in the documentation.  Thank you for considering this request!

One possible implementation in the shell is:

    git-big-picture --graphviz | sed -e '1arankdir=RL;' | dot -Tpng -o graph.png

This produces the style I am looking for.

A few interesting features added
added exclusion file
added inclusion file
added --horizontal option (vertical by default, but has no vertical explicit option…)
added json export (named jsonlt for json light, graphviz now supports exporting to json, but the current Windows version does not include it yet)

maybe you find interesting ideas in this

François
Improved --help output + migrate from optparse to argparse
~Sits on top of pull request #49 to avoid conflicts. Happy to rebase off of it, once #49 is merged to master, if you prefer.~
Stop leaving temp files behind (finishes up on #25)
Based on (a rebased version of) pull request #25 by @fredden
Migrate from unmaintained Cram to maintained Scruf
Just an idea for consideration.

PS: Not sure why GitHub displays the rename as remove and add. Maybe more fun to review locally :thinking: 


Discussion / hints:

Fix patch:
diff --git a/README.rst b/README.rst
index fb47672..eed4f33 100644
--- a/README.rst
+++ b/README.rst
@@ -182,6 +182,9 @@ Usage
       Options to control output and format
 
       -f FMT, --format FMT  set output format [svg, png, ps, pdf, ...]
+      --history-direction {downwards,leftwards,rightwards,upwards}
+                            enforce a specific direction of history on Graphviz
+                            (default: upwards)
       -g, --graphviz        output lines suitable as input for dot/graphviz
       -G, --no-graphviz     disable dot/graphviz output
       -p, --processed       output the dot processed, binary data
diff --git a/git-big-picture b/git-big-picture
index d006403..bee9e37 100755
--- a/git-big-picture
+++ b/git-big-picture
@@ -106,6 +106,15 @@ EXIT_CODES = {"too_many_args":              1,
 
 sha1_pattern = re.compile('[0-9a-fA-F]{40}')
 
+# https://graphviz.org/doc/info/attrs.html#k:rankdir
+# NOTE: "left to right" to a human is "right to left" to Graphviz; same for top and bottom
+RANKDIR_OF_HISTORY_DIRECTION = {
+    'downwards': 'BT',
+    'leftwards': 'LR',
+    'rightwards': 'RL',
+    'upwards': 'TB',
+}
+
 DEBUG = False
 
 USAGE = "%(prog)s OPTIONS [REPOSITORY]"
@@ -124,6 +133,11 @@ def create_parser():
             dest=FORMAT,
             metavar='FMT', help='set output format [svg, png, ps, pdf, ...]')
 
+    format_group.add_argument('--history-direction',
+            default=None, choices=sorted(RANKDIR_OF_HISTORY_DIRECTION.keys()),
+            help='enforce a specific direction of history on Graphviz\n'
+                 '(default: upwards)')
+
     format_group.add_argument('-g', '--graphviz',
             default=None, action='store_true', dest=GRAPHVIZ,
             help='output lines suitable as input for dot/graphviz')
@@ -834,7 +848,8 @@ class CommitGraph:
                 return digit_count
         return 40
 
-    def _generate_dot_file(self, sha_ones_on_labels, with_commit_messages, sha_one_digits=None):
+    def _generate_dot_file(self, sha_ones_on_labels, with_commit_messages, sha_one_digits=None,
+                           history_direction=None):
         """ Generate graphviz input.
 
         Parameters
@@ -884,6 +899,9 @@ class CommitGraph:
                 yield (k, labels, color)
 
         dot_file_lines = ['digraph {']
+        if history_direction is not None:
+            rankdir = RANKDIR_OF_HISTORY_DIRECTION[history_direction]
+            dot_file_lines.append(f'\trankdir="{rankdir}";')
         for sha_one, labels, color in label_gen():
             label = '\\n'.join(labels + ((with_commit_messages or sha_ones_on_labels) and [
                 format_label(sha_one), ] or list()))
@@ -929,7 +947,9 @@ def innermost_main(opts):
     dot_file_lines = graph._generate_dot_file(
         sha_ones_on_labels=opts.all_commits,
         with_commit_messages=annotation_settings['messages'],
-        sha_one_digits=sha_one_digits)
+        sha_one_digits=sha_one_digits,
+        history_direction=opts.history_direction,
+    )
 
     if (output_settings[GRAPHVIZ] and output_settings[PROCESSED]):
         barf("Options '-g | --graphviz' and '-p | --processed' " +


Test patch:
diff --git a/test.scf b/test.scf
index 908ab36..be87356 100755
--- a/test.scf
+++ b/test.scf
@@ -120,6 +120,14 @@ provide filename and viewer and format
     $ rm file.png
     $ ls
 
+check explicit direction of history
+    $ bash -c 'set -o pipefail; for i in {down,left,right,up}wards; do git-big-picture -g --history-direction=${i} | fgrep rankdir ; done'
+    [RE] rankdir="BT";
+    [RE] rankdir="LR";
+    [RE] rankdir="RL";
+    [RE] rankdir="TB";
+    [0]
+
 check for deletion of temp files
     $ ls -1 "$(git-big-picture -d -v true | fgrep 'temp file' | tee /dev/stderr | grep -Eo "/[^']+" | uniq)"
     2: [RE] ^debug:   Created temp file: '/[^']+'$