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 demandload import demandload |
8 from demandload import demandload |
9 from i18n import gettext as _ |
9 from i18n import gettext as _ |
10 demandload(globals(), "os stat util") |
10 demandload(globals(), "os stat util lock") |
11 |
11 |
12 # if server supports streaming clone, it advertises "stream" |
12 # if server supports streaming clone, it advertises "stream" |
13 # capability with value that is version+flags of repo it is serving. |
13 # capability with value that is version+flags of repo it is serving. |
14 # client only streams if it can read that repo format. |
14 # client only streams if it can read that repo format. |
15 |
15 |
63 |
63 |
64 if not repo.ui.configbool('server', 'uncompressed'): |
64 if not repo.ui.configbool('server', 'uncompressed'): |
65 fileobj.write('1\n') |
65 fileobj.write('1\n') |
66 return |
66 return |
67 |
67 |
68 fileobj.write('0\n') |
|
69 |
|
70 # get consistent snapshot of repo. lock during scan so lock not |
68 # get consistent snapshot of repo. lock during scan so lock not |
71 # needed while we stream, and commits can happen. |
69 # needed while we stream, and commits can happen. |
72 lock = repo.lock() |
70 try: |
|
71 repolock = repo.lock() |
|
72 except (lock.LockHeld, lock.LockUnavailable), inst: |
|
73 repo.ui.warn('locking the repository failed: %s\n' % (inst,)) |
|
74 fileobj.write('2\n') |
|
75 return |
|
76 |
|
77 fileobj.write('0\n') |
73 repo.ui.debug('scanning\n') |
78 repo.ui.debug('scanning\n') |
74 entries = [] |
79 entries = [] |
75 total_bytes = 0 |
80 total_bytes = 0 |
76 for name, size in walkrepo(repo.path): |
81 for name, size in walkrepo(repo.path): |
77 entries.append((name, size)) |
82 entries.append((name, size)) |
78 total_bytes += size |
83 total_bytes += size |
79 lock.release() |
84 repolock.release() |
80 |
85 |
81 repo.ui.debug('%d files, %d bytes to transfer\n' % |
86 repo.ui.debug('%d files, %d bytes to transfer\n' % |
82 (len(entries), total_bytes)) |
87 (len(entries), total_bytes)) |
83 fileobj.write('%d %d\n' % (len(entries), total_bytes)) |
88 fileobj.write('%d %d\n' % (len(entries), total_bytes)) |
84 for name, size in entries: |
89 for name, size in entries: |