-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:
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