def add_objects(self, objects): """Add a set of objects to this object store. :param objects: Iterable over objects, should support __len__. :return: Pack object of the objects written. """ if len(objects) == 0: # Don't bother writing an empty pack file return f, commit = self.add_pack() write_pack_data(f, objects, len(objects)) return commit()
def handle(self): write = lambda x: self.proto.write_sideband(1, x) 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) # Did the process short-circuit (e.g. in a stateless RPC call)? Note # that the client still expects a 0-object pack in most cases. if objects_iter is None: return self.progress("dul-daemon says what\n") self.progress("counting objects: %d, done.\n" % len(objects_iter)) write_pack_data(ProtocolFile(None, write), objects_iter, len(objects_iter)) self.progress("how was that, then?\n") # we are done self.proto.write("0000")
def handle(self): write = lambda x: self.proto.write_sideband(1, x) 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) # Did the process short-circuit (e.g. in a stateless RPC call)? Note # that the client still expects a 0-object pack in most cases. if objects_iter is None: return self.progress("dul-daemon says what\n") self.progress("counting objects: %d, done.\n" % len(objects_iter)) write_pack_data(ProtocolFile(None, write), objects_iter, len(objects_iter)) self.progress("how was that, then?\n") # we are done self.proto.write("0000")
def send_pack(self, path, determine_wants, generate_pack_contents): """Upload a pack to a remote repository. :param path: Repository path :param generate_pack_contents: Function that can return the shas of the objects to upload. :raises SendPackError: if server rejects the pack data :raises UpdateRefsError: if the server supports report-status and rejects ref updates """ proto, unused_can_read = self._connect('receive-pack', path) old_refs, server_capabilities = self.read_refs(proto) if 'report-status' not in server_capabilities: self._send_capabilities.remove('report-status') new_refs = determine_wants(old_refs) if not new_refs: proto.write_pkt_line(None) return {} want = [] have = [x for x in old_refs.values() if not x == ZERO_SHA] sent_capabilities = False for refname in set(new_refs.keys() + old_refs.keys()): old_sha1 = old_refs.get(refname, ZERO_SHA) new_sha1 = new_refs.get(refname, ZERO_SHA) if old_sha1 != new_sha1: if sent_capabilities: proto.write_pkt_line("%s %s %s" % (old_sha1, new_sha1, refname)) else: proto.write_pkt_line( "%s %s %s\0%s" % (old_sha1, new_sha1, refname, ' '.join(self._send_capabilities))) sent_capabilities = True if new_sha1 not in have and new_sha1 != ZERO_SHA: want.append(new_sha1) proto.write_pkt_line(None) if not want: return new_refs objects = generate_pack_contents(have, want) entries, sha = write_pack_data(proto.write_file(), objects, len(objects)) if 'report-status' in self._send_capabilities: self._parse_status_report(proto) # wait for EOF before returning data = proto.read() if data: raise SendPackError('Unexpected response %r' % data) return new_refs
def send_pack(self, path, determine_wants, generate_pack_contents): """Upload a pack to a remote repository. :param path: Repository path :param generate_pack_contents: Function that can return the shas of the objects to upload. :raises SendPackError: if server rejects the pack data :raises UpdateRefsError: if the server supports report-status and rejects ref updates """ proto, unused_can_read = self._connect('receive-pack', path) old_refs, server_capabilities = self.read_refs(proto) if 'report-status' not in server_capabilities: self._send_capabilities.remove('report-status') new_refs = determine_wants(old_refs) if not new_refs: proto.write_pkt_line(None) return {} want = [] have = [x for x in old_refs.values() if not x == ZERO_SHA] sent_capabilities = False for refname in set(new_refs.keys() + old_refs.keys()): old_sha1 = old_refs.get(refname, ZERO_SHA) new_sha1 = new_refs.get(refname, ZERO_SHA) if old_sha1 != new_sha1: if sent_capabilities: proto.write_pkt_line("%s %s %s" % (old_sha1, new_sha1, refname)) else: proto.write_pkt_line("%s %s %s\0%s" % (old_sha1, new_sha1, refname, ' '.join(self._send_capabilities))) sent_capabilities = True if new_sha1 not in have and new_sha1 != ZERO_SHA: want.append(new_sha1) proto.write_pkt_line(None) if not want: return new_refs objects = generate_pack_contents(have, want) entries, sha = write_pack_data(proto.write_file(), objects, len(objects)) if 'report-status' in self._send_capabilities: self._parse_status_report(proto) # wait for EOF before returning data = proto.read() if data: raise SendPackError('Unexpected response %r' % data) return new_refs