##// END OF EJS Templates
bundle: get rid of chunkiter
Matt Mackall -
r12335:e21fe9c5 default
parent child Browse files
Show More
@@ -117,7 +117,7 b' def writerevs(ui, r1, r2, order, tr):'
117
117
118 try:
118 try:
119 group = util.chunkbuffer(r1.group(order, lookup, progress))
119 group = util.chunkbuffer(r1.group(order, lookup, progress))
120 r2.addgroup(group.chunks(), unlookup, tr)
120 r2.addgroup(group, unlookup, tr)
121 finally:
121 finally:
122 ui.progress(_('writing'), None)
122 ui.progress(_('writing'), None)
123
123
@@ -33,7 +33,10 b' class bundlerevlog(revlog.revlog):'
33 self.bundle = bundle
33 self.bundle = bundle
34 self.basemap = {}
34 self.basemap = {}
35 def chunkpositer():
35 def chunkpositer():
36 for chunk in bundle.chunks():
36 while 1:
37 chunk = bundle.chunk()
38 if not chunk:
39 break
37 pos = bundle.tell()
40 pos = bundle.tell()
38 yield chunk, pos - len(chunk)
41 yield chunk, pos - len(chunk)
39 n = len(self)
42 n = len(self)
@@ -230,8 +233,10 b' class bundlerepository(localrepo.localre'
230 if not chunk:
233 if not chunk:
231 break
234 break
232 self.bundlefilespos[chunk] = self.bundle.tell()
235 self.bundlefilespos[chunk] = self.bundle.tell()
233 for c in self.bundle.chunks():
236 while 1:
234 pass
237 c = self.bundle.chunk()
238 if not c:
239 break
235
240
236 if f[0] == '/':
241 if f[0] == '/':
237 f = f[1:]
242 f = f[1:]
@@ -24,17 +24,6 b' def getchunk(source):'
24 % (len(d), l - 4))
24 % (len(d), l - 4))
25 return d
25 return d
26
26
27 def chunkiter(source, progress=None):
28 """iterate through the chunks in source, yielding a sequence of chunks
29 (strings)"""
30 while 1:
31 c = getchunk(source)
32 if not c:
33 break
34 elif progress is not None:
35 progress()
36 yield c
37
38 def chunkheader(length):
27 def chunkheader(length):
39 """return a changegroup chunk header (string)"""
28 """return a changegroup chunk header (string)"""
40 return struct.pack(">l", length + 4)
29 return struct.pack(">l", length + 4)
@@ -94,15 +83,18 b' def writebundle(cg, filename, bundletype'
94 # parse the changegroup data, otherwise we will block
83 # parse the changegroup data, otherwise we will block
95 # in case of sshrepo because we don't know the end of the stream
84 # in case of sshrepo because we don't know the end of the stream
96
85
97 # an empty chunkiter is the end of the changegroup
86 # an empty chunkgroup is the end of the changegroup
98 # a changegroup has at least 2 chunkiters (changelog and manifest).
87 # a changegroup has at least 2 chunkgroups (changelog and manifest).
99 # after that, an empty chunkiter is the end of the changegroup
88 # after that, an empty chunkgroup is the end of the changegroup
100 empty = False
89 empty = False
101 count = 0
90 count = 0
102 while not empty or count <= 2:
91 while not empty or count <= 2:
103 empty = True
92 empty = True
104 count += 1
93 count += 1
105 for chunk in chunkiter(cg):
94 while 1:
95 chunk = getchunk(cg)
96 if not chunk:
97 break
106 empty = False
98 empty = False
107 fh.write(z.compress(chunkheader(len(chunk))))
99 fh.write(z.compress(chunkheader(len(chunk))))
108 pos = 0
100 pos = 0
@@ -171,13 +163,6 b' class unbundle10(object):'
171 % (len(d), l))
163 % (len(d), l))
172 return d
164 return d
173
165
174 def chunks(self):
175 while 1:
176 c = self.chunk()
177 if not c:
178 break
179 yield c
180
181 class headerlessfixup(object):
166 class headerlessfixup(object):
182 def __init__(self, fh, h):
167 def __init__(self, fh, h):
183 self._h = h
168 self._h = h
@@ -1676,7 +1676,7 b' class localrepository(repo.repository):'
1676 pr = prog()
1676 pr = prog()
1677 source.callback = pr
1677 source.callback = pr
1678
1678
1679 if (cl.addgroup(source.chunks(), csmap, trp) is None
1679 if (cl.addgroup(source, csmap, trp) is None
1680 and not emptyok):
1680 and not emptyok):
1681 raise util.Abort(_("received changelog group is empty"))
1681 raise util.Abort(_("received changelog group is empty"))
1682 clend = len(cl)
1682 clend = len(cl)
@@ -1695,7 +1695,7 b' class localrepository(repo.repository):'
1695 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1695 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1696 # no new manifest will be created and the manifest group will
1696 # no new manifest will be created and the manifest group will
1697 # be empty during the pull
1697 # be empty during the pull
1698 self.manifest.addgroup(source.chunks(), revmap, trp)
1698 self.manifest.addgroup(source, revmap, trp)
1699 self.ui.progress(_('manifests'), None)
1699 self.ui.progress(_('manifests'), None)
1700
1700
1701 needfiles = {}
1701 needfiles = {}
@@ -1723,7 +1723,7 b' class localrepository(repo.repository):'
1723 pr()
1723 pr()
1724 fl = self.file(f)
1724 fl = self.file(f)
1725 o = len(fl)
1725 o = len(fl)
1726 if fl.addgroup(source.chunks(), revmap, trp) is None:
1726 if fl.addgroup(source, revmap, trp) is None:
1727 raise util.Abort(_("received file revlog group is empty"))
1727 raise util.Abort(_("received file revlog group is empty"))
1728 revisions += len(fl) - o
1728 revisions += len(fl) - o
1729 files += 1
1729 files += 1
@@ -1269,7 +1269,7 b' class revlog(object):'
1269
1269
1270 yield changegroup.closechunk()
1270 yield changegroup.closechunk()
1271
1271
1272 def addgroup(self, revs, linkmapper, transaction):
1272 def addgroup(self, bundle, linkmapper, transaction):
1273 """
1273 """
1274 add a delta group
1274 add a delta group
1275
1275
@@ -1301,7 +1301,10 b' class revlog(object):'
1301 try:
1301 try:
1302 # loop through our set of deltas
1302 # loop through our set of deltas
1303 chain = None
1303 chain = None
1304 for chunk in revs:
1304 while 1:
1305 chunk = bundle.chunk()
1306 if not chunk:
1307 break
1305 node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80])
1308 node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80])
1306 link = linkmapper(cs)
1309 link = linkmapper(cs)
1307 if (node in self.nodemap and
1310 if (node in self.nodemap and
General Comments 0
You need to be logged in to leave comments. Login now