diff --git a/remotefilelog/__init__.py b/remotefilelog/__init__.py --- a/remotefilelog/__init__.py +++ b/remotefilelog/__init__.py @@ -292,7 +292,12 @@ elif util.safehasattr(changegroup, '_packermap'): packermap = changegroup._packermap - if packermap: + # Partway through the hg 4.8 cycle all packers were consolidated + # down to just cgpacker and they were constructed using factory + # functions, so we don't need to override the packermap anymore. + if util.safehasattr(changegroup, 'cgpacker'): + changegroup.cgpacker = shallowbundle.shallowcg1packer + elif packermap: # Mercurial >= 3.3 packermap01 = packermap['01'] packermap02 = packermap['02'] diff --git a/remotefilelog/remotefilelog.py b/remotefilelog/remotefilelog.py --- a/remotefilelog/remotefilelog.py +++ b/remotefilelog/remotefilelog.py @@ -38,6 +38,9 @@ return node class remotefilelog(object): + + _generaldelta = True + def __init__(self, opener, path, repo): self.opener = opener self.filename = path @@ -221,11 +224,48 @@ return p1, p2 + def parentrevs(self, rev): + # TODO(augie): this is a node and should be a rev, but for now + # nothing in core seems to actually break. + return self.parents(rev) + def linknode(self, node): ancestormap = self.repo.metadatastore.getancestors(self.filename, node) p1, p2, linknode, copyfrom = ancestormap[node] return linknode + def linkrev(self, node): + self.repo.changelog.rev(self.linknode(node)) + + def emitrevisiondeltas(self, requests): + prevnode = None + for request in requests: + node = request.node + p1, p2 = self.parents(node) + if prevnode is None: + prevnode = p1 + if request.basenode is not None: + basenode = request.basenode + else: + basenode = p1 + if basenode == nullid: + revision = self.revision(node, raw=True) + delta = None + else: + revision = None + delta = self.revdiff(basenode, node) + yield revlog.revlogrevisiondelta( + node=node, + p1node=p1, + p2node=p2, + linknode=self.linknode(node), + basenode=basenode, + flags=self.flags(node), + baserevisionsize=None, + revision=revision, + delta=delta, + ) + def revdiff(self, node1, node2): return mdiff.textdiff(self.revision(node1, raw=True), self.revision(node2, raw=True)) diff --git a/remotefilelog/shallowbundle.py b/remotefilelog/shallowbundle.py --- a/remotefilelog/shallowbundle.py +++ b/remotefilelog/shallowbundle.py @@ -46,11 +46,17 @@ def _cansendflat(repo, mfnodes): if not util.safehasattr(repo.manifestlog, '_revlog'): - return False + if getattr(repo.manifestlog, '_treeondisk', False): + return False if repo.ui.configbool('treemanifest', 'treeonly'): return False + return True + # TODO(augie): I suspect this code is sniffing for the case where + # we're storing treemanifests but exchanging flat manfiests, or + # something like that. I'm leaving it in because I'm not sure if + # it's addressed with the above code. revlog = repo.manifestlog._revlog for mfnode in mfnodes: if mfnode not in revlog.nodemap: @@ -65,7 +71,6 @@ # Since 4c99c6d1ef95 cgpacker = changegroup.cgpacker -@shallowutil.interposeclass(changegroup, cgpacker.__name__) class shallowcg1packer(cgpacker): def generate(self, commonrevs, clnodes, fastpathlinkrev, source): if "remotefilelog" in self._repo.requirements: @@ -121,10 +126,14 @@ fclnode = fclnodes.setdefault(bnode, clnode) if clrevorder[clnode] < clrevorder[fclnode]: fclnodes[bnode] = clnode + if util.safehasattr(self, 'close'): + yield self.close() - yield self.close() - - def generatefiles(self, changedfiles, linknodes, commonrevs, source): + def generatefiles(self, changedfiles, *args): + try: + linknodes, commonrevs, source = args + except ValueError: + commonrevs, source, mfdicts, fastpathlinkrev, fnodes, clrevs = args if requirement in self._repo.requirements: repo = self._repo if isinstance(repo, bundlerepo.bundlerepository): @@ -141,7 +150,16 @@ if filestosend == NoFiles: changedfiles = list([f for f in changedfiles if not repo.shallowmatch(f)]) + with open('/tmp/wat', 'a') as f: + f.write('nofiles to send: %r\n' % changedfiles) else: + def linknodes(store, fname): + # TODO(augie): this logic is almost certainly + # incorrect in some subtle way. See the + # similarly-named closure in + # mercurial.changegroup.cgpacker.generatefiles. + return {} + files = [] # Prefetch the revisions being bundled for i, fname in enumerate(sorted(changedfiles)): @@ -179,8 +197,8 @@ repo.fileservice.prefetch(prevfiles) - return super(shallowcg1packer, self).generatefiles(changedfiles, - linknodes, commonrevs, source) + return super(shallowcg1packer, self).generatefiles( + changedfiles, *args) def shouldaddfilegroups(self, source): repo = self._repo @@ -231,6 +249,9 @@ yield meta yield delta +if util.safehasattr(changegroup, 'cg1packer'): + shallowutil.interposeclass(changegroup, cgpacker.__name__)(shallowcg1packer) + if util.safehasattr(changegroup, 'cg2packer'): # Mercurial >= 3.3 cg2packer = changegroup.cg2packer diff --git a/tests/test-remotefilelog-bundles.t b/tests/test-remotefilelog-bundles.t --- a/tests/test-remotefilelog-bundles.t +++ b/tests/test-remotefilelog-bundles.t @@ -47,7 +47,7 @@ adding manifests adding file changes added 2 changesets with 2 changes to 1 files - new changesets 66ee28d0328c:16db62c5946f + new changesets 66ee28d0328c:16db62c5946f (2 drafts) (run 'hg update' to get a working copy) Pulling from a shallow bundle @@ -61,7 +61,7 @@ adding manifests adding file changes added 1 changesets with 0 changes to 0 files - new changesets 66ee28d0328c + new changesets 66ee28d0328c (1 drafts) (run 'hg update' to get a working copy) Pulling from a full bundle diff --git a/tests/test-remotefilelog-local.t b/tests/test-remotefilelog-local.t --- a/tests/test-remotefilelog-local.t +++ b/tests/test-remotefilelog-local.t @@ -134,7 +134,7 @@ adding manifests adding file changes added 1 changesets with 0 changes to 0 files - new changesets 19edf50f4de7 + new changesets 19edf50f4de7 (1 drafts) (run 'hg update' to get a working copy) $ hg up @@ -166,7 +166,7 @@ adding manifests adding file changes added 1 changesets with 3 changes to 3 files - new changesets 19edf50f4de7 + new changesets 19edf50f4de7 (1 drafts) (run 'hg update' to get a working copy) $ hg log -r 2 --stat diff --git a/tests/test-remotefilelog-prefetch.t b/tests/test-remotefilelog-prefetch.t --- a/tests/test-remotefilelog-prefetch.t +++ b/tests/test-remotefilelog-prefetch.t @@ -256,12 +256,12 @@ $ hg mv x x2 $ hg mv z2 z3 $ hg revert -a -r 1 || true + forgetting x2 + forgetting y2 + forgetting z3 + adding z undeleting x - forgetting x2 undeleting y - forgetting y2 - adding z - forgetting z3 3 files fetched over 1 fetches - (0 misses, 100.00% hit ratio) over * (glob) abort: z2@109c3a557a73: not found in manifest! (?) diff --git a/tests/test-remotefilelog-push-pull.t b/tests/test-remotefilelog-push-pull.t --- a/tests/test-remotefilelog-push-pull.t +++ b/tests/test-remotefilelog-push-pull.t @@ -72,10 +72,10 @@ adding changesets adding manifests adding file changes - added 3 changesets with 3 changes to 3 files - new changesets d34c38483be9:d7373980d475 + added 3 changesets with 4 changes to 3 files + new changesets d34c38483be9:d7373980d475 (2 drafts) (run 'hg update' to get a working copy) - 2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) + 2 files fetched over 2 fetches - (2 misses, 0.00% hit ratio) over *s (glob) # pull from shallow to shallow (ssh) @@ -87,10 +87,10 @@ adding changesets adding manifests adding file changes - added 3 changesets with 3 changes to 3 files - new changesets d34c38483be9:d7373980d475 + added 3 changesets with 4 changes to 3 files + new changesets d34c38483be9:d7373980d475 (2 drafts) (run 'hg update' to get a working copy) - 2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) + 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) $ hg up 3 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -173,7 +173,7 @@ adding manifests adding file changes added 2 changesets with 2 changes to 2 files - new changesets 3a2e32c04641:cedeb4167c1f + new changesets 3a2e32c04641:cedeb4167c1f (1 drafts) 2 local changesets published (?) (run 'hg update' to get a working copy) @@ -222,7 +222,7 @@ adding manifests adding file changes added 5 changesets with 4 changes to 3 files (+2 heads) - new changesets cb9a9f314b8b:d8f06a4c6d38 + new changesets cb9a9f314b8b:d8f06a4c6d38 (5 drafts) (run 'hg heads' to see heads, 'hg merge' to merge) $ hg up -q 5