comparison hgext/lfs/wrapper.py @ 35922:0b79f99fd7b0

lfs: prefetch lfs blobs when applying merge updates In addition to merge, this method ultimately gets called by many commands: - backout - bisect - clone - fetch - graft - import (without --bypass) - pull -u - rebase - strip - share - transplant - unbundle - update Additionally, it's also called by histedit, shelve, unshelve, and split, but it seems that the related blobs should always be available locally for these. For `hg update`, it happens after the normal argument checking and pre-update hook processing, and remote corruption is detected prior to manipulating the working directory. Other commands could use this treatment (archive, cat, revert, etc), but this covers so many of the frequently used bulk commands, it seems like a good starting point. Losing the verbose message that prints the file name before a corrupt blob aborts the command is a little sad, because there's no easy way to go from oid to file name. I'd like to change that message to list the file name so it looks cleaner and less cryptic, but the pointer object is nowhere near where it needs to be to do this. So punt on that for now.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 03 Feb 2018 21:26:12 -0500
parents 47e737d27e01
children d857cad588e4
comparison
equal deleted inserted replaced
35921:47e737d27e01 35922:0b79f99fd7b0
246 orig(sourcerepo, destrepo, bookmarks, defaultpath) 246 orig(sourcerepo, destrepo, bookmarks, defaultpath)
247 247
248 # If lfs is required for this repo, permanently enable it locally 248 # If lfs is required for this repo, permanently enable it locally
249 if 'lfs' in destrepo.requirements: 249 if 'lfs' in destrepo.requirements:
250 destrepo.vfs.append('hgrc', util.tonativeeol('\n[extensions]\nlfs=\n')) 250 destrepo.vfs.append('hgrc', util.tonativeeol('\n[extensions]\nlfs=\n'))
251
252 def _prefetchfiles(repo, ctx, files):
253 """Ensure that required LFS blobs are present, fetching them as a group if
254 needed.
255
256 This is centralized logic for various prefetch hooks."""
257 pointers = []
258 localstore = repo.svfs.lfslocalblobstore
259
260 for f in files:
261 p = pointerfromctx(ctx, f)
262 if p and not localstore.has(p.oid()):
263 p.filename = f
264 pointers.append(p)
265
266 if pointers:
267 repo.svfs.lfsremoteblobstore.readbatch(pointers, localstore)
268
269 def mergemodapplyupdates(orig, repo, actions, wctx, mctx, overwrite,
270 labels=None):
271 """Ensure that the required LFS blobs are present before applying updates,
272 fetching them as a group if needed.
273
274 This has the effect of ensuring all necessary LFS blobs are present before
275 making working directory changes during an update (including after clone and
276 share) or merge."""
277
278 # Skipping 'a', 'am', 'f', 'r', 'dm', 'e', 'k', 'p' and 'pr', because they
279 # don't touch mctx. 'cd' is skipped, because changed/deleted never resolves
280 # to something from the remote side.
281 oplist = [actions[a] for a in 'g dc dg m'.split()]
282
283 _prefetchfiles(repo, mctx,
284 [f for sublist in oplist for f, args, msg in sublist])
285
286 return orig(repo, actions, wctx, mctx, overwrite, labels)
251 287
252 def _canskipupload(repo): 288 def _canskipupload(repo):
253 # if remotestore is a null store, upload is a no-op and can be skipped 289 # if remotestore is a null store, upload is a no-op and can be skipped
254 return isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote) 290 return isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote)
255 291