diff 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
line wrap: on
line diff
--- a/hgext/lfs/wrapper.py	Sat Jan 27 14:53:16 2018 -0500
+++ b/hgext/lfs/wrapper.py	Sat Feb 03 21:26:12 2018 -0500
@@ -249,6 +249,42 @@
     if 'lfs' in destrepo.requirements:
         destrepo.vfs.append('hgrc', util.tonativeeol('\n[extensions]\nlfs=\n'))
 
+def _prefetchfiles(repo, ctx, files):
+    """Ensure that required LFS blobs are present, fetching them as a group if
+    needed.
+
+    This is centralized logic for various prefetch hooks."""
+    pointers = []
+    localstore = repo.svfs.lfslocalblobstore
+
+    for f in files:
+        p = pointerfromctx(ctx, f)
+        if p and not localstore.has(p.oid()):
+            p.filename = f
+            pointers.append(p)
+
+    if pointers:
+        repo.svfs.lfsremoteblobstore.readbatch(pointers, localstore)
+
+def mergemodapplyupdates(orig, repo, actions, wctx, mctx, overwrite,
+                         labels=None):
+    """Ensure that the required LFS blobs are present before applying updates,
+    fetching them as a group if needed.
+
+    This has the effect of ensuring all necessary LFS blobs are present before
+    making working directory changes during an update (including after clone and
+    share) or merge."""
+
+    # Skipping 'a', 'am', 'f', 'r', 'dm', 'e', 'k', 'p' and 'pr', because they
+    # don't touch mctx.  'cd' is skipped, because changed/deleted never resolves
+    # to something from the remote side.
+    oplist = [actions[a] for a in 'g dc dg m'.split()]
+
+    _prefetchfiles(repo, mctx,
+                   [f for sublist in oplist for f, args, msg in sublist])
+
+    return orig(repo, actions, wctx, mctx, overwrite, labels)
+
 def _canskipupload(repo):
     # if remotestore is a null store, upload is a no-op and can be skipped
     return isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote)