Browse Source

Improved Repo.revision_history(head)

Timo Schmid 14 years ago
parent
commit
e79893c620
1 changed files with 20 additions and 19 deletions
  1. 20 19
      dulwich/repo.py

+ 20 - 19
dulwich/repo.py

@@ -962,28 +962,29 @@ class BaseRepo(object):
 
         XXX: work out how to handle merges.
         """
-        # We build the list backwards, as parents are more likely to be older
-        # than children
-        pending_commits = [head]
-        history = []
+        
+        try:
+            pending_commits = [self.commit(head)]
+        except KeyError:
+            raise MissingCommitError(head)
+        history = set()
+        
         while pending_commits != []:
-            head = pending_commits.pop(0)
-            try:
-                commit = self[head]
-            except KeyError:
-                raise MissingCommitError(head)
-            if type(commit) != Commit:
-                raise NotCommitError(commit)
+            commit = pending_commits.pop(0)
+
             if commit in history:
                 continue
-            i = 0
-            for known_commit in history:
-                if known_commit.commit_time > commit.commit_time:
-                    break
-                i += 1
-            history.insert(i, commit)
-            pending_commits += commit.parents
-        history.reverse()
+
+            history.add(commit)
+            
+            for parent in commit.parents:
+                try:
+                    pending_commits.append(self.commit(parent))
+                except KeyError:
+                    raise MissingCommitError(parent)
+        
+        history = list(history)
+        history.sort(key=lambda c:c.commit_time, reverse=True)
         return history
 
     def __getitem__(self, name):