Mercurial > hg
comparison mercurial/changegroup.py @ 9437:1c4e4004f3a6
Improve some docstrings relating to changegroups and prepush().
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Tue, 08 Sep 2009 17:58:59 -0400 |
parents | f48454a279b9 |
children | 25e572394f5c |
comparison
equal
deleted
inserted
replaced
9436:96379c93ba6f | 9437:1c4e4004f3a6 |
---|---|
8 from i18n import _ | 8 from i18n import _ |
9 import util | 9 import util |
10 import struct, os, bz2, zlib, tempfile | 10 import struct, os, bz2, zlib, tempfile |
11 | 11 |
12 def getchunk(source): | 12 def getchunk(source): |
13 """get a chunk from a changegroup""" | 13 """return the next chunk from changegroup 'source' as a string""" |
14 d = source.read(4) | 14 d = source.read(4) |
15 if not d: | 15 if not d: |
16 return "" | 16 return "" |
17 l = struct.unpack(">l", d)[0] | 17 l = struct.unpack(">l", d)[0] |
18 if l <= 4: | 18 if l <= 4: |
23 " (got %d bytes, expected %d)") | 23 " (got %d bytes, expected %d)") |
24 % (len(d), l - 4)) | 24 % (len(d), l - 4)) |
25 return d | 25 return d |
26 | 26 |
27 def chunkiter(source): | 27 def chunkiter(source): |
28 """iterate through the chunks in source""" | 28 """iterate through the chunks in source, yielding a sequence of chunks |
29 (strings)""" | |
29 while 1: | 30 while 1: |
30 c = getchunk(source) | 31 c = getchunk(source) |
31 if not c: | 32 if not c: |
32 break | 33 break |
33 yield c | 34 yield c |
34 | 35 |
35 def chunkheader(length): | 36 def chunkheader(length): |
36 """build a changegroup chunk header""" | 37 """return a changegroup chunk header (string)""" |
37 return struct.pack(">l", length + 4) | 38 return struct.pack(">l", length + 4) |
38 | 39 |
39 def closechunk(): | 40 def closechunk(): |
41 """return a changegroup chunk header (string) for a zero-length chunk""" | |
40 return struct.pack(">l", 0) | 42 return struct.pack(">l", 0) |
41 | 43 |
42 class nocompress(object): | 44 class nocompress(object): |
43 def compress(self, x): | 45 def compress(self, x): |
44 return x | 46 return x |