comparison mercurial/repocache.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents dcac24ec935b
children 687b865b95ad
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
16 hg, 16 hg,
17 obsolete, 17 obsolete,
18 scmutil, 18 scmutil,
19 util, 19 util,
20 ) 20 )
21
21 22
22 class repoloader(object): 23 class repoloader(object):
23 """Load repositories in background thread 24 """Load repositories in background thread
24 25
25 This is designed for a forking server. A cached repo cannot be obtained 26 This is designed for a forking server. A cached repo cannot be obtained
66 This function must be called after fork(), where the loader thread 67 This function must be called after fork(), where the loader thread
67 is stopped. Otherwise, the returned repo might be updated by the 68 is stopped. Otherwise, the returned repo might be updated by the
68 loader thread. 69 loader thread.
69 """ 70 """
70 if self._thread and self._thread.is_alive(): 71 if self._thread and self._thread.is_alive():
71 raise error.ProgrammingError(b'cannot obtain cached repo while ' 72 raise error.ProgrammingError(
72 b'loader is active') 73 b'cannot obtain cached repo while ' b'loader is active'
74 )
73 return self._cache.peek(path, None) 75 return self._cache.peek(path, None)
74 76
75 def _mainloop(self): 77 def _mainloop(self):
76 while self._accepting: 78 while self._accepting:
77 # Avoid heavy GC after fork(), which would cancel the benefit of 79 # Avoid heavy GC after fork(), which would cancel the benefit of
97 # pop before loading so inconsistent state wouldn't be exposed 99 # pop before loading so inconsistent state wouldn't be exposed
98 repo = self._cache.pop(path) 100 repo = self._cache.pop(path)
99 except KeyError: 101 except KeyError:
100 repo = hg.repository(self._ui, path).unfiltered() 102 repo = hg.repository(self._ui, path).unfiltered()
101 _warmupcache(repo) 103 _warmupcache(repo)
102 repo.ui.log(b'repocache', b'loaded repo into cache: %s (in %.3fs)\n', 104 repo.ui.log(
103 path, util.timer() - start) 105 b'repocache',
106 b'loaded repo into cache: %s (in %.3fs)\n',
107 path,
108 util.timer() - start,
109 )
104 self._cache.insert(path, repo) 110 self._cache.insert(path, repo)
111
105 112
106 # TODO: think about proper API of preloading cache 113 # TODO: think about proper API of preloading cache
107 def _warmupcache(repo): 114 def _warmupcache(repo):
108 repo.invalidateall() 115 repo.invalidateall()
109 repo.changelog 116 repo.changelog
112 repo.obsstore.predecessors 119 repo.obsstore.predecessors
113 repo.obsstore.children 120 repo.obsstore.children
114 for name in obsolete.cachefuncs: 121 for name in obsolete.cachefuncs:
115 obsolete.getrevs(repo, name) 122 obsolete.getrevs(repo, name)
116 repo._phasecache.loadphaserevs(repo) 123 repo._phasecache.loadphaserevs(repo)
124
117 125
118 # TODO: think about proper API of attaching preloaded attributes 126 # TODO: think about proper API of attaching preloaded attributes
119 def copycache(srcrepo, destrepo): 127 def copycache(srcrepo, destrepo):
120 """Copy cached attributes from srcrepo to destrepo""" 128 """Copy cached attributes from srcrepo to destrepo"""
121 destfilecache = destrepo._filecache 129 destfilecache = destrepo._filecache