Mercurial > public > mercurial-scm > hg
comparison mercurial/bundlerepo.py @ 24073:ff5caa8dfd99
bundlerepo: basic bundle2 support
For bundlerepo to work with bundle2 files, we need to find the part that
contains the bundle's changegroup data and work with that instead of the
entire bundle. Future work can add separate processing for other bundle2
parts.
author | Eric Sumner <ericsumner@fb.com> |
---|---|
date | Fri, 06 Feb 2015 11:27:25 -0800 |
parents | 145b823f5ce7 |
children | 6ddc86eedc3b |
comparison
equal
deleted
inserted
replaced
24072:145b823f5ce7 | 24073:ff5caa8dfd99 |
---|---|
13 | 13 |
14 from node import nullid | 14 from node import nullid |
15 from i18n import _ | 15 from i18n import _ |
16 import os, tempfile, shutil | 16 import os, tempfile, shutil |
17 import changegroup, util, mdiff, discovery, cmdutil, scmutil, exchange | 17 import changegroup, util, mdiff, discovery, cmdutil, scmutil, exchange |
18 import localrepo, changelog, manifest, filelog, revlog, error, phases | 18 import localrepo, changelog, manifest, filelog, revlog, error, phases, bundle2 |
19 | 19 |
20 class bundlerevlog(revlog.revlog): | 20 class bundlerevlog(revlog.revlog): |
21 def __init__(self, opener, indexfile, bundle, linkmapper): | 21 def __init__(self, opener, indexfile, bundle, linkmapper): |
22 # How it works: | 22 # How it works: |
23 # To retrieve a revision, we need to know the offset of the revision in | 23 # To retrieve a revision, we need to know the offset of the revision in |
236 f = self.vfs.open(self.tempfile, mode="rb") | 236 f = self.vfs.open(self.tempfile, mode="rb") |
237 self.bundlefile = self.bundle = exchange.readbundle(ui, f, | 237 self.bundlefile = self.bundle = exchange.readbundle(ui, f, |
238 bundlename, | 238 bundlename, |
239 self.vfs) | 239 self.vfs) |
240 | 240 |
241 if isinstance(self.bundle, bundle2.unbundle20): | |
242 cgparts = [part for part in self.bundle.iterparts() | |
243 if (part.type == 'b2x:changegroup') | |
244 and (part.params.get('version', '01') | |
245 in changegroup.packermap)] | |
246 | |
247 if not cgparts: | |
248 raise util.Abort('No changegroups found') | |
249 version = cgparts[0].params.get('version', '01') | |
250 cgparts = [p for p in cgparts | |
251 if p.params.get('version', '01') == version] | |
252 if len(cgparts) > 1: | |
253 raise NotImplementedError("Can't process multiple changegroups") | |
254 part = cgparts[0] | |
255 | |
256 part.seek(0) | |
257 self.bundle = changegroup.packermap[version][1](part, 'UN') | |
258 | |
241 # dict with the mapping 'filename' -> position in the bundle | 259 # dict with the mapping 'filename' -> position in the bundle |
242 self.bundlefilespos = {} | 260 self.bundlefilespos = {} |
243 | 261 |
244 self.firstnewrev = self.changelog.repotiprev + 1 | 262 self.firstnewrev = self.changelog.repotiprev + 1 |
245 phases.retractboundary(self, None, phases.draft, | 263 phases.retractboundary(self, None, phases.draft, |