##// END OF EJS Templates
move write_bundle to changegroup.py
Matt Mackall -
r3659:025f68f2 default
parent child Browse files
Show More
@@ -8,7 +8,7 b' of the GNU General Public License, incor'
8 """
8 """
9 from i18n import gettext as _
9 from i18n import gettext as _
10 from demandload import *
10 from demandload import *
11 demandload(globals(), "struct util")
11 demandload(globals(), "struct os bz2 util tempfile")
12
12
13 def getchunk(source):
13 def getchunk(source):
14 """get a chunk from a changegroup"""
14 """get a chunk from a changegroup"""
@@ -41,3 +41,55 b' def genchunk(data):'
41 def closechunk():
41 def closechunk():
42 return struct.pack(">l", 0)
42 return struct.pack(">l", 0)
43
43
44 class nocompress(object):
45 def compress(self, x):
46 return x
47 def flush(self):
48 return ""
49
50 def writebundle(cg, filename, compress):
51 """Write a bundle file and return its filename.
52
53 Existing files will not be overwritten.
54 If no filename is specified, a temporary file is created.
55 bz2 compression can be turned off.
56 The bundle file will be deleted in case of errors.
57 """
58
59 fh = None
60 cleanup = None
61 try:
62 if filename:
63 if os.path.exists(filename):
64 raise util.Abort(_("file '%s' already exists") % filename)
65 fh = open(filename, "wb")
66 else:
67 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
68 fh = os.fdopen(fd, "wb")
69 cleanup = filename
70
71 if compress:
72 fh.write("HG10")
73 z = bz2.BZ2Compressor(9)
74 else:
75 fh.write("HG10UN")
76 z = nocompress()
77 # parse the changegroup data, otherwise we will block
78 # in case of sshrepo because we don't know the end of the stream
79
80 # an empty chunkiter is the end of the changegroup
81 empty = False
82 while not empty:
83 empty = True
84 for chunk in chunkiter(cg):
85 empty = False
86 fh.write(z.compress(genchunk(chunk)))
87 fh.write(z.compress(closechunk()))
88 fh.write(z.flush())
89 cleanup = None
90 return filename
91 finally:
92 if fh is not None:
93 fh.close()
94 if cleanup is not None:
95 os.unlink(cleanup)
@@ -10,7 +10,7 b' from node import *'
10 from i18n import gettext as _
10 from i18n import gettext as _
11 demandload(globals(), "os re sys signal imp urllib pdb shlex")
11 demandload(globals(), "os re sys signal imp urllib pdb shlex")
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
13 demandload(globals(), "difflib patch tempfile time")
13 demandload(globals(), "difflib patch time")
14 demandload(globals(), "traceback errno version atexit bz2")
14 demandload(globals(), "traceback errno version atexit bz2")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
16
16
@@ -43,58 +43,6 b' def logmessage(opts):'
43 (logfile, inst.strerror))
43 (logfile, inst.strerror))
44 return message
44 return message
45
45
46 def write_bundle(cg, filename=None, compress=True):
47 """Write a bundle file and return its filename.
48
49 Existing files will not be overwritten.
50 If no filename is specified, a temporary file is created.
51 bz2 compression can be turned off.
52 The bundle file will be deleted in case of errors.
53 """
54 class nocompress(object):
55 def compress(self, x):
56 return x
57 def flush(self):
58 return ""
59
60 fh = None
61 cleanup = None
62 try:
63 if filename:
64 if os.path.exists(filename):
65 raise util.Abort(_("file '%s' already exists") % filename)
66 fh = open(filename, "wb")
67 else:
68 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
69 fh = os.fdopen(fd, "wb")
70 cleanup = filename
71
72 if compress:
73 fh.write("HG10")
74 z = bz2.BZ2Compressor(9)
75 else:
76 fh.write("HG10UN")
77 z = nocompress()
78 # parse the changegroup data, otherwise we will block
79 # in case of sshrepo because we don't know the end of the stream
80
81 # an empty chunkiter is the end of the changegroup
82 empty = False
83 while not empty:
84 empty = True
85 for chunk in changegroup.chunkiter(cg):
86 empty = False
87 fh.write(z.compress(changegroup.genchunk(chunk)))
88 fh.write(z.compress(changegroup.closechunk()))
89 fh.write(z.flush())
90 cleanup = None
91 return filename
92 finally:
93 if fh is not None:
94 fh.close()
95 if cleanup is not None:
96 os.unlink(cleanup)
97
98 def setremoteconfig(ui, opts):
46 def setremoteconfig(ui, opts):
99 "copy remote options to ui tree"
47 "copy remote options to ui tree"
100 if opts.get('ssh'):
48 if opts.get('ssh'):
@@ -384,7 +332,7 b' def bundle(ui, repo, fname, dest=None, *'
384 cg = repo.changegroupsubset(o, revs, 'bundle')
332 cg = repo.changegroupsubset(o, revs, 'bundle')
385 else:
333 else:
386 cg = repo.changegroup(o, 'bundle')
334 cg = repo.changegroup(o, 'bundle')
387 write_bundle(cg, fname)
335 changegroup.writebundle(cg, fname, False)
388
336
389 def cat(ui, repo, file1, *pats, **opts):
337 def cat(ui, repo, file1, *pats, **opts):
390 """output the latest or given revisions of files
338 """output the latest or given revisions of files
@@ -1344,7 +1292,7 b' def incoming(ui, repo, source="default",'
1344 if fname or not other.local():
1292 if fname or not other.local():
1345 # create a bundle (uncompressed if other repo is not local)
1293 # create a bundle (uncompressed if other repo is not local)
1346 cg = other.changegroup(incoming, "incoming")
1294 cg = other.changegroup(incoming, "incoming")
1347 fname = cleanup = write_bundle(cg, fname, compress=other.local())
1295 fname = cleanup = changegroup.writebundle(cg, fname, other.local())
1348 # keep written bundle?
1296 # keep written bundle?
1349 if opts["bundle"]:
1297 if opts["bundle"]:
1350 cleanup = None
1298 cleanup = None
@@ -1782,8 +1730,7 b' def rawcommit(ui, repo, *pats, **opts):'
1782 parents = [repo.lookup(p) for p in opts['parent']]
1730 parents = [repo.lookup(p) for p in opts['parent']]
1783
1731
1784 try:
1732 try:
1785 repo.rawcommit(files, message,
1733 repo.rawcommit(files, message, opts['user'], opts['date'], *parents)
1786 opts['user'], opts['date'], *parents)
1787 except ValueError, inst:
1734 except ValueError, inst:
1788 raise util.Abort(str(inst))
1735 raise util.Abort(str(inst))
1789
1736
General Comments 0
You need to be logged in to leave comments. Login now