def handle(self): refs = self.backend.get_refs().items() if refs: self.proto.write_pkt_line("%s %s\x00%s\n" % (refs[0][1], refs[0][0], self.capabilities())) for i in range(1, len(refs)): ref = refs[i] self.proto.write_pkt_line("%s %s\n" % (ref[1], ref[0])) else: self.proto.write_pkt_line("0000000000000000000000000000000000000000 capabilities^{} %s" % self.capabilities()) self.proto.write("0000") client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, client_capabilities = extract_capabilities(ref) # client will now send us a list of (oldsha, newsha, ref) while ref: client_refs.append(ref.split()) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read self.backend.apply_pack(client_refs, self.proto.read)
def determine_wants(heads): keys = heads.keys() if keys: self.proto.write_pkt_line("%s %s\x00%s\n" % ( heads[keys[0]], keys[0], self.capabilities())) for k in keys[1:]: self.proto.write_pkt_line("%s %s\n" % (heads[k], k)) # i'm done.. self.proto.write("0000") # Now client will either send "0000", meaning that it doesnt want to pull. # or it will start sending want want want commands want = self.proto.read_pkt_line() if want == None: return [] want, self.client_capabilities = extract_capabilities(want) want_revs = [] while want and want[:4] == 'want': want_revs.append(want[5:45]) want = self.proto.read_pkt_line() if want == None: self.proto.write_pkt_line("ACK %s\n" % want_revs[-1]) return want_revs
def determine_wants(heads): keys = heads.keys() if keys: self.proto.write_pkt_line( "%s %s\x00%s\n" % (heads[keys[0]], keys[0], self.capabilities())) for k in keys[1:]: self.proto.write_pkt_line("%s %s\n" % (heads[k], k)) # i'm done.. self.proto.write("0000") # Now client will either send "0000", meaning that it doesnt want to pull. # or it will start sending want want want commands want = self.proto.read_pkt_line() if want == None: return [] want, self.client_capabilities = extract_capabilities(want) want_revs = [] while want and want[:4] == 'want': want_revs.append(want[5:45]) want = self.proto.read_pkt_line() return want_revs
def handle(self): refs = self.backend.get_refs().items() if refs: self.proto.write_pkt_line( "%s %s\x00%s\n" % (refs[0][1], refs[0][0], self.capabilities())) for i in range(1, len(refs)): ref = refs[i] self.proto.write_pkt_line("%s %s\n" % (ref[1], ref[0])) else: self.proto.write_pkt_line( "0000000000000000000000000000000000000000 capabilities^{} %s" % self.capabilities()) self.proto.write("0000") client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, client_capabilities = extract_capabilities(ref) # client will now send us a list of (oldsha, newsha, ref) while ref: client_refs.append(ref.split()) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read self.backend.apply_pack(client_refs, self.proto.read)
def read_refs(self): server_capabilities = None refs = {} # Receive refs from server for pkt in self.proto.read_pkt_seq(): (sha, ref) = pkt.rstrip("\n").split(" ", 1) if server_capabilities is None: (ref, server_capabilities) = extract_capabilities(ref) refs[ref] = sha return refs, server_capabilities
def _read_refs(self, proto): server_capabilities = None refs = {} # Receive refs from server for pkt in proto.read_pkt_seq(): (sha, ref) = pkt.rstrip(b'\n').split(b' ', 1) if sha == b'ERR': raise GitProtocolError(ref) if server_capabilities is None: (ref, server_capabilities) = extract_capabilities(ref) refs[ref] = Sha1Sum(sha) return refs, server_capabilities
def _read_refs(self, proto): server_capabilities = None refs = {} # Receive refs from server for pkt in proto.read_pkt_seq(): (sha, ref) = pkt.rstrip('\n').split(' ', 1) if sha == 'ERR': raise GitProtocolError(ref) if server_capabilities is None: (ref, server_capabilities) = extract_capabilities(ref) refs[ref] = sha return refs, set(server_capabilities)
def _read_refs(self, proto): server_capabilities = None refs = {} # Receive refs from server for pkt in proto.read_pkt_seq(): (sha, ref) = pkt.rstrip("\n").split(" ", 1) if sha == "ERR": raise GitProtocolError(ref) if server_capabilities is None: (ref, server_capabilities) = extract_capabilities(ref) refs[ref] = sha return refs, set(server_capabilities)
def handle(self) -> None: if self.advertise_refs or not self.stateless_rpc: refs = sorted(self.repo.get_refs().items()) symrefs = sorted(self.repo.refs.get_symrefs().items()) if not refs: refs = [(CAPABILITIES_REF, ZERO_SHA)] self.proto.write_pkt_line( refs[0][1] + b" " + refs[0][0] + b"\0" + self.capability_line( self.capabilities() + symref_capabilities(symrefs) ) + b"\n" ) for i in range(1, len(refs)): ref = refs[i] self.proto.write_pkt_line(ref[1] + b" " + ref[0] + b"\n") self.proto.write_pkt_line(None) if self.advertise_refs: return client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, caps = extract_capabilities(ref) self.set_client_capabilities(caps) # client will now send us a list of (oldsha, newsha, ref) while ref: client_refs.append(ref.split()) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read status = self._apply_pack(client_refs) self._on_post_receive(client_refs) # when we have read all the pack from the client, send a status report # if the client asked for it if self.has_capability(CAPABILITY_REPORT_STATUS): self._report_status(status)
def read_pkt_refs(proto): server_capabilities = None refs = {} # Receive refs from server for pkt in proto.read_pkt_seq(): (sha, ref) = pkt.rstrip(b'\n').split(None, 1) if sha == b'ERR': raise GitProtocolError(ref) if server_capabilities is None: (ref, server_capabilities) = extract_capabilities(ref) refs[ref] = sha if len(refs) == 0: return None, set([]) return refs, set(server_capabilities)
def handle(self): refs = sorted(self.repo.get_refs().items()) if self.advertise_refs or not self.http_req: if refs: refs[0] = [refs[0][0], _force_bytes(refs[0][1])] self.proto.write_pkt_line( refs[0][1] + b' ' + refs[0][0] + b'\x00' + self.capability_line() + b'\n') for i in range(1, len(refs)): ref = [refs[i][0], _force_bytes(refs[i][1])] self.proto.write_pkt_line(ref[1] + b' ' + ref[0] + b'\n') else: self.proto.write_pkt_line(ZERO_SHA.hex_bytes + b' capabilities^{}\0' + self.capability_line()) self.proto.write(b"0000") if self.advertise_refs: return client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, caps = extract_capabilities(ref) self.set_client_capabilities(caps) # client will now send us a list of (oldsha, newsha, ref) while ref: tmp = ref.split() tmp[0] = Sha1Sum(tmp[0]) tmp[1] = Sha1Sum(tmp[1]) client_refs.append(tmp) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read status = self._apply_pack(client_refs) # when we have read all the pack from the client, send a status report # if the client asked for it if self.has_capability(b'report-status'): self._report_status(status)
def handle(self): refs = self.backend.get_refs().items() if self.advertise_refs or not self.stateless_rpc: if refs: self.proto.write_pkt_line("%s %s\x00%s\n" % (refs[0][1], refs[0][0], self.capabilities())) for i in range(1, len(refs)): ref = refs[i] self.proto.write_pkt_line("%s %s\n" % (ref[1], ref[0])) else: self.proto.write_pkt_line("0000000000000000000000000000000000000000 capabilities^{} %s" % self.capabilities()) self.proto.write("0000") if self.advertise_refs: return client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, client_capabilities = extract_capabilities(ref) # client will now send us a list of (oldsha, newsha, ref) while ref: client_refs.append(ref.split()) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read status = self.backend.apply_pack(client_refs, self.proto.read) # when we have read all the pack from the client, send a status report # if the client asked for it if 'report-status' in client_capabilities: for name, msg in status: if name == 'unpack': self.proto.write_pkt_line('unpack %s\n' % msg) elif msg == 'ok': self.proto.write_pkt_line('ok %s\n' % name) else: self.proto.write_pkt_line('ng %s %s\n' % (name, msg)) self.proto.write_pkt_line(None)
def read_pkt_refs(proto): server_capabilities = None refs = {} # Receive refs from server for pkt in proto.read_pkt_seq(): (sha, ref) = pkt.rstrip(b"\n").split(None, 1) if sha == b"ERR": raise GitProtocolError(ref) if server_capabilities is None: (ref, server_capabilities) = extract_capabilities(ref) symref = b"symref=HEAD:" for cap in server_capabilities: if cap.startswith(symref): sha = cap.replace(symref, b"") refs[ref] = sha if len(refs) == 0: return None, set([]) return refs, set(server_capabilities)
def handle(self): refs = sorted(self.repo.get_refs().iteritems()) if self.advertise_refs or not self.http_req: if refs: self.proto.write_pkt_line( "%s %s\x00%s\n" % (refs[0][1], refs[0][0], self.capability_line())) for i in range(1, len(refs)): ref = refs[i] self.proto.write_pkt_line("%s %s\n" % (ref[1], ref[0])) else: self.proto.write_pkt_line("%s capabilities^{}\0%s" % ( ZERO_SHA, self.capability_line())) self.proto.write("0000") if self.advertise_refs: return client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, caps = extract_capabilities(ref) self.set_client_capabilities(caps) # client will now send us a list of (oldsha, newsha, ref) while ref: client_refs.append(ref.split()) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read status = self._apply_pack(client_refs) # when we have read all the pack from the client, send a status report # if the client asked for it if self.has_capability('report-status'): self._report_status(status)
def handle(self): if self.advertise_refs or not self.http_req: refs = sorted(self.repo.get_refs().items()) if refs: self.proto.write_pkt_line( refs[0][1] + b' ' + refs[0][0] + b'\0' + self.capability_line() + b'\n') for i in range(1, len(refs)): ref = refs[i] self.proto.write_pkt_line(ref[1] + b' ' + ref[0] + b'\n') else: self.proto.write_pkt_line(ZERO_SHA + b" capabilities^{}\0" + self.capability_line()) self.proto.write_pkt_line(None) if self.advertise_refs: return client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, caps = extract_capabilities(ref) self.set_client_capabilities(caps) # client will now send us a list of (oldsha, newsha, ref) while ref: client_refs.append(ref.split()) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read status = self._apply_pack(client_refs) # when we have read all the pack from the client, send a status report # if the client asked for it if self.has_capability(CAPABILITY_REPORT_STATUS): self._report_status(status)
def handle(self): refs = sorted(self.repo.get_refs().iteritems()) if self.advertise_refs or not self.http_req: if refs: self.proto.write_pkt_line( "%s %s\x00%s\n" % (refs[0][1], refs[0][0], self.capability_line())) for i in range(1, len(refs)): ref = refs[i] self.proto.write_pkt_line("%s %s\n" % (ref[1], ref[0])) else: self.proto.write_pkt_line("%s capabilities^{}\0%s" % (ZERO_SHA, self.capability_line())) self.proto.write("0000") if self.advertise_refs: return client_refs = [] ref = self.proto.read_pkt_line() # if ref is none then client doesnt want to send us anything.. if ref is None: return ref, caps = extract_capabilities(ref) self.set_client_capabilities(caps) # client will now send us a list of (oldsha, newsha, ref) while ref: client_refs.append(ref.split()) ref = self.proto.read_pkt_line() # backend can now deal with this refs and read a pack using self.read status = self._apply_pack(client_refs) # when we have read all the pack from the client, send a status report # if the client asked for it if self.has_capability('report-status'): self._report_status(status)
def test_caps(self): self.assertEqual((b"bla", [b"la"]), extract_capabilities(b"bla\0la")) self.assertEqual((b"bla", [b"la"]), extract_capabilities(b"bla\0la\n")) self.assertEqual((b"bla", [b"la", b"la"]), extract_capabilities(b"bla\0la la"))
def test_caps(self): self.assertEquals(('bla', ['la']), extract_capabilities('bla\0la')) self.assertEquals(('bla', ['la']), extract_capabilities('bla\0la\n')) self.assertEquals(('bla', ['la', 'la']), extract_capabilities('bla\0la la'))
def test_caps(self): self.assertEqual((b'bla', [b'la']), extract_capabilities(b'bla\0la')) self.assertEqual((b'bla', [b'la']), extract_capabilities(b'bla\0la\n')) self.assertEqual((b'bla', [b'la', b'la']), extract_capabilities(b'bla\0la la'))
def test_plain(self): self.assertEquals(('bla', []), extract_capabilities('bla'))
def test_plain(self): self.assertEqual((b'bla', []), extract_capabilities(b'bla'))
def test_caps(self): self.assertEquals(("bla", ["la"]), extract_capabilities("bla\0la")) self.assertEquals(("bla", ["la"]), extract_capabilities("bla\0la\n")) self.assertEquals(("bla", ["la", "la"]), extract_capabilities("bla\0la la"))
def test_plain(self): self.assertEquals(("bla", []), extract_capabilities("bla"))
def test_plain(self): self.assertEqual((b"bla", []), extract_capabilities(b"bla"))