Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 3564:eda9e7c9300d
New UnexpectedOutput exception to catch server errors in localrepo.stream_in
If the unexpected is a string, the empty string will be mentioned, and long
strings are cut to at most 400 chars.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 27 Oct 2006 18:17:12 +0200 |
parents | 9383af6f236d |
children | 23f7d9621783 |
comparison
equal
deleted
inserted
replaced
3563:db946221a58a | 3564:eda9e7c9300d |
---|---|
1781 return newheads - oldheads + 1 | 1781 return newheads - oldheads + 1 |
1782 | 1782 |
1783 | 1783 |
1784 def stream_in(self, remote): | 1784 def stream_in(self, remote): |
1785 fp = remote.stream_out() | 1785 fp = remote.stream_out() |
1786 resp = int(fp.readline()) | 1786 l = fp.readline() |
1787 try: | |
1788 resp = int(l) | |
1789 except ValueError: | |
1790 raise util.UnexpectedOutput( | |
1791 _('Unexpected response from remote server:'), l) | |
1787 if resp != 0: | 1792 if resp != 0: |
1788 raise util.Abort(_('operation forbidden by server')) | 1793 raise util.Abort(_('operation forbidden by server')) |
1789 self.ui.status(_('streaming all changes\n')) | 1794 self.ui.status(_('streaming all changes\n')) |
1790 total_files, total_bytes = map(int, fp.readline().split(' ', 1)) | 1795 l = fp.readline() |
1796 try: | |
1797 total_files, total_bytes = map(int, l.split(' ', 1)) | |
1798 except ValueError, TypeError: | |
1799 raise util.UnexpectedOutput( | |
1800 _('Unexpected response from remote server:'), l) | |
1791 self.ui.status(_('%d files to transfer, %s of data\n') % | 1801 self.ui.status(_('%d files to transfer, %s of data\n') % |
1792 (total_files, util.bytecount(total_bytes))) | 1802 (total_files, util.bytecount(total_bytes))) |
1793 start = time.time() | 1803 start = time.time() |
1794 for i in xrange(total_files): | 1804 for i in xrange(total_files): |
1795 name, size = fp.readline().split('\0', 1) | 1805 l = fp.readline() |
1796 size = int(size) | 1806 try: |
1807 name, size = l.split('\0', 1) | |
1808 size = int(size) | |
1809 except ValueError, TypeError: | |
1810 raise util.UnexpectedOutput( | |
1811 _('Unexpected response from remote server:'), l) | |
1797 self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) | 1812 self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) |
1798 ofp = self.sopener(name, 'w') | 1813 ofp = self.sopener(name, 'w') |
1799 for chunk in util.filechunkiter(fp, limit=size): | 1814 for chunk in util.filechunkiter(fp, limit=size): |
1800 ofp.write(chunk) | 1815 ofp.write(chunk) |
1801 ofp.close() | 1816 ofp.close() |