Benoit Boissinot avatar Benoit Boissinot committed 515d414

unbundler: separate delta and header parsing

Add header parsing for changelog and manifest (currently no headers might
change for next-gen bundle).

Comments (0)

Files changed (5)

mercurial/bundlerepo.py

         n = len(self)
         chain = None
         while 1:
-            chunkdata = bundle.parsechunk(chain)
+            chunkdata = bundle.deltachunk(chain)
             if not chunkdata:
                 break
             node = chunkdata['node']
 
     @util.propertycache
     def changelog(self):
+        # consume the header if it exists
+        self.bundle.changelogheader()
         c = bundlechangelog(self.sopener, self.bundle)
         self.manstart = self.bundle.tell()
         return c
     @util.propertycache
     def manifest(self):
         self.bundle.seek(self.manstart)
+        # consume the header if it exists
+        self.bundle.manifestheader()
         m = bundlemanifest(self.sopener, self.bundle, self.changelog.rev)
         self.filestart = self.bundle.tell()
         return m
         if not self.bundlefilespos:
             self.bundle.seek(self.filestart)
             while 1:
-                chunk = self.bundle.chunk()
-                if not chunk:
+                chunkdata = self.bundle.filelogheader()
+                if not chunkdata:
                     break
-                self.bundlefilespos[chunk] = self.bundle.tell()
+                fname = chunkdata['filename']
+                self.bundlefilespos[fname] = self.bundle.tell()
                 while 1:
-                    c = self.bundle.chunk()
+                    c = self.bundle.deltachunk(None)
                     if not c:
                         break
 

mercurial/changegroup.py

             self.callback()
         return l - 4
 
-    def chunk(self):
-        """return the next chunk from changegroup 'source' as a string"""
+    def changelogheader(self):
+        """v10 does not have a changelog header chunk"""
+        return {}
+
+    def manifestheader(self):
+        """v10 does not have a manifest header chunk"""
+        return {}
+
+    def filelogheader(self):
+        """return the header of the filelogs chunk, v10 only has the filename"""
         l = self.chunklength()
-        return readexactly(self._stream, l)
+        if not l:
+            return {}
+        fname = readexactly(self._stream, l)
+        return dict(filename=fname)
 
-    def parsedeltaheader(self, node, p1, p2, cs):
+    def _deltaheader(self, node, p1, p2, cs):
         return node, p1, p2, _TIPDELTA, cs
 
-    def parsechunk(self, prevnode):
+    def deltachunk(self, prevnode):
         l = self.chunklength()
         if not l:
             return {}
         headerdata = readexactly(self._stream, self.deltaheadersize)
         header = struct.unpack(self.deltaheader, headerdata)
         delta = readexactly(self._stream, l - self.deltaheadersize)
-        node, p1, p2, deltatype, cs = self.parsedeltaheader(*header)
+        node, p1, p2, deltatype, cs = self._deltaheader(*header)
         if deltatype == _P1DELTA or prevnode is None:
             deltabase = p1
         elif deltatype == _TIPDELTA:

mercurial/commands.py

                 ui.write("\n%s\n" % named)
                 chain = None
                 while 1:
-                    chunkdata = gen.parsechunk(chain)
+                    chunkdata = gen.deltachunk(chain)
                     if not chunkdata:
                         break
                     node = chunkdata['node']
                               hex(cs), hex(deltabase), len(delta)))
                     chain = node
 
+            chunkdata = gen.changelogheader()
             showchunks("changelog")
+            chunkdata = gen.manifestheader()
             showchunks("manifest")
             while 1:
-                fname = gen.chunk()
+                chunkdata = gen.filelogheader()
+                fname = chunkdata['filename']
                 if not fname:
                     break
                 showchunks(fname)
         else:
-            chain = None
+            chunkdata = gen.changelogheader()
             while 1:
-                chunkdata = gen.parsechunk(chain)
+                chunkdata = gen.deltachunk(chain)
                 if not chunkdata:
                     break
                 node = chunkdata['node']

mercurial/localrepo.py

             pr = prog()
             source.callback = pr
 
+            source.changelogheader()
             if (cl.addgroup(source, csmap, trp) is None
                 and not emptyok):
                 raise util.Abort(_("received changelog group is empty"))
             # if the result of the merge of 1 and 2 is the same in 3 and 4,
             # no new manifest will be created and the manifest group will
             # be empty during the pull
+            source.manifestheader()
             self.manifest.addgroup(source, revmap, trp)
             self.ui.progress(_('manifests'), None)
 
             source.callback = None
 
             while 1:
-                f = source.chunk()
-                if not f:
+                chunkdata = source.filelogheader()
+                if not chunkdata:
                     break
+                f = chunkdata["filename"]
                 self.ui.debug("adding %s revisions\n" % f)
                 pr()
                 fl = self.file(f)

mercurial/revlog.py

             # loop through our set of deltas
             chain = None
             while 1:
-                chunkdata = bundle.parsechunk(chain)
+                chunkdata = bundle.deltachunk(chain)
                 if not chunkdata:
                     break
                 node = chunkdata['node']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.