Jelmer Vernooij 11 роки тому
батько
коміт
cfced379b2
4 змінених файлів з 74 додано та 1 видалено
  1. 3 0
      NEWS
  2. 55 0
      dulwich/client.py
  3. 1 1
      dulwich/repo.py
  4. 15 0
      dulwich/tests/test_client.py

+ 3 - 0
NEWS

@@ -19,6 +19,9 @@
  * Add support for file:// URLs in `get_transport_and_path_from_url`.
    (Jelmer Vernooij)
 
+ * Add LocalGitClient implementation.
+   (Jelmer Vernooij)
+
  CHANGES
 
   * Ref handling has been moved to dulwich.refs.

+ 55 - 0
dulwich/client.py

@@ -645,6 +645,61 @@ class SubprocessGitClient(TraditionalGitClient):
                         report_activity=self._report_activity), p.can_read
 
 
+class LocalGitClient(GitClient):
+    """Git Client that just uses a local Repo."""
+
+    def __init__(self, thin_packs=True, report_activity=None):
+        """Create a new LocalGitClient instance.
+
+        :param path: Path to the local repository
+        :param thin_packs: Whether or not thin packs should be retrieved
+        :param report_activity: Optional callback for reporting transport
+            activity.
+        """
+        self._report_activity = report_activity
+        # Ignore the thin_packs argument
+
+    def send_pack(self, path, determine_wants, generate_pack_contents,
+                  progress=None):
+        """Upload a pack to a remote repository.
+
+        :param path: Repository path
+        :param generate_pack_contents: Function that can return a sequence of the
+            shas of the objects to upload.
+        :param progress: Optional progress function
+
+        :raises SendPackError: if server rejects the pack data
+        :raises UpdateRefsError: if the server supports report-status
+                                 and rejects ref updates
+        """
+        raise NotImplementedError(self.send_pack)
+
+    def fetch(self, path, target, determine_wants=None, progress=None):
+        """Fetch into a target repository.
+
+        :param path: Path to fetch from
+        :param target: Target repository to fetch into
+        :param determine_wants: Optional function to determine what refs
+            to fetch
+        :param progress: Optional progress function
+        :return: remote refs as dictionary
+        """
+        from dulwich.repo import Repo
+        r = Repo(path)
+        return r.fetch(target, determine_wants=determine_wants, progress=progress)
+
+    def fetch_pack(self, path, determine_wants, graph_walker, pack_data,
+                   progress=None):
+        """Retrieve a pack from a git smart server.
+
+        :param determine_wants: Callback that returns list of commits to fetch
+        :param graph_walker: Object with next() and ack().
+        :param pack_data: Callback called for each bit of data in the pack
+        :param progress: Callback for progress reports (strings)
+        """
+        raise NotImplementedError(self.fetch_pack)
+
+
 # What Git client to use for local access
 default_local_git_client_cls = SubprocessGitClient
 

+ 1 - 1
dulwich/repo.py

@@ -224,7 +224,7 @@ class BaseRepo(object):
         :return: The local refs
         """
         if determine_wants is None:
-            determine_wants = lambda heads: heads.values()
+            determine_wants = target.object_store.determine_wants_all
         target.object_store.add_objects(
           self.fetch_objects(determine_wants, target.get_graph_walker(),
                              progress))

+ 15 - 0
dulwich/tests/test_client.py

@@ -22,6 +22,7 @@ from dulwich import (
     client,
     )
 from dulwich.client import (
+    LocalGitClient,
     TraditionalGitClient,
     TCPGitClient,
     SubprocessGitClient,
@@ -47,6 +48,10 @@ from dulwich.objects import (
     Commit,
     Tree
     )
+from dulwich.repo import MemoryRepo
+from dulwich.tests.utils import (
+    open_repo,
+    )
 
 
 class DummyClient(TraditionalGitClient):
@@ -522,6 +527,7 @@ class SSHGitClientTests(TestCase):
         self.assertEquals(["git-relative-command '~/path/to/repo'"],
                           server.command)
 
+
 class ReportStatusParserTests(TestCase):
 
     def test_invalid_pack(self):
@@ -544,3 +550,12 @@ class ReportStatusParserTests(TestCase):
         parser.handle_packet("ok refs/foo/bar")
         parser.handle_packet(None)
         parser.check()
+
+
+class LocalGitClientTests(TestCase):
+
+    def test_fetch_into_empty(self):
+        c = LocalGitClient()
+        t = MemoryRepo()
+        s = open_repo('a.git')
+        self.assertEquals(s.get_refs(), c.fetch(s.path, t))