merge: invoke scmutil.fileprefetchhooks() prior to applying updates
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 11 Feb 2018 13:25:56 -0500
changeset 36142 60dd840a7fdb
parent 36141 62719115875d
child 36143 5e947367606c
merge: invoke scmutil.fileprefetchhooks() prior to applying updates This moves the file list calculation into core, so other extensions don't need to duplicate it.
hgext/lfs/__init__.py
hgext/lfs/wrapper.py
mercurial/merge.py
--- a/hgext/lfs/__init__.py	Sun Feb 11 00:40:27 2018 -0500
+++ b/hgext/lfs/__init__.py	Sun Feb 11 13:25:56 2018 -0500
@@ -137,7 +137,6 @@
     fileset,
     hg,
     localrepo,
-    merge,
     minifileset,
     node,
     pycompat,
@@ -333,8 +332,6 @@
     wrapfunction(hg, 'clone', wrapper.hgclone)
     wrapfunction(hg, 'postshare', wrapper.hgpostshare)
 
-    wrapfunction(merge, 'applyupdates', wrapper.mergemodapplyupdates)
-
     scmutil.fileprefetchhooks.add('lfs', wrapper._prefetchfiles)
 
     # Make bundle choose changegroup3 instead of changegroup2. This affects
--- a/hgext/lfs/wrapper.py	Sun Feb 11 00:40:27 2018 -0500
+++ b/hgext/lfs/wrapper.py	Sun Feb 11 13:25:56 2018 -0500
@@ -251,9 +251,7 @@
 
 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."""
+    needed."""
     pointers = []
     localstore = repo.svfs.lfslocalblobstore
 
@@ -266,25 +264,6 @@
     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)
--- a/mercurial/merge.py	Sun Feb 11 00:40:27 2018 -0500
+++ b/mercurial/merge.py	Sun Feb 11 13:25:56 2018 -0500
@@ -1385,6 +1385,16 @@
     if i > 0:
         yield i, f
 
+def _prefetchfiles(repo, ctx, actions):
+    """Invoke ``scmutil.fileprefetchhooks()`` for the files relevant to the dict
+    of merge actions.  ``ctx`` is the context being merged in."""
+
+    # Skipping 'a', 'am', 'f', 'r', 'dm', 'e', 'k', 'p' and 'pr', because they
+    # don't touch the context to be merged in.  '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()]
+    prefetch = scmutil.fileprefetchhooks
+    prefetch(repo, ctx, [f for sublist in oplist for f, args, msg in sublist])
 
 def applyupdates(repo, actions, wctx, mctx, overwrite, labels=None):
     """apply the merge action list to the working directory
@@ -1396,6 +1406,8 @@
     describes how many files were affected by the update.
     """
 
+    _prefetchfiles(repo, mctx, actions)
+
     updated, merged, removed = 0, 0, 0
     ms = mergestate.clean(repo, wctx.p1().node(), mctx.node(), labels)
     moves = []