Patchwork [3,of,4] copy: move _forwardcopies file logic to a function

login
register
mail settings
Submitter Durham Goode
Date Feb. 3, 2015, 3:20 a.m.
Message ID <7c2e0203750f9372d77c.1422933601@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7622/
State Accepted
Headers show

Comments

Durham Goode - Feb. 3, 2015, 3:20 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1422408252 28800
#      Tue Jan 27 17:24:12 2015 -0800
# Node ID 7c2e0203750f9372d77c374ce931e0bb87a54f0f
# Parent  8241440835148535f6d70f93affbb74fe2305436
copy: move _forwardcopies file logic to a function

Moves the _forwardcopies missingfiles logic to a separate function so that other
extensions which need to prefetch information about the files being
processed have a hook point.

This saves extensions from having to recompute this information themselves, and
thus saves several seconds off of various commands (like rebase).

Patch

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -144,6 +144,15 @@  def _dirstatecopies(d):
             del c[k]
     return c
 
+def _computeforwardmissing(a, b):
+    """Computes which files are in b but not a.
+    This is its own function so extensions can easily wrap this call to see what
+    files _forwardcopies is about to process.
+    """
+    missing = set(b.manifest().iterkeys())
+    missing.difference_update(a.manifest().iterkeys())
+    return missing
+
 def _forwardcopies(a, b):
     '''find {dst@b: src@a} copy mapping where a is an ancestor of b'''
 
@@ -167,9 +176,7 @@  def _forwardcopies(a, b):
     # we currently don't try to find where old files went, too expensive
     # this means we can miss a case like 'hg rm b; hg cp a b'
     cm = {}
-    missing = set(b.manifest().iterkeys())
-    missing.difference_update(a.manifest().iterkeys())
-
+    missing = _computeforwardmissing(a, b)
     ancestrycontext = a._repo.changelog.ancestors([b.rev()], inclusive=True)
     for f in missing:
         fctx = b[f]