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