Don't try and send objects if there are none to send (client hung up already)
[jelmer/dulwich-libgit2.git] / dulwich / repo.py
index 66db3a061e0d2d978ff7896944c3e2d74bccb7bf..3d5412b644358fd998cf2b69210f5421212352d1 100644 (file)
@@ -101,33 +101,32 @@ class Repo(object):
     sha_done = set()
     ref = graph_walker.next()
     while ref:
-        sha_done.add(ref)
         if ref in self.object_store:
             graph_walker.ack(ref)
         ref = graph_walker.next()
     while commits_to_send:
-        sha = commits_to_send.pop()
+        sha = (commits_to_send.pop(), None)
         if sha in sha_done:
             continue
 
         c = self.commit(sha)
         assert isinstance(c, Commit)
-        sha_done.add(sha)
+        sha_done.add((sha, None))
 
         commits_to_send.update([p for p in c.parents if not p in sha_done])
 
         def parse_tree(tree, sha_done):
             for mode, name, sha in tree.entries():
-                if sha in sha_done:
+                if (sha, name) in sha_done:
                     continue
                 if mode & stat.S_IFDIR:
                     parse_tree(self.tree(sha), sha_done)
-                sha_done.add(sha)
+                sha_done.add((sha, name))
 
         treesha = c.tree
         if c.tree not in sha_done:
             parse_tree(self.tree(c.tree), sha_done)
-            sha_done.add(c.tree)
+            sha_done.add((c.tree, None))
 
         progress("counting objects: %d\r" % len(sha_done))
     return sha_done
@@ -142,10 +141,10 @@ class Repo(object):
         that a revision is present.
     :param progress: Simple progress function that will be called with 
         updated progress strings.
+    :return: tuple with number of objects, iterator over objects
     """
     shas = self.find_missing_objects(determine_wants, graph_walker, progress)
-    for sha in shas:
-        yield self.get_object(sha)
+    return (len(shas), ((self.get_object(sha), path) for sha, path in shas))
 
   def object_dir(self):
     return os.path.join(self.controldir(), OBJECTDIR)