Browse Source

Support passing tag ids to Walkers include argument.

Jelmer Vernooij 8 years ago
parent
commit
e282317837
3 changed files with 25 additions and 6 deletions
  1. 3 0
      NEWS
  2. 7 0
      dulwich/tests/test_walk.py
  3. 15 6
      dulwich/walk.py

+ 3 - 0
NEWS

@@ -22,6 +22,9 @@
  * Allow porcelain.clone of repository without HEAD.
    (Jelmer Vernooij, #501)
 
+ * Support passing tag ids to Walker()'s include argument.
+   (Jelmer Vernooij)
+
 0.16.3	2016-01-14
 
  TEST FIXES

+ 7 - 0
dulwich/tests/test_walk.py

@@ -51,6 +51,7 @@ from dulwich.tests import TestCase
 from dulwich.tests.utils import (
     F,
     make_object,
+    make_tag,
     build_commit_graph,
     )
 
@@ -105,6 +106,12 @@ class WalkerTest(TestCase):
         actual = list(walker)
         self.assertEqual(expected, actual)
 
+    def test_tag(self):
+        c1, c2, c3 = self.make_linear_commits(3)
+        t2 = make_tag(target=c2)
+        self.store.add_object(t2)
+        self.assertWalkYields([c2, c1], [t2.id])
+
     def test_linear(self):
         c1, c2, c3 = self.make_linear_commits(3)
         self.assertWalkYields([c1], [c1.id])

+ 15 - 6
dulwich/walk.py

@@ -36,6 +36,10 @@ from dulwich.diff_tree import (
 from dulwich.errors import (
     MissingCommitError,
     )
+from dulwich.objects import (
+    Commit,
+    Tag,
+    )
 
 ORDER_DATE = 'date'
 ORDER_TOPO = 'topo'
@@ -136,15 +140,20 @@ class _CommitTimeQueue(object):
         for commit_id in chain(walker.include, walker.excluded):
             self._push(commit_id)
 
-    def _push(self, commit_id):
+    def _push(self, object_id):
         try:
-            commit = self._store[commit_id]
+            obj = self._store[object_id]
         except KeyError:
-            raise MissingCommitError(commit_id)
-        if commit_id not in self._pq_set and commit_id not in self._done:
+            raise MissingCommitError(object_id)
+        if isinstance(obj, Tag):
+            self._push(obj.object[1])
+            return
+        # TODO(jelmer): What to do about non-Commit and non-Tag objects?
+        commit = obj
+        if commit.id not in self._pq_set and commit.id not in self._done:
             heapq.heappush(self._pq, (-commit.commit_time, commit))
-            self._pq_set.add(commit_id)
-            self._seen.add(commit_id)
+            self._pq_set.add(commit.id)
+            self._seen.add(commit.id)
 
     def _exclude_parents(self, commit):
         excluded = self._excluded