# Importer fast fertig
# Aber die light Variante
-hashpat7 = compile(r"[a-f0-9]{7}")
-hashpat32 = compile(r"[a-f0-9]{32}")
linepat = compile(r'[^|\/\\]')
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 Hash:
+ hashpat7 = compile(r"[a-f0-9]{7}")
+ hashpat40 = compile(r"[a-f0-9]{40}")
+ def __init__(self,hash):
+ if Hash.hashpat7.match(hash) or hashpat40.match(hash):
+ self._hash: str = hash
+ else:
+ raise ValueError('Wrong Hash Format')
+
+ def hash(self):
+ return self._hash[0:7]
+
+ def hashLong(self):
+ return self._hash
+
+ def __str__(self):
+ return self._hash[0:7]
+
+ def __len__(self):
+ return len(self._hash)
+
+ def __eq__(self,other):
+ return self.hash() == other.hash()
class Commit:
def __init__(self,line):
self._line = None
- self._hash = None
+ self._hash: Hash = None
self._children = {}
self._parents = {}
self._message= None
if self._hash:
self._message = self._message.replace("!","")
-
def __init__(self,hashes,node_pos,message_pos):
self._children = {}
self._parents = {}
self._node_color = None
self._author = None
self._date = None
- self._hash = hashes[0]
+ self._hash = Hash(hashes[0])
self._node_pos = node_pos
self._message_pos = message_pos
for parent in hashes[1:]:
- self._parents[parent] = NotImplemented
+ self._parents[Hash(parent).hash()] = NotImplemented
+
+ def hash(self):
+ return self._hash.hash()
def AddInfo(self,line):
line = line[self._message_pos:]
return
def update_parent (self, child):
- self._parents[child._hash] = child
- child._children[self._hash] = self
+ 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 + ");")
-
+
+ def __eq__(self,other):
+ return self.hash() == other.hash()
class Branch:
def __init__(self, line):
self._branches = []
def add_commit(self, commit):
- if commit._hash:
- self._commits[commit._hash] = commit
+ if commit.hash():
+ self._commits[commit.hash()] = commit
+ else:
+ raise ValueError('Commit has no hash')
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):
print("\\node[branch,right,xshift=10] (" + branch._name + ") at (label_" + branch._hash + ".east) {\\lstinline{" + branch._name +"}};")
print("\\end{tikzpicture}")
+
+#new Repo
+r = Repo()
+
# extract Commits
cmd = "git log --branches --graph --parents"
return_output = check_output(cmd, shell=True, encoding='utf-8')
#print(return_output.split("\n"))
+comm = None
for line in return_output.split("\n"):
if not line == "":
com = line[message_pos:].split(' ')
if com[0] == 'commit':
comm = Commit(com[1:],node_pos,message_pos)
+ r.add_commit(comm)
else:
- print("something went wrong at:" + line)
+ raise ValueError('looks like a new commit but isn\'t: ' + line)
else: #still old commit
comm.AddInfo(line)
+r.resolve_parents()
print(node_pos + message_pos)