Render graph

This commit is contained in:
David Doblas Jiménez 2024-05-22 16:52:44 +02:00
parent 2362d69673
commit b854b4fa18

View File

@ -1,4 +1,5 @@
import argparse
import subprocess
import sys
import textwrap
@ -110,14 +111,24 @@ def tag(args):
def k(args):
dot = "digraph commits {\n"
oids = set()
for refname, ref in data.iter_refs():
print(refname, ref)
dot += f"'{refname}' [shape=note]\n"
dot += f"'{refname}' -> '{ref}'\n"
oids.add(ref)
for oid in base.iter_commits_and_parents(oids):
commit = base.get_commit(oid)
print(oid)
dot += f"'{oid}' [shape=box style=filled label='{oid[:10]}']\n"
if commit.parent:
print("Parent", commit.parent)
# TODO visualize refs
dot += f"'{oid}' -> '{commit.parent}'\n"
dot += "}"
print(dot)
with subprocess.Popen(
["dot", "-Tgtk", "/dev/stdin"], stdin=subprocess.PIPE
) as proc:
proc.communicate(dot.encode())