|
@@ -0,0 +1,65 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class Protocol(object):
|
|
|
+
|
|
|
+ def __init__(self, read, write):
|
|
|
+ self.read = read
|
|
|
+ self.write = write
|
|
|
+
|
|
|
+ def read_pkt_line(self):
|
|
|
+ """
|
|
|
+ Reads a 'pkt line' from the remote git process
|
|
|
+
|
|
|
+ :return: The next string from the stream
|
|
|
+ """
|
|
|
+ sizestr = self.read(4)
|
|
|
+ if not sizestr:
|
|
|
+ return None
|
|
|
+ size = int(sizestr, 16)
|
|
|
+ if size == 0:
|
|
|
+ return None
|
|
|
+ return self.read(size-4)
|
|
|
+
|
|
|
+ def write_pkt_line(self, line):
|
|
|
+ """
|
|
|
+ Sends a 'pkt line' to the remote git process
|
|
|
+
|
|
|
+ :param line: A string containing the data to send
|
|
|
+ """
|
|
|
+ if line is None:
|
|
|
+ self.write("0000")
|
|
|
+ else:
|
|
|
+ self.write("%04x%s" % (len(line)+4, line))
|
|
|
+
|
|
|
+ def write_sideband(self, channel, blob):
|
|
|
+ """
|
|
|
+ Write data to the sideband (a git multiplexing method)
|
|
|
+
|
|
|
+ :param channel: int specifying which channel to write to
|
|
|
+ :param blob: a blob of data (as a string) to send on this channel
|
|
|
+ """
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ while blob:
|
|
|
+ self.write_pkt_line("%s%s" % (chr(channel), blob[:65530]))
|
|
|
+ blob = blob[65530:]
|
|
|
+
|
|
|
+
|