Patchwork [3,of,3,relative-diff] patch.diff: restrict matcher to relative root in certain cases

login
register
mail settings
Submitter Siddharth Agarwal
Date March 24, 2015, 12:36 a.m.
Message ID <f330222612e877d983b6.1427157396@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8226/
State Accepted
Commit f5f4dc115fb2cd53a0fe6a6afebbaec43efe7344
Headers show

Comments

Siddharth Agarwal - March 24, 2015, 12:36 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1426632396 25200
#      Tue Mar 17 15:46:36 2015 -0700
# Node ID f330222612e877d983b690703196d9c941c97980
# Parent  5176824fc54fd930f8032a15792b3b68d5dd8d1f
patch.diff: restrict matcher to relative root in certain cases

Previously we'd request all results, then filter by relative root. This is
clearly inefficient, so we now restrict the matcher to the relative root for
certain easy cases.

The particular case here is when the matcher matches all files. In that case we
can simply create a matcher by the relative root.

This is purely an optimization and has no impact on correctness.
Matt Mackall - March 24, 2015, 2:35 p.m.
On Mon, 2015-03-23 at 17:36 -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1426632396 25200
> #      Tue Mar 17 15:46:36 2015 -0700
> # Node ID f330222612e877d983b690703196d9c941c97980
> # Parent  5176824fc54fd930f8032a15792b3b68d5dd8d1f
> patch.diff: restrict matcher to relative root in certain cases

These are queued for default, thanks.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2105,6 +2105,13 @@ 
     ctx1 = repo[node1]
     ctx2 = repo[node2]
 
+    relfiltered = False
+    if relroot != '' and match.always():
+        # as a special case, create a new matcher with just the relroot
+        pats = [relroot]
+        match = scmutil.match(ctx2, pats, default='path')
+        relfiltered = True
+
     if not changes:
         changes = repo.status(ctx1, ctx2, match=match)
     modified, added, removed = changes[:3]
@@ -2123,14 +2130,16 @@ 
         copy = copies.pathcopies(ctx1, ctx2)
 
     if relroot is not None:
-        # XXX this would ideally be done in the matcher, but that is generally
-        # meant to 'or' patterns, not 'and' them. In this case we need to 'and'
-        # all the patterns from the matcher with relroot.
-        def filterrel(l):
-            return [f for f in l if f.startswith(relroot)]
-        modified = filterrel(modified)
-        added = filterrel(added)
-        removed = filterrel(removed)
+        if not relfiltered:
+            # XXX this would ideally be done in the matcher, but that is
+            # generally meant to 'or' patterns, not 'and' them. In this case we
+            # need to 'and' all the patterns from the matcher with relroot.
+            def filterrel(l):
+                return [f for f in l if f.startswith(relroot)]
+            modified = filterrel(modified)
+            added = filterrel(added)
+            removed = filterrel(removed)
+            relfiltered = True
         # filter out copies where either side isn't inside the relative root
         copy = dict(((dst, src) for (dst, src) in copy.iteritems()
                      if dst.startswith(relroot)