phase-shelve: Extract function for _optimized_match for re-use
authorJason R. Coombs <jaraco@jaraco.com>
Mon, 08 Aug 2022 13:40:08 -0400
changeset 49425 35c9f0bc2648
parent 49424 360c156e1f81
child 49426 24ffd13893cc
phase-shelve: Extract function for _optimized_match for re-use
mercurial/shelve.py
--- a/mercurial/shelve.py	Wed Aug 17 02:43:44 2022 +0200
+++ b/mercurial/shelve.py	Mon Aug 08 13:40:08 2022 -0400
@@ -210,6 +210,15 @@
             self.vfs.tryunlink(self.name + b'.' + ext)
 
 
+def _optimized_match(repo, node):
+    """
+    Create a matcher so that prefetch doesn't attempt to fetch
+    the entire repository pointlessly, and as an optimisation
+    for movedirstate, if needed.
+    """
+    return scmutil.matchfiles(repo, repo[node].files())
+
+
 class shelvedstate:
     """Handle persistence during unshelving operations.
 
@@ -579,10 +588,7 @@
             _nothingtoshelvemessaging(ui, repo, pats, opts)
             return 1
 
-        # Create a matcher so that prefetch doesn't attempt to fetch
-        # the entire repository pointlessly, and as an optimisation
-        # for movedirstate, if needed.
-        match = scmutil.matchfiles(repo, repo[node].files())
+        match = _optimized_match(repo, node)
         _shelvecreatedcommit(repo, node, name, match)
 
         ui.status(_(b'shelved as %s\n') % name)
@@ -957,7 +963,7 @@
         user=shelvectx.user(),
     )
     if snode:
-        m = scmutil.matchfiles(repo, repo[snode].files())
+        m = _optimized_match(repo, snode)
         _shelvecreatedcommit(repo, snode, basename, m)
 
     return newnode, bool(snode)