##// END OF EJS Templates
fix typo
Benoit Boissinot -
r5456:a58d415b default
parent child Browse files
Show More
@@ -1,95 +1,95 b''
1 # streamclone.py - streaming clone server support for mercurial
1 # streamclone.py - streaming clone server support for mercurial
2 #
2 #
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from i18n import _
8 from i18n import _
9 import os, osutil, stat, util, lock
9 import os, osutil, stat, util, lock
10
10
11 # if server supports streaming clone, it advertises "stream"
11 # if server supports streaming clone, it advertises "stream"
12 # capability with value that is version+flags of repo it is serving.
12 # capability with value that is version+flags of repo it is serving.
13 # client only streams if it can read that repo format.
13 # client only streams if it can read that repo format.
14
14
15 def walkrepo(root):
15 def walkrepo(root):
16 '''iterate over metadata files in repository.
16 '''iterate over metadata files in repository.
17 walk in natural (sorted) order.
17 walk in natural (sorted) order.
18 yields 2-tuples: name of .d or .i file, size of file.'''
18 yields 2-tuples: name of .d or .i file, size of file.'''
19
19
20 strip_count = len(root) + len(os.sep)
20 strip_count = len(root) + len(os.sep)
21 def walk(path, recurse):
21 def walk(path, recurse):
22 for e, kind, st in osutil.listdir(path, stat=True):
22 for e, kind, st in osutil.listdir(path, stat=True):
23 pe = os.path.join(path, e)
23 pe = os.path.join(path, e)
24 if kind == stat.S_IFDIR:
24 if kind == stat.S_IFDIR:
25 if recurse:
25 if recurse:
26 for x in walk(pe, True):
26 for x in walk(pe, True):
27 yield x
27 yield x
28 else:
28 else:
29 if kind != stat.S_IFREG or len(e) < 2:
29 if kind != stat.S_IFREG or len(e) < 2:
30 continue
30 continue
31 sfx = e[-2:]
31 sfx = e[-2:]
32 if sfx in ('.d', '.i'):
32 if sfx in ('.d', '.i'):
33 yield pe[strip_count:], st.st_size
33 yield pe[strip_count:], st.st_size
34 # write file data first
34 # write file data first
35 for x in walk(os.path.join(root, 'data'), True):
35 for x in walk(os.path.join(root, 'data'), True):
36 yield x
36 yield x
37 # write manifest before changelog
37 # write manifest before changelog
38 meta = list(walk(root, False))
38 meta = list(walk(root, False))
39 meta.sort()
39 meta.sort()
40 meta.reverse()
40 meta.reverse()
41 for x in meta:
41 for x in meta:
42 yield x
42 yield x
43
43
44 # stream file format is simple.
44 # stream file format is simple.
45 #
45 #
46 # server writes out line that says how many files, how many total
46 # server writes out line that says how many files, how many total
47 # bytes. separator is ascii space, byte counts are strings.
47 # bytes. separator is ascii space, byte counts are strings.
48 #
48 #
49 # then for each file:
49 # then for each file:
50 #
50 #
51 # server writes out line that says file name, how many bytes in
51 # server writes out line that says file name, how many bytes in
52 # file. separator is ascii nul, byte count is string.
52 # file. separator is ascii nul, byte count is string.
53 #
53 #
54 # server writes out raw file data.
54 # server writes out raw file data.
55
55
56 def stream_out(repo, fileobj, untrusted=False):
56 def stream_out(repo, fileobj, untrusted=False):
57 '''stream out all metadata files in repository.
57 '''stream out all metadata files in repository.
58 writes to file-like object, must support write() and optional flush().'''
58 writes to file-like object, must support write() and optional flush().'''
59
59
60 if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted):
60 if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted):
61 fileobj.write('1\n')
61 fileobj.write('1\n')
62 return
62 return
63
63
64 # get consistent snapshot of repo. lock during scan so lock not
64 # get consistent snapshot of repo. lock during scan so lock not
65 # needed while we stream, and commits can happen.
65 # needed while we stream, and commits can happen.
66 lock = None
66 repolock = None
67 try:
67 try:
68 try:
68 try:
69 repolock = repo.lock()
69 repolock = repo.lock()
70 except (lock.LockHeld, lock.LockUnavailable), inst:
70 except (lock.LockHeld, lock.LockUnavailable), inst:
71 repo.ui.warn('locking the repository failed: %s\n' % (inst,))
71 repo.ui.warn('locking the repository failed: %s\n' % (inst,))
72 fileobj.write('2\n')
72 fileobj.write('2\n')
73 return
73 return
74
74
75 fileobj.write('0\n')
75 fileobj.write('0\n')
76 repo.ui.debug('scanning\n')
76 repo.ui.debug('scanning\n')
77 entries = []
77 entries = []
78 total_bytes = 0
78 total_bytes = 0
79 for name, size in walkrepo(repo.spath):
79 for name, size in walkrepo(repo.spath):
80 name = repo.decodefn(util.pconvert(name))
80 name = repo.decodefn(util.pconvert(name))
81 entries.append((name, size))
81 entries.append((name, size))
82 total_bytes += size
82 total_bytes += size
83 finally:
83 finally:
84 del repolock
84 del repolock
85
85
86 repo.ui.debug('%d files, %d bytes to transfer\n' %
86 repo.ui.debug('%d files, %d bytes to transfer\n' %
87 (len(entries), total_bytes))
87 (len(entries), total_bytes))
88 fileobj.write('%d %d\n' % (len(entries), total_bytes))
88 fileobj.write('%d %d\n' % (len(entries), total_bytes))
89 for name, size in entries:
89 for name, size in entries:
90 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
90 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
91 fileobj.write('%s\0%d\n' % (name, size))
91 fileobj.write('%s\0%d\n' % (name, size))
92 for chunk in util.filechunkiter(repo.sopener(name), limit=size):
92 for chunk in util.filechunkiter(repo.sopener(name), limit=size):
93 fileobj.write(chunk)
93 fileobj.write(chunk)
94 flush = getattr(fileobj, 'flush', None)
94 flush = getattr(fileobj, 'flush', None)
95 if flush: flush()
95 if flush: flush()
General Comments 0
You need to be logged in to leave comments. Login now