Mercurial > hg
comparison mercurial/localrepo.py @ 25236:5095059340dc
exchange: move code for consuming streaming clone into exchange
For reasons outlined in the previous commit, we want to make the code
for consuming "stream bundles" reusable. This patch extracts the code
into a standalone function.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 21 May 2015 10:27:45 -0700 |
parents | 451df92cec49 |
children | 7504a7325e4c |
comparison
equal
deleted
inserted
replaced
25235:41965bf23295 | 25236:5095059340dc |
---|---|
1774 raise util.Abort(_('operation forbidden by server')) | 1774 raise util.Abort(_('operation forbidden by server')) |
1775 elif resp == 2: | 1775 elif resp == 2: |
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')) | 1779 |
1780 l = fp.readline() | 1780 exchange.consumestreamclone(self, fp) |
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 | |
1792 tr = self.transaction(_('clone')) | |
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 |
1831 # requirements from the streamed-in repository | 1784 # requirements from the streamed-in repository |
1832 self.requirements = remotereqs | ( | 1785 self.requirements = remotereqs | ( |