Browse Source

Add shallow grafts to repo before fetching objects

milki 11 years ago
parent
commit
9d53251a15
1 changed files with 33 additions and 0 deletions
  1. 33 0
      dulwich/repo.py

+ 33 - 0
dulwich/repo.py

@@ -248,11 +248,44 @@ class BaseRepo(object):
         wants = determine_wants(self.get_refs())
         if type(wants) is not list:
             raise TypeError("determine_wants() did not return a list")
+
+        try:
+            has_shallows = getattr(graph_walker, 'shallow')
+            has_unshallows = getattr(graph_walker, 'unshallow')
+        except AttributeError:
+            # Walker doesn't support shallows
+            has_shallows = False
+            has_unshallows = False
+
         if wants == []:
             # TODO(dborowitz): find a way to short-circuit that doesn't change
             # this interface.
+
+            if has_shallows or has_unshallows:
+                # Do not send a pack in shallow short-circuit path
+                return None
+
             return []
+
         haves = self.object_store.find_common_revisions(graph_walker)
+
+        # Deal with shallow requests separately because the haves do
+        # not reflect what objects are missing
+        if has_shallows or has_unshallows:
+            # Set the shallow commits in the object_store
+            shallow_grafts = {}
+            for shallow in graph_walker.shallow:
+                shallow_grafts[shallow] = []
+            self._add_graftpoints(shallow_grafts)
+
+            haves = []  # TODO: filter haves from iter_shas
+
+            shas = self.object_store.iter_shas(
+              self.object_store.find_missing_objects(haves, wants, progress,
+                                                     get_tagged))
+            self._remove_graftpoints(shallow_grafts)
+            return shas
+
         return self.object_store.iter_shas(
           self.object_store.find_missing_objects(haves, wants, progress,
                                                  get_tagged))