Mercurial > hg > hg-git
diff hggit/git_handler.py @ 283:90458271e374
use a simple toposort algorithm for DAG (post order from a DFS from the heads)
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Wed, 24 Feb 2010 17:21:23 +0100 |
parents | 8655c071a15d |
children | 12cfa77a2ab0 |
line wrap: on
line diff
--- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -1,5 +1,4 @@ import os, math, urllib, re -import toposort from dulwich.errors import HangupException from dulwich.index import commit_tree @@ -371,19 +370,25 @@ todo.append(sha) # traverse the heads getting a list of all the unique commits + commits = [] + seen = set(todo) while todo: - sha = todo.pop() + sha = todo[-1] + if sha in done: + todo.pop() + continue assert isinstance(sha, str) - if sha in done: - continue - done.add(sha) obj = self.git.get_object(sha) assert isinstance(obj, Commit) - convert_list[sha] = obj - todo.extend([p for p in obj.parents if p not in done]) - - # sort the commits - commits = toposort.TopoSort(convert_list).items() + for p in obj.parents: + if p not in done: + todo.append(p) + break + else: + commits.append(sha) + convert_list[sha] = obj + done.add(sha) + todo.pop() commits = [commit for commit in commits if not commit in self._map_git] # import each of the commits, oldest first