Mercurial > hg
annotate mercurial/streamclone.py @ 6840:80e51429cb9a
introduce store classes
move store walking from streamclone.py into store.py
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Thu, 24 Jul 2008 16:32:52 +0200 |
parents | 8ff321a381d0 |
children | 43a817f3a649 |
rev | line source |
---|---|
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1 # streamclone.py - streaming clone server support for mercurial |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 # |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
4 # |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
7 |
6840
80e51429cb9a
introduce store classes
Adrian Buehlmann <adrian@cadifra.com>
parents:
6794
diff
changeset
|
8 import util, lock |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
9 |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
10 # if server supports streaming clone, it advertises "stream" |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
11 # capability with value that is version+flags of repo it is serving. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
12 # client only streams if it can read that repo format. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
13 |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
14 # stream file format is simple. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
15 # |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
16 # server writes out line that says how many files, how many total |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
17 # bytes. separator is ascii space, byte counts are strings. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
18 # |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
19 # then for each file: |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
20 # |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
21 # server writes out line that says file name, how many bytes in |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
22 # file. separator is ascii nul, byte count is string. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
23 # |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
24 # server writes out raw file data. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
25 |
6794
8ff321a381d0
Backed out changeset b9d6ab187523 (doesn't work on Python 2.3/2.4)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6782
diff
changeset
|
26 def stream_out(repo, fileobj, untrusted=False): |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
27 '''stream out all metadata files in repository. |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
28 writes to file-like object, must support write() and optional flush().''' |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
29 |
4834
439e2f2fde42
Fix inconsistency for the stream_out capability in hgweb
Edouard Gomez <ed.gomez@free.fr>
parents:
4134
diff
changeset
|
30 if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted): |
6794
8ff321a381d0
Backed out changeset b9d6ab187523 (doesn't work on Python 2.3/2.4)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6782
diff
changeset
|
31 fileobj.write('1\n') |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
32 return |
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
33 |
3687
d5dd0a2a44bc
Handle locking exceptions if streaming clone can't lock the repo. (Issue324)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2623
diff
changeset
|
34 try: |
6840
80e51429cb9a
introduce store classes
Adrian Buehlmann <adrian@cadifra.com>
parents:
6794
diff
changeset
|
35 entries, total_bytes = repo.storefiles() |
80e51429cb9a
introduce store classes
Adrian Buehlmann <adrian@cadifra.com>
parents:
6794
diff
changeset
|
36 except (lock.LockHeld, lock.LockUnavailable), inst: |
80e51429cb9a
introduce store classes
Adrian Buehlmann <adrian@cadifra.com>
parents:
6794
diff
changeset
|
37 repo.ui.warn('locking the repository failed: %s\n' % (inst,)) |
80e51429cb9a
introduce store classes
Adrian Buehlmann <adrian@cadifra.com>
parents:
6794
diff
changeset
|
38 fileobj.write('2\n') |
80e51429cb9a
introduce store classes
Adrian Buehlmann <adrian@cadifra.com>
parents:
6794
diff
changeset
|
39 return |
3687
d5dd0a2a44bc
Handle locking exceptions if streaming clone can't lock the repo. (Issue324)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2623
diff
changeset
|
40 |
6840
80e51429cb9a
introduce store classes
Adrian Buehlmann <adrian@cadifra.com>
parents:
6794
diff
changeset
|
41 fileobj.write('0\n') |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
42 repo.ui.debug('%d files, %d bytes to transfer\n' % |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
43 (len(entries), total_bytes)) |
6794
8ff321a381d0
Backed out changeset b9d6ab187523 (doesn't work on Python 2.3/2.4)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6782
diff
changeset
|
44 fileobj.write('%d %d\n' % (len(entries), total_bytes)) |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
45 for name, size in entries: |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
46 repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) |
6794
8ff321a381d0
Backed out changeset b9d6ab187523 (doesn't work on Python 2.3/2.4)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6782
diff
changeset
|
47 fileobj.write('%s\0%d\n' % (name, size)) |
3791
8643b9f90b51
introduce localrepo.spath for the store path, sopener fixes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3721
diff
changeset
|
48 for chunk in util.filechunkiter(repo.sopener(name), limit=size): |
6794
8ff321a381d0
Backed out changeset b9d6ab187523 (doesn't work on Python 2.3/2.4)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6782
diff
changeset
|
49 fileobj.write(chunk) |
8ff321a381d0
Backed out changeset b9d6ab187523 (doesn't work on Python 2.3/2.4)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6782
diff
changeset
|
50 flush = getattr(fileobj, 'flush', None) |
8ff321a381d0
Backed out changeset b9d6ab187523 (doesn't work on Python 2.3/2.4)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6782
diff
changeset
|
51 if flush: flush() |