Show More
@@ -5,6 +5,7 b'' | |||||
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
|
8 | import time | |||
8 | from i18n import _ |
|
9 | from i18n import _ | |
9 | from node import hex, nullid |
|
10 | from node import hex, nullid | |
10 | import errno, urllib |
|
11 | import errno, urllib | |
@@ -1397,3 +1398,66 b' def generatestreamclone(repo):' | |||||
1397 | yield chunk |
|
1398 | yield chunk | |
1398 | finally: |
|
1399 | finally: | |
1399 | sopener.mustaudit = oldaudit |
|
1400 | sopener.mustaudit = oldaudit | |
|
1401 | ||||
|
1402 | def consumestreamclone(repo, fp): | |||
|
1403 | """Apply the contents from a streaming clone file. | |||
|
1404 | ||||
|
1405 | This takes the output from "streamout" and applies it to the specified | |||
|
1406 | repository. | |||
|
1407 | ||||
|
1408 | Like "streamout," the status line added by the wire protocol is not handled | |||
|
1409 | by this function. | |||
|
1410 | """ | |||
|
1411 | lock = repo.lock() | |||
|
1412 | try: | |||
|
1413 | repo.ui.status(_('streaming all changes\n')) | |||
|
1414 | l = fp.readline() | |||
|
1415 | try: | |||
|
1416 | total_files, total_bytes = map(int, l.split(' ', 1)) | |||
|
1417 | except (ValueError, TypeError): | |||
|
1418 | raise error.ResponseError( | |||
|
1419 | _('unexpected response from remote server:'), l) | |||
|
1420 | repo.ui.status(_('%d files to transfer, %s of data\n') % | |||
|
1421 | (total_files, util.bytecount(total_bytes))) | |||
|
1422 | handled_bytes = 0 | |||
|
1423 | repo.ui.progress(_('clone'), 0, total=total_bytes) | |||
|
1424 | start = time.time() | |||
|
1425 | ||||
|
1426 | tr = repo.transaction(_('clone')) | |||
|
1427 | try: | |||
|
1428 | for i in xrange(total_files): | |||
|
1429 | # XXX doesn't support '\n' or '\r' in filenames | |||
|
1430 | l = fp.readline() | |||
|
1431 | try: | |||
|
1432 | name, size = l.split('\0', 1) | |||
|
1433 | size = int(size) | |||
|
1434 | except (ValueError, TypeError): | |||
|
1435 | raise error.ResponseError( | |||
|
1436 | _('unexpected response from remote server:'), l) | |||
|
1437 | if repo.ui.debugflag: | |||
|
1438 | repo.ui.debug('adding %s (%s)\n' % | |||
|
1439 | (name, util.bytecount(size))) | |||
|
1440 | # for backwards compat, name was partially encoded | |||
|
1441 | ofp = repo.svfs(store.decodedir(name), 'w') | |||
|
1442 | for chunk in util.filechunkiter(fp, limit=size): | |||
|
1443 | handled_bytes += len(chunk) | |||
|
1444 | repo.ui.progress(_('clone'), handled_bytes, | |||
|
1445 | total=total_bytes) | |||
|
1446 | ofp.write(chunk) | |||
|
1447 | ofp.close() | |||
|
1448 | tr.close() | |||
|
1449 | finally: | |||
|
1450 | tr.release() | |||
|
1451 | ||||
|
1452 | # Writing straight to files circumvented the inmemory caches | |||
|
1453 | repo.invalidate() | |||
|
1454 | ||||
|
1455 | elapsed = time.time() - start | |||
|
1456 | if elapsed <= 0: | |||
|
1457 | elapsed = 0.001 | |||
|
1458 | repo.ui.progress(_('clone'), None) | |||
|
1459 | repo.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % | |||
|
1460 | (util.bytecount(total_bytes), elapsed, | |||
|
1461 | util.bytecount(total_bytes / elapsed))) | |||
|
1462 | finally: | |||
|
1463 | lock.release() |
@@ -1776,55 +1776,8 b' class localrepository(object):' | |||||
1776 | raise util.Abort(_('locking the remote repository failed')) |
|
1776 | raise util.Abort(_('locking the remote repository failed')) | |
1777 | elif resp != 0: |
|
1777 | elif resp != 0: | |
1778 | raise util.Abort(_('the server sent an unknown error code')) |
|
1778 | raise util.Abort(_('the server sent an unknown error code')) | |
1779 | self.ui.status(_('streaming all changes\n')) |
|
|||
1780 | l = fp.readline() |
|
|||
1781 | try: |
|
|||
1782 | total_files, total_bytes = map(int, l.split(' ', 1)) |
|
|||
1783 | except (ValueError, TypeError): |
|
|||
1784 | raise error.ResponseError( |
|
|||
1785 | _('unexpected response from remote server:'), l) |
|
|||
1786 | self.ui.status(_('%d files to transfer, %s of data\n') % |
|
|||
1787 | (total_files, util.bytecount(total_bytes))) |
|
|||
1788 | handled_bytes = 0 |
|
|||
1789 | self.ui.progress(_('clone'), 0, total=total_bytes) |
|
|||
1790 | start = time.time() |
|
|||
1791 |
|
1779 | |||
1792 | tr = self.transaction(_('clone')) |
|
1780 | exchange.consumestreamclone(self, fp) | |
1793 | try: |
|
|||
1794 | for i in xrange(total_files): |
|
|||
1795 | # XXX doesn't support '\n' or '\r' in filenames |
|
|||
1796 | l = fp.readline() |
|
|||
1797 | try: |
|
|||
1798 | name, size = l.split('\0', 1) |
|
|||
1799 | size = int(size) |
|
|||
1800 | except (ValueError, TypeError): |
|
|||
1801 | raise error.ResponseError( |
|
|||
1802 | _('unexpected response from remote server:'), l) |
|
|||
1803 | if self.ui.debugflag: |
|
|||
1804 | self.ui.debug('adding %s (%s)\n' % |
|
|||
1805 | (name, util.bytecount(size))) |
|
|||
1806 | # for backwards compat, name was partially encoded |
|
|||
1807 | ofp = self.svfs(store.decodedir(name), 'w') |
|
|||
1808 | for chunk in util.filechunkiter(fp, limit=size): |
|
|||
1809 | handled_bytes += len(chunk) |
|
|||
1810 | self.ui.progress(_('clone'), handled_bytes, |
|
|||
1811 | total=total_bytes) |
|
|||
1812 | ofp.write(chunk) |
|
|||
1813 | ofp.close() |
|
|||
1814 | tr.close() |
|
|||
1815 | finally: |
|
|||
1816 | tr.release() |
|
|||
1817 |
|
||||
1818 | # Writing straight to files circumvented the inmemory caches |
|
|||
1819 | self.invalidate() |
|
|||
1820 |
|
||||
1821 | elapsed = time.time() - start |
|
|||
1822 | if elapsed <= 0: |
|
|||
1823 | elapsed = 0.001 |
|
|||
1824 | self.ui.progress(_('clone'), None) |
|
|||
1825 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % |
|
|||
1826 | (util.bytecount(total_bytes), elapsed, |
|
|||
1827 | util.bytecount(total_bytes / elapsed))) |
|
|||
1828 |
|
1781 | |||
1829 | # new requirements = old non-format requirements + |
|
1782 | # new requirements = old non-format requirements + | |
1830 | # new format-related remote requirements |
|
1783 | # new format-related remote requirements |
General Comments 0
You need to be logged in to leave comments.
Login now