def CreateLogGraph(self):
        rows = []  # items: (node, edges)
        nodes = {} # commit => GraphNode
        lanes = []
        color = 0

        self.rows = rows
        self.columns = 0
        self.nodes = nodes
        
        for y in xrange(len(self.commits)):
            # 1. Create node
            commit = self.commits[y]
            node = GraphNode(commit)
            nodes[commit] = node
            node.y = y
            rows.append((node, []))

            # 2. Determine column
            x = None

            # 2.1. search for a commit in lanes whose parent is c
            for i in xrange(len(lanes)):
                if lanes[i] and commit in lanes[i].commit.parents:
                    x = i
                    node.color = lanes[i].color
                    break

            # 2.2. if there is no such commit, put to the first empty place
            if x == None:
                node.color = color
                color += 1
                if None in lanes:
                    x = lanes.index(None)
                else:
                    x = len(lanes)
                    lanes.append(None)

            node.x = x
            self.columns = max(self.columns, x)

            # 3. Create edges
            for child_commit in commit.children:
                child = nodes[child_commit]
                edge = GraphEdge(node, child)
                node.child_edges.append(edge)
                child.parent_edges.append(edge)

                # 3.1. Determine edge style
                if child.x == node.x and lanes[x] == child:
                    edge.style = EDGE_DIRECT
                    edge.x = node.x
                    edge.color = child.color
                elif len(child_commit.parents) == 1:
                    edge.style = EDGE_BRANCH
                    edge.x = child.x
                    edge.color = child.color
                else:
                    edge.style = EDGE_MERGE
                    edge.color = node.color

                    # Determine column for merge edges
                    edge.x = max(node.x, child.x+1)
                    success = False
                    while not success:
                        success = True
                        for yy in xrange(node.y, child.y, -1):
                            n, edges = rows[yy]
                            if (yy < node.y and n.x == edge.x) or (len(edges) > edge.x and edges[edge.x] != None):
                                edge.x += 1
                                success = False
                                break

                # 3.2. Register edge in rows
                for yy in xrange(node.y, child.y, -1):
                    n, edges = rows[yy]
                    if len(edges) < edge.x+1:
                        edges += [None] * (edge.x+1 - len(edges))
                    edges[edge.x] = edge

                self.columns = max(self.columns, edge.x)

            # 4. End those lanes whose parents are already drawn
            for i in xrange(len(lanes)):
                if lanes[i] and len(lanes[i].parent_edges) == len(lanes[i].commit.parents):
                    lanes[i] = None

            lanes[x] = node

        # References
        if self.repo.current_branch:
            self._add_reference(self.repo.head, self.repo.current_branch, REF_HEADBRANCH)
        else:
            self._add_reference(self.repo.head, 'DETACHED HEAD', REF_DETACHEDHEAD)

        if self.repo.main_ref:
            self._add_reference(self.repo.main_ref, 'MAIN/HEAD', REF_MODULE)
        if self.repo.main_merge_ref:
            self._add_reference(self.repo.main_merge_ref, 'MAIN/MERGE_HEAD', REF_MODULE)

        for branch,commit_id in self.repo.branches.iteritems():
            if branch != self.repo.current_branch:
                self._add_reference(commit_id, branch, REF_BRANCH)
        for branch,commit_id in self.repo.remote_branches.iteritems():
            self._add_reference(commit_id, branch, REF_REMOTE)
        for tag,commit_id in self.repo.tags.iteritems():
            self._add_reference(commit_id, tag, REF_TAG)
dataset/ETHPy150Open gyim/stupidgit/stupidgit_gui/CommitList.py/CommitList.CreateLogGraph/original