← Back to team overview

dulwich-users team mailing list archive

[MERGE] Deprecate ``Repo.revision_history`` in favour of ``Repo.get_walker``.

 

The attached patch deprecates ``Repo.revision_history`` in favour of
the more powerful ``Repo.get_walker``, which is a simple wrapper of
dulwich.walk.Walker.

Cheers,

Jelmer
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: jelmer@xxxxxxxxx-20110903143056-7tr5t251sfsj8g6j
# target_branch: file:///home/jelmer/src/dulwich/trunk/
# testament_sha1: a5443694fa65fd3f3053aa116e1c9656325389a2
# timestamp: 2011-09-03 16:31:40 +0200
# base_revision_id: git-v1:f6f410694154c771f101e9f2e145c849534bade4
# 
# Begin patch
=== modified file 'NEWS'
--- NEWS	2011-09-03 13:46:10 +0000
+++ NEWS	2011-09-03 14:30:56 +0000
@@ -6,6 +6,8 @@
 
   * Repo.do_commit has a new argument 'merge_heads'. (Jelmer Vernooij)
 
+  * New ``Repo.get_walker`` method. (Jelmer Vernooij)
+
   * New ``Repo.clone`` method. (Jelmer Vernooij, #725369)
 
  CHANGES
@@ -13,6 +15,11 @@
   * unittest2 or python >= 2.7 is now required for the testsuite.
     testtools is no longer supported. (Jelmer Vernooij, #830713)
 
+ API CHANGES
+
+  * ``Repo.revision_history`` is now deprecated in favour of ``Repo.get_walker``.
+    (Jelmer Vernooij)
+
 0.8.0	2011-08-07
 
  FEATURES

=== modified file 'dulwich/repo.py'
--- dulwich/repo.py	2011-09-03 13:46:10 +0000
+++ dulwich/repo.py	2011-09-03 14:30:56 +0000
@@ -52,9 +52,6 @@
     Tree,
     hex_to_sha,
     )
-from dulwich.walk import (
-    Walker,
-    )
 import warnings
 
 
@@ -953,6 +950,35 @@
             return cached
         return self.object_store.peel_sha(self.refs[ref]).id
 
+    def get_walker(self, include=None, *args, **kwargs):
+        """Obtain a walker for this repository.
+
+        :param include: Iterable of SHAs of commits to include along with their
+            ancestors. Defaults to [HEAD]
+        :param exclude: Iterable of SHAs of commits to exclude along with their
+            ancestors, overriding includes.
+        :param order: ORDER_* constant specifying the order of results. Anything
+            other than ORDER_DATE may result in O(n) memory usage.
+        :param reverse: If True, reverse the order of output, requiring O(n)
+            memory.
+        :param max_entries: The maximum number of entries to yield, or None for
+            no limit.
+        :param paths: Iterable of file or subtree paths to show entries for.
+        :param rename_detector: diff.RenameDetector object for detecting
+            renames.
+        :param follow: If True, follow path across renames/copies. Forces a
+            default rename_detector.
+        :param since: Timestamp to list commits after.
+        :param until: Timestamp to list commits before.
+        :param queue_cls: A class to use for a queue of commits, supporting the
+            iterator protocol. The constructor takes a single argument, the
+            Walker.
+        """
+        from dulwich.walk import Walker
+        if include is None:
+            include = [self.head()]
+        return Walker(self.object_store, include, *args, **kwargs)
+
     def revision_history(self, head):
         """Returns a list of the commits reachable from head.
 
@@ -962,9 +988,10 @@
         :raise MissingCommitError: if any missing commits are referenced,
             including if the head parameter isn't the SHA of a commit.
         """
-        # 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])]
+        warnings.warn("Repo.revision_history() is deprecated."
+            "Use dulwich.walker.Walker(repo) instead.",
+            category=DeprecationWarning, stacklevel=2)
+        return [e.commit for e in self.get_walker(include=[head])]
 
     def __getitem__(self, name):
         if len(name) in (20, 40):

=== modified file 'dulwich/tests/test_repository.py'
--- dulwich/tests/test_repository.py	2011-09-03 13:46:10 +0000
+++ dulwich/tests/test_repository.py	2011-09-03 14:30:56 +0000
@@ -247,8 +247,19 @@
         self.addCleanup(warnings.resetwarnings)
         self.assertRaises(errors.NotBlobError, r.get_blob, r.head())
 
+    def test_get_walker(self):
+        r = self._repo = open_repo('a.git')
+        # include defaults to [r.head()]
+        self.assertEqual([e.commit.id for e in r.get_walker()],
+                         [r.head(), '2a72d929692c41d8554c07f6301757ba18a65d91'])
+        self.assertEqual(
+            [e.commit.id for e in r.get_walker(['2a72d929692c41d8554c07f6301757ba18a65d91'])],
+            ['2a72d929692c41d8554c07f6301757ba18a65d91'])
+
     def test_linear_history(self):
         r = self._repo = open_repo('a.git')
+        warnings.simplefilter("ignore", DeprecationWarning)
+        self.addCleanup(warnings.resetwarnings)
         history = r.revision_history(r.head())
         shas = [c.sha().hexdigest() for c in history]
         self.assertEqual(shas, [r.head(),
@@ -268,15 +279,13 @@
             'refs/tags/mytag-packed':
                 'b0931cadc54336e78a1d980420e3268903b57a50',
             }, t.refs.as_dict())
-        history = t.revision_history(t.head())
-        shas = [c.sha().hexdigest() for c in history]
+        shas = [e.commit.id for e in r.get_walker()]
         self.assertEqual(shas, [t.head(),
                          '2a72d929692c41d8554c07f6301757ba18a65d91'])
 
     def test_merge_history(self):
         r = self._repo = open_repo('simple_merge.git')
-        history = r.revision_history(r.head())
-        shas = [c.sha().hexdigest() for c in history]
+        shas = [e.commit.id for e in r.get_walker()]
         self.assertEqual(shas, ['5dac377bdded4c9aeb8dff595f0faeebcc8498cc',
                                 'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
                                 '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6',
@@ -285,14 +294,15 @@
 
     def test_revision_history_missing_commit(self):
         r = self._repo = open_repo('simple_merge.git')
+        warnings.simplefilter("ignore", DeprecationWarning)
+        self.addCleanup(warnings.resetwarnings)
         self.assertRaises(errors.MissingCommitError, r.revision_history,
                           missing_sha)
 
     def test_out_of_order_merge(self):
         """Test that revision history is ordered by date, not parent order."""
         r = self._repo = open_repo('ooo_merge.git')
-        history = r.revision_history(r.head())
-        shas = [c.sha().hexdigest() for c in history]
+        shas = [e.commit.id for e in r.get_walker()]
         self.assertEqual(shas, ['7601d7f6231db6a57f7bbb79ee52e4d462fd44d1',
                                 'f507291b64138b875c28e03469025b1ea20bc614',
                                 'fb5b0425c7ce46959bec94d54b9a157645e114f5',

=== modified file 'dulwich/walk.py'
--- dulwich/walk.py	2011-07-29 17:08:26 +0000
+++ dulwich/walk.py	2011-09-03 14:30:56 +0000
@@ -221,6 +221,8 @@
             iterator protocol. The constructor takes a single argument, the
             Walker.
         """
+        # Note: when adding arguments to this method, please also update
+        # dulwich.repo.BaseRepo.get_walker
         if order not in ALL_ORDERS:
             raise ValueError('Unknown walk order %s' % order)
         self.store = store

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWUCrCQ8ABLr/gERQAgBY9//3
f/Hfiv////BgCYn3e48Y3pQAzkultktJll26ddu2uISSETBNqJtGTUxTaao/SnonpN6NU/SD0oP0
KeUMQJJAAgETSnhQeUNNGg0AGgA0ACpsU2pAGgZAAAAZGgAAAAJEUaZKPTRU/TVPGmiepPKZqP0Q
Q8kDQaADIOMmTRiGJpgIGBNMEYJiaaaADCCRTRNQMQT0mjU2ptU/U8qe1J6m1AMRtIBoeoNJABUB
X2X22O1FLejOm3jM947z+/KlnGnorqG16v2rqkyYDprSMgbZVMTt3dth32XjeP4ErZ9WSH7eHhbW
iAZhG9Q4bxrdnyteCn7LUnOPaCEDkgWd7wHhgHvDODBsbSbbXw/UDyniZlzSzlgTnOjNDZSsyQIY
SLALnGISBRpFBJUL4VwBBmQoUc7ys3RlzGmvB8o7kdtLefp5qP9SsqDBc9+T71D99DTllZ1/dxeG
UefBVVkWlbLT+JQFKmkch8g2g4x6UNXH7+WrpSb00FjOeMNv5JtSilD6o5y9sHS1mMPHOZjpd6jh
8ZhxKUY+V/JG7rkuV3QujFNYWtO7NWoDn7ZN1lo5h/IwVQi2G2cfVf7enp6uylMy8cZGXYHXi2tX
uGjmOcCZiHvd2sk4YDAtHp8GyqX/OjUX27Xpht9DsDO8Rwazm3teu+/WSR7sWN7TbXKVhmrP7YPe
Q5290xpIDE+aDXwjB7gXmBaJ69sAPhzVl3WubL8b1tgx7NmirRYUyiYXXMviREoXovybgiNGRKZA
22bA6Ja1U4w+3B0iG34VEeVgm02GmI88dXiwUQmLk4An7PEtbwpAYFaoE1oe91QBWCjDg6OHK7Uu
VHmLwKsvtcq471C3ePhcKhkFmBde43RgeyRaC8rzROnIqcynPl1FX7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