##// END OF EJS Templates
bundle2: move `readbundle` into the `exchange` module...
Pierre-Yves David -
r21063:7ca4f204 default
parent child Browse files
Show More
@@ -25,7 +25,7 b' from mercurial.i18n import _'
25 from mercurial.node import nullid, nullrev, bin, hex
25 from mercurial.node import nullid, nullrev, bin, hex
26 from mercurial import changegroup, cmdutil, scmutil, phases, commands
26 from mercurial import changegroup, cmdutil, scmutil, phases, commands
27 from mercurial import error, hg, mdiff, merge, patch, repair, util
27 from mercurial import error, hg, mdiff, merge, patch, repair, util
28 from mercurial import templatefilters, changegroup
28 from mercurial import templatefilters, changegroup, exchange
29 from mercurial import lock as lockmod
29 from mercurial import lock as lockmod
30 from hgext import rebase
30 from hgext import rebase
31 import errno
31 import errno
@@ -71,7 +71,7 b' class shelvedfile(object):'
71 def applybundle(self):
71 def applybundle(self):
72 fp = self.opener()
72 fp = self.opener()
73 try:
73 try:
74 gen = changegroup.readbundle(fp, self.fname, self.vfs)
74 gen = exchange.readbundle(fp, self.fname, self.vfs)
75 changegroup.addchangegroup(self.repo, gen, 'unshelve',
75 changegroup.addchangegroup(self.repo, gen, 'unshelve',
76 'bundle:' + self.vfs.join(self.fname))
76 'bundle:' + self.vfs.join(self.fname))
77 finally:
77 finally:
@@ -14,7 +14,7 b' were part of the actual repository.'
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
17 import changegroup, util, mdiff, discovery, cmdutil, scmutil, exchange
18 import localrepo, changelog, manifest, filelog, revlog, error
18 import localrepo, changelog, manifest, filelog, revlog, error
19
19
20 class bundlerevlog(revlog.revlog):
20 class bundlerevlog(revlog.revlog):
@@ -202,7 +202,7 b' class bundlerepository(localrepo.localre'
202
202
203 self.tempfile = None
203 self.tempfile = None
204 f = util.posixfile(bundlename, "rb")
204 f = util.posixfile(bundlename, "rb")
205 self.bundle = changegroup.readbundle(f, bundlename)
205 self.bundle = exchange.readbundle(f, bundlename)
206 if self.bundle.compressed():
206 if self.bundle.compressed():
207 fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-",
207 fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-",
208 suffix=".hg10un")
208 suffix=".hg10un")
@@ -220,7 +220,7 b' class bundlerepository(localrepo.localre'
220 fptemp.close()
220 fptemp.close()
221
221
222 f = self.vfs.open(self.tempfile, mode="rb")
222 f = self.vfs.open(self.tempfile, mode="rb")
223 self.bundle = changegroup.readbundle(f, bundlename, self.vfs)
223 self.bundle = exchange.readbundle(f, bundlename, self.vfs)
224
224
225 # dict with the mapping 'filename' -> position in the bundle
225 # dict with the mapping 'filename' -> position in the bundle
226 self.bundlefilespos = {}
226 self.bundlefilespos = {}
@@ -227,25 +227,6 b' class headerlessfixup(object):'
227 return d
227 return d
228 return readexactly(self._fh, n)
228 return readexactly(self._fh, n)
229
229
230 def readbundle(fh, fname, vfs=None):
231 header = readexactly(fh, 6)
232
233 if not fname:
234 fname = "stream"
235 if not header.startswith('HG') and header.startswith('\0'):
236 fh = headerlessfixup(fh, header)
237 header = "HG10UN"
238 elif vfs:
239 fname = vfs.join(fname)
240
241 magic, version, alg = header[0:2], header[2:4], header[4:6]
242
243 if magic != 'HG':
244 raise util.Abort(_('%s: not a Mercurial bundle') % fname)
245 if version != '10':
246 raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
247 return unbundle10(fh, alg)
248
249 class bundle10(object):
230 class bundle10(object):
250 deltaheader = _BUNDLE10_DELTA_HEADER
231 deltaheader = _BUNDLE10_DELTA_HEADER
251 def __init__(self, repo, bundlecaps=None):
232 def __init__(self, repo, bundlecaps=None):
@@ -20,7 +20,7 b' import minirst, revset, fileset'
20 import dagparser, context, simplemerge, graphmod
20 import dagparser, context, simplemerge, graphmod
21 import random
21 import random
22 import setdiscovery, treediscovery, dagutil, pvec, localrepo
22 import setdiscovery, treediscovery, dagutil, pvec, localrepo
23 import phases, obsolete
23 import phases, obsolete, exchange
24
24
25 table = {}
25 table = {}
26
26
@@ -1736,7 +1736,7 b' def debugbundle(ui, bundlepath, all=None'
1736 """lists the contents of a bundle"""
1736 """lists the contents of a bundle"""
1737 f = hg.openpath(ui, bundlepath)
1737 f = hg.openpath(ui, bundlepath)
1738 try:
1738 try:
1739 gen = changegroup.readbundle(f, bundlepath)
1739 gen = exchange.readbundle(f, bundlepath)
1740 if all:
1740 if all:
1741 ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
1741 ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
1742
1742
@@ -5807,7 +5807,7 b' def unbundle(ui, repo, fname1, *fnames, '
5807 try:
5807 try:
5808 for fname in fnames:
5808 for fname in fnames:
5809 f = hg.openpath(ui, fname)
5809 f = hg.openpath(ui, fname)
5810 gen = changegroup.readbundle(f, fname)
5810 gen = exchange.readbundle(f, fname)
5811 modheads = changegroup.addchangegroup(repo, gen, 'unbundle',
5811 modheads = changegroup.addchangegroup(repo, gen, 'unbundle',
5812 'bundle:' + fname)
5812 'bundle:' + fname)
5813 finally:
5813 finally:
@@ -11,6 +11,25 b' import errno'
11 import util, scmutil, changegroup, base85
11 import util, scmutil, changegroup, base85
12 import discovery, phases, obsolete, bookmarks, bundle2
12 import discovery, phases, obsolete, bookmarks, bundle2
13
13
14 def readbundle(fh, fname, vfs=None):
15 header = changegroup.readexactly(fh, 6)
16
17 if not fname:
18 fname = "stream"
19 if not header.startswith('HG') and header.startswith('\0'):
20 fh = changegroup.headerlessfixup(fh, header)
21 header = "HG10UN"
22 elif vfs:
23 fname = vfs.join(fname)
24
25 magic, version, alg = header[0:2], header[2:4], header[4:6]
26
27 if magic != 'HG':
28 raise util.Abort(_('%s: not a Mercurial bundle') % fname)
29 if version != '10':
30 raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
31 return changegroup.unbundle10(fh, alg)
32
14
33
15 class pushoperation(object):
34 class pushoperation(object):
16 """A object that represent a single push operation
35 """A object that represent a single push operation
@@ -6,7 +6,7 b''
6 # This software may be used and distributed according to the terms of the
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9 from mercurial import changegroup
9 from mercurial import changegroup, exchange
10 from mercurial.node import short
10 from mercurial.node import short
11 from mercurial.i18n import _
11 from mercurial.i18n import _
12 import errno
12 import errno
@@ -147,7 +147,7 b' def strip(ui, repo, nodelist, backup="al'
147 if saveheads or savebases:
147 if saveheads or savebases:
148 ui.note(_("adding branch\n"))
148 ui.note(_("adding branch\n"))
149 f = vfs.open(chgrpfile, "rb")
149 f = vfs.open(chgrpfile, "rb")
150 gen = changegroup.readbundle(f, chgrpfile, vfs)
150 gen = exchange.readbundle(f, chgrpfile, vfs)
151 if not repo.ui.verbose:
151 if not repo.ui.verbose:
152 # silence internal shuffling chatter
152 # silence internal shuffling chatter
153 repo.ui.pushbuffer()
153 repo.ui.pushbuffer()
@@ -766,7 +766,7 b' def unbundle(repo, proto, heads):'
766 try:
766 try:
767 proto.getfile(fp)
767 proto.getfile(fp)
768 fp.seek(0)
768 fp.seek(0)
769 gen = changegroupmod.readbundle(fp, None)
769 gen = exchange.readbundle(fp, None)
770 r = exchange.unbundle(repo, gen, their_heads, 'serve',
770 r = exchange.unbundle(repo, gen, their_heads, 'serve',
771 proto._client())
771 proto._client())
772 return pushres(r)
772 return pushres(r)
General Comments 0
You need to be logged in to leave comments. Login now