formatting fixes, trailing whitespace, unused imports.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 5 Dec 2012 04:25:07 +0000 (05:25 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 5 Dec 2012 04:25:07 +0000 (05:25 +0100)
dulwich/object_store.py
dulwich/tests/test_missing_obj_finder.py

index 235110dbdf4d156502d5c331acc1e3bf95af2ecf..2765034758a50611f07fe676004068c70d754d80 100644 (file)
@@ -221,10 +221,12 @@ class BaseObjectStore(object):
             obj = self[sha]
         return obj
 
-    def _collect_ancestors(self, heads, common = set()):
-        """Collect all ancestors of heads up to (excluding) those in common
+    def _collect_ancestors(self, heads, common=set()):
+        """Collect all ancestors of heads up to (excluding) those in common.
+
         :param heads: commits to start from
-        :param common: commits to end at, or empty set to walk repository completely
+        :param common: commits to end at, or empty set to walk repository
+            completely
         :return: a tuple (A, B) where A - all commits reachable
             from heads but not present in common, B - common (shared) elements
             that are directly reachable from heads
@@ -815,30 +817,34 @@ def tree_lookup_path(lookup_obj, root_sha, path):
         raise NotTreeError(root_sha)
     return tree.lookup_path(lookup_obj, path)
 
+
 def _collect_filetree_revs(obj_store, tree_sha, kset):
-    """Collect SHA1s of files and directories for specified tree
-        (identified by SHA1)
+    """Collect SHA1s of files and directories for specified tree.
+
     :param obj_store: Object store to get objects by SHA from
     :param tree_sha: tree reference to walk
     :param kset: set to fill with references to files and directories
     """
     filetree = obj_store[tree_sha]
-    for name,mode,sha in filetree.iteritems():
+    for name, mode, sha in filetree.iteritems():
        if not S_ISGITLINK(mode) and sha not in kset:
            kset.add(sha)
            if stat.S_ISDIR(mode):
                _collect_filetree_revs(obj_store, sha, kset)
 
-def _split_commits_and_tags(obj_store, lst, ignore_unknown = False):
-    """Split lst into two lists, one with commit SHA1s, another with
-        tag SHA1s. Commits referenced by tags are included into commits
-        list as well. Only SHA1s known in this repository will get
-        through, and unless ignore_unknown argument is True, KeyError
-        is thrown for SHA1 missing in the repository
+
+def _split_commits_and_tags(obj_store, lst, ignore_unknown=False):
+    """Split object id list into two list with commit SHA1s and tag SHA1s.
+
+    Commits referenced by tags are included into commits
+    list as well. Only SHA1s known in this repository will get
+    through, and unless ignore_unknown argument is True, KeyError
+    is thrown for SHA1 missing in the repository
+
     :param obj_store: Object store to get objects by SHA1 from
     :param lst: Collection of commit and tag SHAs
-    :param ignore_unknown: True to skip SHA1 missing in the 
-        repository silently.
+    :param ignore_unknown: True to skip SHA1 missing in the repository
+        silently.
     :return: A tuple of (commits, tags) SHA1s
     """
     commits = set()
@@ -847,9 +853,7 @@ def _split_commits_and_tags(obj_store, lst, ignore_unknown = False):
         try:
             o = obj_store[e]
         except KeyError:
-            if ignore_unknown:
-                pass
-            else:
+            if not ignore_unknown:
                 raise
         else:
             if isinstance(o, Commit):
index 7e69b3d782f88a2d60e362e719d206a1c8523047..39f5349768eed2c9c1828954b198340f6af56cdf 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
-from dulwich.errors import (
-    MissingCommitError,
-    )
 from dulwich.object_store import (
     MemoryObjectStore,
     )
 from dulwich.objects import (
-    Commit,
     Blob,
     )
 from dulwich.tests import TestCase
 from utils import (
-    F,
     make_object,
     build_commit_graph,
     )
 
+
 class MissingObjectFinderTest(TestCase):
 
     def setUp(self):
@@ -40,21 +36,21 @@ class MissingObjectFinderTest(TestCase):
         self.store = MemoryObjectStore()
         self.commits = []
 
-    def __getitem__(self, n):
-        # rename for brevity
-        return self.commits[n-1]
-
     def cmt(self, n):
-        return self[n]
+        return self.commits[n-1]
 
     def assertMissingMatch(self, haves, wants, expected):
-        for sha,path in self.store.find_missing_objects(haves, wants):
-            self.assertTrue(sha in expected, "FAILURE: (%s,%s) erroneously reported as missing" % (sha,path))
+        for sha, path in self.store.find_missing_objects(haves, wants):
+            self.assertTrue(sha in expected,
+                "FAILURE: (%s,%s) erroneously reported as missing" %
+                (sha, path))
             expected.remove(sha)
 
         self.assertFalse(len(expected) > 0, "FAILURE: some objects are not reported as missing: %s" % (expected))
 
+
 class MOFLinearRepoTest(MissingObjectFinderTest):
+
     def setUp(self):
         super(MOFLinearRepoTest, self).setUp()
         f1_1 = make_object(Blob, data='f1') # present in 1, removed in 3
@@ -80,13 +76,16 @@ class MOFLinearRepoTest(MissingObjectFinderTest):
 
 
     def test_1_to_2(self):
-        self.assertMissingMatch([self.cmt(1).id], [self.cmt(2).id], self.missing_1_2)
+        self.assertMissingMatch([self.cmt(1).id], [self.cmt(2).id],
+            self.missing_1_2)
 
     def test_2_to_3(self):
-        self.assertMissingMatch([self.cmt(2).id], [self.cmt(3).id], self.missing_2_3)
+        self.assertMissingMatch([self.cmt(2).id], [self.cmt(3).id],
+            self.missing_2_3)
 
     def test_1_to_3(self):
-        self.assertMissingMatch([self.cmt(1).id], [self.cmt(3).id], self.missing_1_3)
+        self.assertMissingMatch([self.cmt(1).id], [self.cmt(3).id],
+            self.missing_1_3)
 
     def test_bogus_haves_failure(self):
         """Ensure non-existent SHA in haves are not tolerated"""
@@ -100,11 +99,13 @@ class MOFLinearRepoTest(MissingObjectFinderTest):
         bogus_sha = self.cmt(2).id[::-1]
         haves = [self.cmt(1).id]
         wants = [self.cmt(3).id, bogus_sha]
-        self.assertRaises(KeyError, self.store.find_missing_objects, self.store, haves, wants)
+        self.assertRaises(KeyError, self.store.find_missing_objects,
+            self.store, haves, wants)
 
     def test_no_changes(self):
         self.assertMissingMatch([self.cmt(3).id], [self.cmt(3).id], [])
 
+
 class MOFMergeForkRepoTest(MissingObjectFinderTest):
     """ 1 --- 2 --- 4 --- 6 --- 7
                \        /
@@ -187,10 +188,9 @@ class MOFMergeForkRepoTest(MissingObjectFinderTest):
           have 5, want 7. Common parent is rev2, hence children of rev2 from
           a descent line other than rev5 shall be reported
         """
-        # expects f1_4 from rev6. f3_5 is known in rev5; 
+        # expects f1_4 from rev6. f3_5 is known in rev5;
         # f1_7 shall be the same as f1_2 (known, too)
         self.assertMissingMatch([self.cmt(5).id], [self.cmt(7).id], [
               self.cmt(7).id, self.cmt(6).id, self.cmt(4).id,
               self.cmt(7).tree, self.cmt(6).tree, self.cmt(4).tree,
-              self.f1_4_id]) 
-
+              self.f1_4_id])