Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 26441:56527b886d1d
streamclone: move applystreamclone() from localrepo.py
Upcoming patches will modernize the streaming clone code. Streaming
clone data and code kind of lives in its own world. exchange.py is
arguably the most appropriate existing location for it. However, over
a dozen patches from now it became apparent that there was a lot of code
related to streaming clones and that having it contained within its own
module would make it easier to comprehend. So, we establish
streamclone.py.
It's worth noting that streamclone.py existed a long time ago, last seen
in the 1.6 release. It was removed in 04f76a954842.
The function was renamed as part of the move because its old name was
redundant with the new module name. The only other content change was
"self" was renamed to "repo" and minor grammar in the docstring was
updated.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 02 Oct 2015 15:51:32 -0700 |
parents | b50f5beadf3e |
children | ef8d27f53204 |
comparison
equal
deleted
inserted
replaced
26440:85b992177d2a | 26441:56527b886d1d |
---|---|
17 import tags as tagsmod | 17 import tags as tagsmod |
18 from lock import release | 18 from lock import release |
19 import weakref, errno, os, time, inspect, random | 19 import weakref, errno, os, time, inspect, random |
20 import branchmap, pathutil | 20 import branchmap, pathutil |
21 import namespaces | 21 import namespaces |
22 import streamclone | |
22 propertycache = util.propertycache | 23 propertycache = util.propertycache |
23 filecache = scmutil.filecache | 24 filecache = scmutil.filecache |
24 | 25 |
25 class repofilecache(filecache): | 26 class repofilecache(filecache): |
26 """All filecache usage on repo are done for logic that should be unfiltered | 27 """All filecache usage on repo are done for logic that should be unfiltered |
1806 elif resp == 2: | 1807 elif resp == 2: |
1807 raise util.Abort(_('locking the remote repository failed')) | 1808 raise util.Abort(_('locking the remote repository failed')) |
1808 elif resp != 0: | 1809 elif resp != 0: |
1809 raise util.Abort(_('the server sent an unknown error code')) | 1810 raise util.Abort(_('the server sent an unknown error code')) |
1810 | 1811 |
1811 self.applystreamclone(remotereqs, rbranchmap, fp) | 1812 streamclone.applyremotedata(self, remotereqs, rbranchmap, fp) |
1812 return len(self.heads()) + 1 | 1813 return len(self.heads()) + 1 |
1813 | |
1814 def applystreamclone(self, remotereqs, remotebranchmap, fp): | |
1815 """Apply stream clone data to this repository. | |
1816 | |
1817 "remotereqs" is a set of requirements to handle the incoming data. | |
1818 "remotebranchmap" is the result of a branchmap lookup on the remote. It | |
1819 can be None. | |
1820 "fp" is a file object containing the raw stream data, suitable for | |
1821 feeding into exchange.consumestreamclone. | |
1822 """ | |
1823 lock = self.lock() | |
1824 try: | |
1825 exchange.consumestreamclone(self, fp) | |
1826 | |
1827 # new requirements = old non-format requirements + | |
1828 # new format-related remote requirements | |
1829 # requirements from the streamed-in repository | |
1830 self.requirements = remotereqs | ( | |
1831 self.requirements - self.supportedformats) | |
1832 self._applyopenerreqs() | |
1833 self._writerequirements() | |
1834 | |
1835 if remotebranchmap: | |
1836 rbheads = [] | |
1837 closed = [] | |
1838 for bheads in remotebranchmap.itervalues(): | |
1839 rbheads.extend(bheads) | |
1840 for h in bheads: | |
1841 r = self.changelog.rev(h) | |
1842 b, c = self.changelog.branchinfo(r) | |
1843 if c: | |
1844 closed.append(h) | |
1845 | |
1846 if rbheads: | |
1847 rtiprev = max((int(self.changelog.rev(node)) | |
1848 for node in rbheads)) | |
1849 cache = branchmap.branchcache(remotebranchmap, | |
1850 self[rtiprev].node(), | |
1851 rtiprev, | |
1852 closednodes=closed) | |
1853 # Try to stick it as low as possible | |
1854 # filter above served are unlikely to be fetch from a clone | |
1855 for candidate in ('base', 'immutable', 'served'): | |
1856 rview = self.filtered(candidate) | |
1857 if cache.validfor(rview): | |
1858 self._branchcaches[candidate] = cache | |
1859 cache.write(rview) | |
1860 break | |
1861 self.invalidate() | |
1862 finally: | |
1863 lock.release() | |
1864 | 1814 |
1865 def clone(self, remote, heads=[], stream=None): | 1815 def clone(self, remote, heads=[], stream=None): |
1866 '''clone remote repository. | 1816 '''clone remote repository. |
1867 | 1817 |
1868 keyword arguments: | 1818 keyword arguments: |