From 52b65619e1406581c29c561bc1edc1d7fea2e3fc Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Wed, 13 Feb 2019 23:12:53 +0100 Subject: [PATCH] minor PyUpdate Fix Front parsing works basic --- git-log-to-tikz.py | 4 +- gitLog2tikz.py | 146 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 gitLog2tikz.py diff --git a/git-log-to-tikz.py b/git-log-to-tikz.py index 629a1ac..440a3fc 100755 --- a/git-log-to-tikz.py +++ b/git-log-to-tikz.py @@ -120,7 +120,7 @@ r = Repo() # extract Commits cmd = "git log --branches --graph --oneline --parents" -return_output = check_output(cmd, shell=True) +return_output = check_output(cmd, shell=True, encoding='utf-8') #print(return_output.split("\n")) for line in return_output.split("\n"): @@ -133,7 +133,7 @@ r.resolve_parents() # extract Branches cmd = "git branch -av | cut -b 3-" -return_output = check_output(cmd, shell=True) +return_output = check_output(cmd, shell=True, encoding='utf-8') #print(return_output.split("\n")) for line in return_output.split("\n"): diff --git a/gitLog2tikz.py b/gitLog2tikz.py new file mode 100644 index 0000000..2121f67 --- /dev/null +++ b/gitLog2tikz.py @@ -0,0 +1,146 @@ +from subprocess import check_output +from collections import OrderedDict +from re import compile, match + +# Importer fast fertig +# Aber die light Variante + +hashpat = compile(r"[a-f0-9]{7}") +linepat = compile(r'[^|\/\\]') + + +def color(numb): + colors = ["black", "blue", "brown", "cyan", "darkgray", "gray", "green", "lightgray", "lime", "magenta", "olive", "orange", "pink", "purple", "red", "teal", "violet", "white", "yellow"] + return colors[numb % colors.__len__()] + + +class Commit: + def __init__(self,line): + self._line = None + self._hash = None + self._children = {} + self._parents = {} + self._message= None + self._message_pos = None + self._node_pos = None + self._node_color = None + + self._line = line + pos = 0 + for word in line.split(" "): + if self._message: + self._message += " " + word + elif hashpat.match(word): + if not self._hash: + self._hash = word + else: + self._parents[word] = NotImplemented + elif word == '*' and not self._message: + self._node_pos = pos + elif linepat.match(word): + self._message = word + self._message_pos = pos + + pos = pos + 1 + if self._hash: + self._message = self._message.replace("!","") + + def update_parent (self, child): + self._parents[child._hash] = child + child._children[self._hash] = self + + def export_to_tikz(self, ypos): + print("\\node[commit, " + color(self._node_pos) + ", fill=" + color(self._node_pos) + "] (" + self._hash + ") at (" + str(.5 * self._node_pos) + "," + str(ypos) + ") {};") + print("\\node[right,xshift=10] (label_" + self._hash + ") at (" + self._hash + ".east) {\\verb!" + self._hash + ": " + self._message + "!};") + #for child in self._children.itervalues(): + # print("\\path[" + "blue" +"] (" + self._hash + ") to[out=90,in=-90] (" + child._hash + ");") + + +class Branch: + def __init__(self, line): + self._hash="" + words = line.split(" ") + self._name = words.pop(0) + while self._hash == "": + self._hash = words.pop(0) + self._commit = " ".join(words) + + def to_s_long(self): + print("Name : " + self._name) + print("Hash : " + self._hash) + print("Commit: " + self._commit) + + def to_s(self): + print(" ".join({self._name, self._hash, self._commit})) + +class Repo: + + def __init__(self): + self._commits = OrderedDict() + self._branches = [] + + def add_commit(self, commit): + if commit._hash: + self._commits[commit._hash] = commit + + def resolve_parents(self): + for commit in self._commits.values(): + for key_p in commit._parents.keys(): + commit.update_parent(self._commits[key_p]) + + def add_branch(self, branch): + if self._commits.has_key(branch._hash): + branch._commit = self._commits[branch._hash] + self._branches.append( branch) + + def export_to_tikz(self): + print("\\begin{tikzpicture}") + print("\\tikzstyle{commit}=[draw,circle,fill=white,inner sep=0pt,minimum size=5pt]") + print("\\tikzstyle{every path}=[draw]") + print("\\tikzstyle{branch}=[draw,rectangle,rounded corners=3,fill=white,inner sep=2pt,minimum size=5pt]") + ypos = 0 + ystep = .5 + for commit in reversed(self._commits.values()): + commit.export_to_tikz(ypos) + ypos = ypos + ystep + + for commit in self._commits.values(): + for child in commit._children.values(): + print("\\path[" + color(commit._node_pos) +"] (" + commit._hash + ") to[out=90,in=-90] (" + child._hash + ");") + + for branch in self._branches: + print("\\node[branch,right,xshift=10] (" + branch._name + ") at (label_" + branch._hash + ".east) {\\lstinline{" + branch._name +"}};") + print("\\end{tikzpicture}") + +# extract Commits +cmd = "git log --branches --graph --parents" + +return_output = check_output(cmd, shell=True, encoding='utf-8') +#print(return_output.split("\n")) + + +for line in return_output.split("\n"): + if not line == "": + + node_pos = -1 + message_pos = -1 + + pos = 0 + for c in line: + if c == '*': + node_pos = pos + elif linepat.match(c) and c != ' ': + message_pos = pos + break + pos = pos + 1 + + msg = line[message_pos:] + if node_pos >= 0: + com = msg.split(' ') + else: + inf = msg.split(':') + + +print(node_pos + message_pos) + + -- 2.47.3