From: Peter Schaefer Date: Wed, 2 Jan 2019 20:07:59 +0000 (+0100) Subject: [py] Commit funktioniert X-Git-Tag: v1.0~13 X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=afd6f5af80c64fdb9e9263a0176e5315da32561a;p=tex_tools.git [py] Commit funktioniert --- diff --git a/git-log-to-tikz.py b/git-log-to-tikz.py index e056b15..c1da957 100644 --- a/git-log-to-tikz.py +++ b/git-log-to-tikz.py @@ -1,19 +1,39 @@ -from subprocess import Popen, check_output +from subprocess import check_output +import re +hashpat = re.compile(r"[a-f0-9]{7}") +linepat = re.compile(r'[^|\/\\]') class Commit: + _line = None _hash = None _children = None - _parents = None - _message = None + _parents = {} + _message= None + _message_pos = None _node_pos = None _node_color = None - def __init__(self): - self._children = hash.__new__() - self._parents = hash.__new__() - self._message = "" - self._node_pos = 0 + def __init__(self,line): + + 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 + class Branch: @@ -35,9 +55,23 @@ class Branch: def to_s(self): print(" ".join({self._name, self._hash, self._commit})) +class Repo: + _commits = {} + + def add_commit(self, commit): + if commit._hash: + self._commits[commit._hash] = commit + cmd = "git log --graph --oneline --parents" return_output = check_output(cmd, shell=True) print(return_output.split("\n")) + +r = Repo() + +for line in return_output.split("\n"): + r.add_commit(Commit(line)) + +print() \ No newline at end of file