dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00619
[PATCH 20/34] repo: Implement revision_history with a Walker.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: Ic6f7a4186757100e2a5203747b91858a51b278cc
---
dulwich/repo.py | 52 +++++++++++-----------------------------------------
1 files changed, 11 insertions(+), 41 deletions(-)
diff --git a/dulwich/repo.py b/dulwich/repo.py
index dea3a8e..94f896e 100644
--- a/dulwich/repo.py
+++ b/dulwich/repo.py
@@ -53,6 +53,9 @@ from dulwich.objects import (
Tree,
hex_to_sha,
)
+from dulwich.walk import (
+ Walker,
+ )
import warnings
@@ -954,48 +957,15 @@ class BaseRepo(object):
def revision_history(self, head):
"""Returns a list of the commits reachable from head.
- Returns a list of commit objects. the first of which will be the commit
- of head, then following that will be the parents.
-
- Raises NotCommitError if any no commits are referenced, including if the
- head parameter isn't the sha of a commit.
-
- XXX: work out how to handle merges.
+ :param head: The SHA of the head to list revision history for.
+ :return: A list of commit objects reachable from head, starting with
+ head itself, in descending commit time order.
+ :raise MissingCommitError: if any missing commits are referenced,
+ including if the head parameter isn't the SHA of a commit.
"""
-
- try:
- commit = self[head]
- except KeyError:
- raise MissingCommitError(head)
-
- if type(commit) != Commit:
- raise NotCommitError(commit)
- pending_commits = [commit]
-
- history = set()
-
- while pending_commits != []:
- commit = pending_commits.pop(0)
-
- if commit in history:
- continue
-
- history.add(commit)
-
- for parent in commit.parents:
- try:
- commit = self[parent]
- except KeyError:
- raise MissingCommitError(head)
-
- if type(commit) != Commit:
- raise NotCommitError(commit)
-
- pending_commits.append(commit)
-
- history = list(history)
- history.sort(key=lambda c:c.commit_time, reverse=True)
- return history
+ # TODO(dborowitz): Expose more of the Walker functionality here or in a
+ # separate Repo/BaseObjectStore method.
+ return [e.commit for e in Walker(self.object_store, [head])]
def __getitem__(self, name):
if len(name) in (20, 40):
--
1.7.3.1
References