for refname in set(new_refs.keys() + old_refs.keys()):
old_sha1 = old_refs.get(refname, "0" * 40)
new_sha1 = new_refs.get(refname, "0" * 40)
- if sent_capabilities:
- self.proto.write_pkt_line("%s %s %s" % (old_sha1, new_sha1, refname))
- else:
- self.proto.write_pkt_line("%s %s %s\0%s" % (old_sha1, new_sha1, refname, self.capabilities()))
- sent_capabilities = True
+ if old_sha1 != new_sha1:
+ if sent_capabilities:
+ self.proto.write_pkt_line("%s %s %s" % (old_sha1, new_sha1, refname))
+ else:
+ self.proto.write_pkt_line("%s %s %s\0%s" % (old_sha1, new_sha1, refname, self.capabilities()))
+ sent_capabilities = True
if not new_sha1 in (have, "0" * 40):
want.append(new_sha1)
self.proto.write_pkt_line(None)
+ if not want:
+ return new_refs
objects = generate_pack_contents(have, want)
(entries, sha) = write_pack_data(self.proto.write_file(), objects,
len(objects))
return new_refs
+ 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
+ """
+ if determine_wants is None:
+ determine_wants = target.object_store.determine_wants_all
+ f, commit = target.object_store.add_pack()
+ try:
+ return self.fetch_pack(path, determine_wants, target.graph_walker,
+ f.write, progress)
+ finally:
+ commit()
+
def fetch_pack(self, path, determine_wants, graph_walker, pack_data,
progress):
"""Retrieve a pack from a git smart server.