Parcourir la source

Some cleanup.

Remove untested and only once used mkdir argument to Repo.init_bare.
Remove unused import, trailing whitespace.
Jelmer Vernooij il y a 10 ans
Parent
commit
b61886c0f4
4 fichiers modifiés avec 12 ajouts et 19 suppressions
  1. 3 4
      dulwich/client.py
  2. 1 3
      dulwich/repo.py
  3. 7 3
      dulwich/tests/test_client.py
  4. 1 9
      dulwich/tests/utils.py

+ 3 - 4
dulwich/client.py

@@ -680,8 +680,7 @@ class LocalGitClient(GitClient):
                                  and rejects ref updates
         """
         from dulwich.repo import Repo
-        from dulwich.protocol import ZERO_SHA
-        
+
         target = Repo(path)
         old_refs = target.get_refs()
         new_refs = determine_wants(old_refs)
@@ -693,12 +692,12 @@ class LocalGitClient(GitClient):
             new_sha1 = new_refs.get(refname, ZERO_SHA)
             if new_sha1 not in have and new_sha1 != ZERO_SHA:
                 want.append(new_sha1)
-        
+
         if not want and old_refs == new_refs:
             return new_refs
 
         target.object_store.add_objects(generate_pack_contents(have, want))
-        
+
         for name, sha in new_refs.iteritems():
             target.refs[name] = sha
 

+ 1 - 3
dulwich/repo.py

@@ -888,7 +888,7 @@ class Repo(BaseRepo):
         return cls(path)
 
     @classmethod
-    def init_bare(cls, path, mkdir=False):
+    def init_bare(cls, path):
         """Create a new bare repository.
 
         ``path`` should already exist and be an emty directory.
@@ -896,8 +896,6 @@ class Repo(BaseRepo):
         :param path: Path to create bare repository in
         :return: a `Repo` instance
         """
-        if mkdir:
-            os.mkdir(path)
         return cls._init_maybe_bare(path, True)
 
     create = init_bare

+ 7 - 3
dulwich/tests/test_client.py

@@ -18,6 +18,9 @@
 
 from io import BytesIO
 import sys
+import shutil
+import tempfile
+
 try:
     from unittest import skipIf
 except ImportError:
@@ -55,11 +58,10 @@ from dulwich.objects import (
     )
 from dulwich.repo import (
     MemoryRepo,
-    Repo
+    Repo,
     )
 from dulwich.tests.utils import (
     open_repo,
-    init_repo,
     skipIfPY3,
     )
 
@@ -622,7 +624,9 @@ class LocalGitClientTests(TestCase):
 
     def test_send_pack_with_changes(self):
         local = open_repo('a.git')
-        target = init_repo('a.git')
+        target_path = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, target_path)
+        target = Repo.init_bare(target_path)
         self.send_and_verify("master", local, target)
 
     def send_and_verify(self, branch, local, target):

+ 1 - 9
dulwich/tests/utils.py

@@ -75,21 +75,13 @@ def open_repo(name):
     shutil.copytree(repo_dir, temp_repo_dir, symlinks=True)
     return Repo(temp_repo_dir)
 
-def init_repo(name):
-    """Init an empty bare repo in a temporary directory.
-
-    Use tear_down_repo to delete any temp files created.
-
-    :param name: The name of the repository
-    :returns: An initialized Repo object that lives in a temporary directory.
-    """
-    return Repo.init_bare(os.path.join(tempfile.mkdtemp(), name), mkdir = True)
 
 def tear_down_repo(repo):
     """Tear down a test repository."""
     temp_dir = os.path.dirname(repo.path.rstrip(os.sep))
     shutil.rmtree(temp_dir)
 
+
 def make_object(cls, **attrs):
     """Make an object for testing and assign some members.