Use open_repository to find repository for get_peeled.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 2 Apr 2010 02:45:54 +0000 (04:45 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 2 Apr 2010 02:45:54 +0000 (04:45 +0200)
dulwich/server.py
dulwich/tests/test_server.py

index c44cc010597020582ab460570eec08226eaeaff9..971f2c75ce66940e82b5eb9c882347d510a38b4f 100644 (file)
@@ -75,6 +75,16 @@ class BackendRepo(object):
         """
         raise NotImplementedError
 
+    def get_peeled(self, name):
+        """Return the cached peeled value of a ref, if available.
+
+        :param name: Name of the ref to peel
+        :return: The peeled value of the ref. If the ref is known not point to
+            a tag, this will be the SHA the ref refers to. If the ref may 
+            point to a tag, but no cached information is available, None is 
+            returned.  """
+        return None
+
     def apply_pack(self, refs, read, delete_refs=True):
         """ Import a set of changes into a repository and update the refs
 
@@ -267,7 +277,8 @@ class UploadPackHandler(Handler):
     def handle(self):
         write = lambda x: self.proto.write_sideband(1, x)
 
-        graph_walker = ProtocolGraphWalker(self, self.repo.object_store)
+        graph_walker = ProtocolGraphWalker(self, self.repo.object_store,
+            self.repo.get_peeled)
         objects_iter = self.repo.fetch_objects(
           graph_walker.determine_wants, graph_walker, self.progress,
           get_tagged=self.get_tagged)
@@ -298,9 +309,10 @@ class ProtocolGraphWalker(object):
     call to set_ack_level() is required to set up the implementation, before any
     calls to next() or ack() are made.
     """
-    def __init__(self, handler, object_store):
+    def __init__(self, handler, object_store, get_peeled):
         self.handler = handler
         self.store = object_store
+        self.get_peeled = get_peeled
         self.proto = handler.proto
         self.stateless_rpc = handler.stateless_rpc
         self.advertise_refs = handler.advertise_refs
@@ -330,7 +342,7 @@ class ProtocolGraphWalker(object):
                 if not i:
                     line = "%s\x00%s" % (line, self.handler.capability_line())
                 self.proto.write_pkt_line("%s\n" % line)
-                peeled_sha = self.handler.backend.repo.get_peeled(ref)
+                peeled_sha = self.get_peeled(ref)
                 if peeled_sha != sha:
                     self.proto.write_pkt_line('%s %s^{}\n' %
                                               (peeled_sha, ref))
index ce56b14bc30a2dd247310c6a80e6ff31acf47d04..bc7d2386dd318c155271880e2fe5415c79c6d010 100644 (file)
@@ -229,7 +229,7 @@ class ProtocolGraphWalkerTestCase(TestCase):
 
         self._walker = ProtocolGraphWalker(
             TestUploadPackHandler(self._objects, TestProto()),
-            self._objects)
+            self._objects, None)
 
     def test_is_satisfied_no_haves(self):
         self.assertFalse(self._walker._is_satisfied([], ONE, 0))
@@ -281,7 +281,7 @@ class ProtocolGraphWalkerTestCase(TestCase):
             'want %s' % TWO,
             ])
         heads = {'ref1': ONE, 'ref2': TWO, 'ref3': THREE}
-        self._walker.handler.backend.repo.peeled = heads
+        self._walker.get_peeled = heads.get
         self.assertEquals([ONE, TWO], self._walker.determine_wants(heads))
 
         self._walker.proto.set_output(['want %s multi_ack' % FOUR])
@@ -301,7 +301,7 @@ class ProtocolGraphWalkerTestCase(TestCase):
         # advertise branch tips plus tag
         heads = {'ref4': FOUR, 'ref5': FIVE, 'tag6': SIX}
         peeled = {'ref4': FOUR, 'ref5': FIVE, 'tag6': FIVE}
-        self._walker.handler.backend.repo.peeled = peeled
+        self._walker.get_peeled = peeled.get
         self._walker.determine_wants(heads)
         lines = []
         while True: