diff mercurial/bundlerepo.py @ 29728:55d341877316

bundlerepo: add support for treemanifests in cg3 bundles This is a little messier than I'd like, and I'll probably come back and do some more refactoring later, but as it is this unblocks narrowhg. An alternative approach (which I may do as part of the mentioned refactoring) would be to construct *all* dirlog instances up front, so that we don't have to keep track of the linkmapper method. This would avoid a reference cycle between the bundlemanifest and the bundlerepository, but I was hesitant to do all the work up front like that. With this change, it's possible to do 'hg incoming' and 'hg pull' from bundles in .hg/strip-backup in a treemanifest repository. Sadly, this doesn't make it possible to 'hg clone' one of those (if you do 'hg strip 0'), because the cg3 in the bundle gets written without a treemanifest flag. Since that's going to be an involved refactor in a different part of the code (which I *suspect* won't touch any of the code I've just written here), let's leave it as an idea for Later.
author Augie Fackler <augie@google.com>
date Fri, 05 Aug 2016 13:08:11 -0400
parents 43924f3a55fa
children 27c0792e834c
line wrap: on
line diff
--- a/mercurial/bundlerepo.py	Fri Aug 05 11:19:22 2016 -0400
+++ b/mercurial/bundlerepo.py	Fri Aug 05 13:08:11 2016 -0400
@@ -188,10 +188,16 @@
             self.filteredrevs = oldfilter
 
 class bundlemanifest(bundlerevlog, manifest.manifest):
-    def __init__(self, opener, bundle, linkmapper):
-        manifest.manifest.__init__(self, opener)
+    def __init__(self, opener, bundle, linkmapper, dirlogstarts=None, dir=''):
+        manifest.manifest.__init__(self, opener, dir=dir)
         bundlerevlog.__init__(self, opener, self.indexfile, bundle,
                               linkmapper)
+        if dirlogstarts is None:
+            dirlogstarts = {}
+            if self.bundle.version == "03":
+                dirlogstarts = _getfilestarts(self.bundle)
+        self._dirlogstarts = dirlogstarts
+        self._linkmapper = linkmapper
 
     def baserevision(self, nodeorrev):
         node = nodeorrev
@@ -204,6 +210,14 @@
             result = manifest.manifest.revision(self, nodeorrev)
         return result
 
+    def dirlog(self, d):
+        if d in self._dirlogstarts:
+            self.bundle.seek(self._dirlogstarts[d])
+            return bundlemanifest(
+                self.opener, self.bundle, self._linkmapper,
+                self._dirlogstarts, dir=d)
+        return super(bundlemanifest, self).dirlog(d)
+
 class bundlefilelog(bundlerevlog, filelog.filelog):
     def __init__(self, opener, path, bundle, linkmapper):
         filelog.filelog.__init__(self, opener, path)
@@ -336,10 +350,6 @@
         self.bundle.manifestheader()
         linkmapper = self.unfiltered().changelog.rev
         m = bundlemanifest(self.svfs, self.bundle, linkmapper)
-        # XXX: hack to work with changegroup3, but we still don't handle
-        # tree manifests correctly
-        if self.bundle.version == "03":
-            self.bundle.filelogheader()
         self.filestart = self.bundle.tell()
         return m