##// END OF EJS Templates
fix problem with uncompressed clone and python 2.3.
Vadim Gelfer -
r2623:d1cbfe9e default
parent child Browse files
Show More
@@ -1,89 +1,90 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 demandload import demandload
9 9 from i18n import gettext as _
10 10 demandload(globals(), "os stat util")
11 11
12 12 # if server supports streaming clone, it advertises "stream"
13 13 # capability with value that is version+flags of repo it is serving.
14 14 # client only streams if it can read that repo format.
15 15
16 16 def walkrepo(root):
17 17 '''iterate over metadata files in repository.
18 18 walk in natural (sorted) order.
19 19 yields 2-tuples: name of .d or .i file, size of file.'''
20 20
21 21 strip_count = len(root) + len(os.sep)
22 22 def walk(path, recurse):
23 23 ents = os.listdir(path)
24 24 ents.sort()
25 25 for e in ents:
26 26 pe = os.path.join(path, e)
27 27 st = os.lstat(pe)
28 28 if stat.S_ISDIR(st.st_mode):
29 29 if recurse:
30 30 for x in walk(pe, True):
31 31 yield x
32 32 else:
33 33 if not stat.S_ISREG(st.st_mode) or len(e) < 2:
34 34 continue
35 35 sfx = e[-2:]
36 36 if sfx in ('.d', '.i'):
37 37 yield pe[strip_count:], st.st_size
38 38 # write file data first
39 39 for x in walk(os.path.join(root, 'data'), True):
40 40 yield x
41 41 # write manifest before changelog
42 42 meta = list(walk(root, False))
43 meta.sort(reverse=True)
43 meta.sort()
44 meta.reverse()
44 45 for x in meta:
45 46 yield x
46 47
47 48 # stream file format is simple.
48 49 #
49 50 # server writes out line that says how many files, how many total
50 51 # bytes. separator is ascii space, byte counts are strings.
51 52 #
52 53 # then for each file:
53 54 #
54 55 # server writes out line that says file name, how many bytes in
55 56 # file. separator is ascii nul, byte count is string.
56 57 #
57 58 # server writes out raw file data.
58 59
59 60 def stream_out(repo, fileobj):
60 61 '''stream out all metadata files in repository.
61 62 writes to file-like object, must support write() and optional flush().'''
62 63
63 64 if not repo.ui.configbool('server', 'uncompressed'):
64 65 fileobj.write('1\n')
65 66 return
66 67
67 68 fileobj.write('0\n')
68 69
69 70 # get consistent snapshot of repo. lock during scan so lock not
70 71 # needed while we stream, and commits can happen.
71 72 lock = repo.lock()
72 73 repo.ui.debug('scanning\n')
73 74 entries = []
74 75 total_bytes = 0
75 76 for name, size in walkrepo(repo.path):
76 77 entries.append((name, size))
77 78 total_bytes += size
78 79 lock.release()
79 80
80 81 repo.ui.debug('%d files, %d bytes to transfer\n' %
81 82 (len(entries), total_bytes))
82 83 fileobj.write('%d %d\n' % (len(entries), total_bytes))
83 84 for name, size in entries:
84 85 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
85 86 fileobj.write('%s\0%d\n' % (name, size))
86 87 for chunk in util.filechunkiter(repo.opener(name), limit=size):
87 88 fileobj.write(chunk)
88 89 flush = getattr(fileobj, 'flush', None)
89 90 if flush: flush()
General Comments 0
You need to be logged in to leave comments. Login now