From: Peter Schaefer Date: Wed, 2 Jan 2019 20:59:42 +0000 (+0100) Subject: [py] commit & branch läuft X-Git-Tag: v1.0~12 X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=3dbbd41041d10003d90938f52a84ed3560f35d51;p=tex_tools.git [py] commit & branch läuft --- diff --git a/git-log-to-tikz.py b/git-log-to-tikz.py index c1da957..c748b14 100644 --- a/git-log-to-tikz.py +++ b/git-log-to-tikz.py @@ -5,16 +5,15 @@ hashpat = re.compile(r"[a-f0-9]{7}") linepat = re.compile(r'[^|\/\\]') class Commit: - _line = None - _hash = None - _children = None - _parents = {} - _message= None - _message_pos = None - _node_pos = None - _node_color = None - 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 @@ -32,19 +31,24 @@ class Commit: self._message = word self._message_pos = pos - pos = pos + 1 + pos = pos + 1 + def update_parent (self, child): + self._parents[child._hash] = child + child._children[self._hash] = self + + def export_to_tikz(self, ypos): + print("export Commit:") + class Branch: - _name = "" - _hash = "" - _commit = "" - def __init__(self, line): + self._hash="" words = line.split(" ") self._name = words.pop(0) - self._hash = words.pop(0) + while self._hash == "": + self._hash = words.pop(0) self._commit = " ".join(words) def to_s_long(self): @@ -56,22 +60,44 @@ class Branch: print(" ".join({self._name, self._hash, self._commit})) class Repo: - _commits = {} + + def __init__(self): + self._commits = {} + self._branches = [] def add_commit(self, commit): if commit._hash: self._commits[commit._hash] = commit + def resolve_parents(self): + for key_c, commit in self._commits.iteritems(): + for key_p, parent in commit._parents.iteritems(): + 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) cmd = "git log --graph --oneline --parents" return_output = check_output(cmd, shell=True) -print(return_output.split("\n")) +#print(return_output.split("\n")) r = Repo() for line in return_output.split("\n"): - r.add_commit(Commit(line)) + if not line == "": + r.add_commit(Commit(line)) + +r.resolve_parents() + +cmd = "git branch -av | cut -b 3-" + +return_output = check_output(cmd, shell=True) +for line in return_output.split("\n"): + if not line == "": + r.add_branch(Branch(line)) -print() \ No newline at end of file +print(return_output.split("\n")) \ No newline at end of file