35 |
35 |
36 # These make*stores functions are global so that other extensions can replace |
36 # These make*stores functions are global so that other extensions can replace |
37 # them. |
37 # them. |
38 def makelocalstores(repo): |
38 def makelocalstores(repo): |
39 """In-repo stores, like .hg/store/data; can not be discarded.""" |
39 """In-repo stores, like .hg/store/data; can not be discarded.""" |
40 localpath = os.path.join(repo.svfs.vfs.base, 'data') |
40 localpath = os.path.join(repo.svfs.vfs.base, b'data') |
41 if not os.path.exists(localpath): |
41 if not os.path.exists(localpath): |
42 os.makedirs(localpath) |
42 os.makedirs(localpath) |
43 |
43 |
44 # Instantiate local data stores |
44 # Instantiate local data stores |
45 localcontent = contentstore.remotefilelogcontentstore( |
45 localcontent = contentstore.remotefilelogcontentstore( |
90 packmetadatastore = historypack.historypackstore(repo.ui, packpath) |
90 packmetadatastore = historypack.historypackstore(repo.ui, packpath) |
91 |
91 |
92 repo.shareddatastores.append(packcontentstore) |
92 repo.shareddatastores.append(packcontentstore) |
93 repo.sharedhistorystores.append(packmetadatastore) |
93 repo.sharedhistorystores.append(packmetadatastore) |
94 shallowutil.reportpackmetrics( |
94 shallowutil.reportpackmetrics( |
95 repo.ui, 'filestore', packcontentstore, packmetadatastore |
95 repo.ui, b'filestore', packcontentstore, packmetadatastore |
96 ) |
96 ) |
97 return packcontentstore, packmetadatastore |
97 return packcontentstore, packmetadatastore |
98 |
98 |
99 |
99 |
100 def makeunionstores(repo): |
100 def makeunionstores(repo): |
132 repo.metadatastore, |
132 repo.metadatastore, |
133 fileservicedatawrite, |
133 fileservicedatawrite, |
134 fileservicehistorywrite, |
134 fileservicehistorywrite, |
135 ) |
135 ) |
136 shallowutil.reportpackmetrics( |
136 shallowutil.reportpackmetrics( |
137 repo.ui, 'filestore', packcontentstore, packmetadatastore |
137 repo.ui, b'filestore', packcontentstore, packmetadatastore |
138 ) |
138 ) |
139 |
139 |
140 |
140 |
141 def wraprepo(repo): |
141 def wraprepo(repo): |
142 class shallowrepository(repo.__class__): |
142 class shallowrepository(repo.__class__): |
143 @util.propertycache |
143 @util.propertycache |
144 def name(self): |
144 def name(self): |
145 return self.ui.config('remotefilelog', 'reponame') |
145 return self.ui.config(b'remotefilelog', b'reponame') |
146 |
146 |
147 @util.propertycache |
147 @util.propertycache |
148 def fallbackpath(self): |
148 def fallbackpath(self): |
149 path = repo.ui.config( |
149 path = repo.ui.config( |
150 "remotefilelog", |
150 b"remotefilelog", |
151 "fallbackpath", |
151 b"fallbackpath", |
152 repo.ui.config('paths', 'default'), |
152 repo.ui.config(b'paths', b'default'), |
153 ) |
153 ) |
154 if not path: |
154 if not path: |
155 raise error.Abort( |
155 raise error.Abort( |
156 "no remotefilelog server " |
156 b"no remotefilelog server " |
157 "configured - is your .hg/hgrc trusted?" |
157 b"configured - is your .hg/hgrc trusted?" |
158 ) |
158 ) |
159 |
159 |
160 return path |
160 return path |
161 |
161 |
162 def maybesparsematch(self, *revs, **kwargs): |
162 def maybesparsematch(self, *revs, **kwargs): |
222 opts=None, |
222 opts=None, |
223 ensurestart=False, |
223 ensurestart=False, |
224 ): |
224 ): |
225 """Runs prefetch in background with optional repack |
225 """Runs prefetch in background with optional repack |
226 """ |
226 """ |
227 cmd = [procutil.hgexecutable(), '-R', repo.origroot, 'prefetch'] |
227 cmd = [procutil.hgexecutable(), b'-R', repo.origroot, b'prefetch'] |
228 if repack: |
228 if repack: |
229 cmd.append('--repack') |
229 cmd.append(b'--repack') |
230 if revs: |
230 if revs: |
231 cmd += ['-r', revs] |
231 cmd += [b'-r', revs] |
232 # We know this command will find a binary, so don't block |
232 # We know this command will find a binary, so don't block |
233 # on it starting. |
233 # on it starting. |
234 procutil.runbgcommand( |
234 procutil.runbgcommand( |
235 cmd, encoding.environ, ensurestart=ensurestart |
235 cmd, encoding.environ, ensurestart=ensurestart |
236 ) |
236 ) |
239 """Prefetches all the necessary file revisions for the given revs |
239 """Prefetches all the necessary file revisions for the given revs |
240 Optionally runs repack in background |
240 Optionally runs repack in background |
241 """ |
241 """ |
242 with repo._lock( |
242 with repo._lock( |
243 repo.svfs, |
243 repo.svfs, |
244 'prefetchlock', |
244 b'prefetchlock', |
245 True, |
245 True, |
246 None, |
246 None, |
247 None, |
247 None, |
248 _('prefetching in %s') % repo.origroot, |
248 _(b'prefetching in %s') % repo.origroot, |
249 ): |
249 ): |
250 self._prefetch(revs, base, pats, opts) |
250 self._prefetch(revs, base, pats, opts) |
251 |
251 |
252 def _prefetch(self, revs, base=None, pats=None, opts=None): |
252 def _prefetch(self, revs, base=None, pats=None, opts=None): |
253 fallbackpath = self.fallbackpath |
253 fallbackpath = self.fallbackpath |
254 if fallbackpath: |
254 if fallbackpath: |
255 # If we know a rev is on the server, we should fetch the server |
255 # If we know a rev is on the server, we should fetch the server |
256 # version of those files, since our local file versions might |
256 # version of those files, since our local file versions might |
257 # become obsolete if the local commits are stripped. |
257 # become obsolete if the local commits are stripped. |
258 localrevs = repo.revs('outgoing(%s)', fallbackpath) |
258 localrevs = repo.revs(b'outgoing(%s)', fallbackpath) |
259 if base is not None and base != nullrev: |
259 if base is not None and base != nullrev: |
260 serverbase = list( |
260 serverbase = list( |
261 repo.revs('first(reverse(::%s) - %ld)', base, localrevs) |
261 repo.revs( |
|
262 b'first(reverse(::%s) - %ld)', base, localrevs |
|
263 ) |
262 ) |
264 ) |
263 if serverbase: |
265 if serverbase: |
264 base = serverbase[0] |
266 base = serverbase[0] |
265 else: |
267 else: |
266 localrevs = repo |
268 localrevs = repo |
267 |
269 |
268 mfl = repo.manifestlog |
270 mfl = repo.manifestlog |
269 mfrevlog = mfl.getstorage('') |
271 mfrevlog = mfl.getstorage(b'') |
270 if base is not None: |
272 if base is not None: |
271 mfdict = mfl[repo[base].manifestnode()].read() |
273 mfdict = mfl[repo[base].manifestnode()].read() |
272 skip = set(mfdict.iteritems()) |
274 skip = set(mfdict.iteritems()) |
273 else: |
275 else: |
274 skip = set() |
276 skip = set() |
278 files = skip.copy() |
280 files = skip.copy() |
279 serverfiles = skip.copy() |
281 serverfiles = skip.copy() |
280 visited = set() |
282 visited = set() |
281 visited.add(nullrev) |
283 visited.add(nullrev) |
282 revcount = len(revs) |
284 revcount = len(revs) |
283 progress = self.ui.makeprogress(_('prefetching'), total=revcount) |
285 progress = self.ui.makeprogress(_(b'prefetching'), total=revcount) |
284 progress.update(0) |
286 progress.update(0) |
285 for rev in sorted(revs): |
287 for rev in sorted(revs): |
286 ctx = repo[rev] |
288 ctx = repo[rev] |
287 if pats: |
289 if pats: |
288 m = scmutil.match(ctx, pats, opts) |
290 m = scmutil.match(ctx, pats, opts) |
335 repo.shallowmatch = match.always() |
337 repo.shallowmatch = match.always() |
336 |
338 |
337 makeunionstores(repo) |
339 makeunionstores(repo) |
338 |
340 |
339 repo.includepattern = repo.ui.configlist( |
341 repo.includepattern = repo.ui.configlist( |
340 "remotefilelog", "includepattern", None |
342 b"remotefilelog", b"includepattern", None |
341 ) |
343 ) |
342 repo.excludepattern = repo.ui.configlist( |
344 repo.excludepattern = repo.ui.configlist( |
343 "remotefilelog", "excludepattern", None |
345 b"remotefilelog", b"excludepattern", None |
344 ) |
346 ) |
345 if not util.safehasattr(repo, 'connectionpool'): |
347 if not util.safehasattr(repo, b'connectionpool'): |
346 repo.connectionpool = connectionpool.connectionpool(repo) |
348 repo.connectionpool = connectionpool.connectionpool(repo) |
347 |
349 |
348 if repo.includepattern or repo.excludepattern: |
350 if repo.includepattern or repo.excludepattern: |
349 repo.shallowmatch = match.match( |
351 repo.shallowmatch = match.match( |
350 repo.root, '', None, repo.includepattern, repo.excludepattern |
352 repo.root, b'', None, repo.includepattern, repo.excludepattern |
351 ) |
353 ) |