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