Patchwork [2,of,3] merge: remove unnecessary matcher checks

login
register
mail settings
Submitter Durham Goode
Date March 19, 2017, 7 p.m.
Message ID <d598e42fa629195ecf43.1489950057@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/19462/
State Accepted
Headers show

Comments

Durham Goode - March 19, 2017, 7 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1489948937 25200
#      Sun Mar 19 11:42:17 2017 -0700
# Node ID d598e42fa629195ecf43f438b71603df9fb66d6d
# Parent  c2f68e8cd96f92c2fa240fe04e541c14c1bad3d8
merge: remove unnecessary matcher checks

As part of changing manifest.diff to accept a matcher, a previous patch added
matcher calls to each location in merge.manifestmerge that tested if 'x in mf'
to maintain the same behavior as before. After analyzing it further, this
matcher call isn't needed, and in fact hurts future patches ability to use the
matcher here.

Basically, all these 'if x in mf' checks were checking if a matched file's copy
source was in the matcher as well. This meant if you passed a matcher for just
file foo, it would not return file bar even if foo was a copy of bar. Since
manifestmerge cares about copy information, let's allow all lookups of copy
sources.

We also update one spot with a 'is not None' check, since it wasn't obvious that
the value could sometimes be None before, which broke when we called
matcher(None).

A future patch adds matcher optimizations to manifestmerge which causes this
code path to get covered by existing tests.
Yuya Nishihara - March 20, 2017, 6:37 a.m.
On Sun, 19 Mar 2017 12:00:57 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1489948937 25200
> #      Sun Mar 19 11:42:17 2017 -0700
> # Node ID d598e42fa629195ecf43f438b71603df9fb66d6d
> # Parent  c2f68e8cd96f92c2fa240fe04e541c14c1bad3d8
> merge: remove unnecessary matcher checks
> 
> As part of changing manifest.diff to accept a matcher, a previous patch added
> matcher calls to each location in merge.manifestmerge that tested if 'x in mf'
> to maintain the same behavior as before. After analyzing it further, this
> matcher call isn't needed, and in fact hurts future patches ability to use the
> matcher here.
> 
> Basically, all these 'if x in mf' checks were checking if a matched file's copy
> source was in the matcher as well. This meant if you passed a matcher for just
> file foo, it would not return file bar even if foo was a copy of bar. Since
> manifestmerge cares about copy information, let's allow all lookups of copy
> sources.

Makes sense. Perhaps 2e31a17ad1bf wasn't good for copy tracing. Queued.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -858,7 +858,7 @@  def manifestmerge(repo, wctx, p2, pa, br
                 pass # we'll deal with it on m2 side
             elif f in movewithdir: # directory rename, move local
                 f2 = movewithdir[f]
-                if matcher(f2) and f2 in m2:
+                if f2 in m2:
                     actions[f2] = ('m', (f, f2, None, True, pa.node()),
                                    "remote directory rename, both created")
                 else:
@@ -887,7 +887,7 @@  def manifestmerge(repo, wctx, p2, pa, br
                 pass # we'll deal with it on m1 side
             elif f in movewithdir:
                 f2 = movewithdir[f]
-                if matcher(f2) and f2 in m1:
+                if f2 in m1:
                     actions[f2] = ('m', (f2, f, None, False, pa.node()),
                                    "local directory rename, both created")
                 else:
@@ -895,7 +895,7 @@  def manifestmerge(repo, wctx, p2, pa, br
                                    "local directory rename - get from " + f)
             elif f in copy:
                 f2 = copy[f]
-                if matcher(f2) and f2 in m2:
+                if f2 in m2:
                     actions[f] = ('m', (f2, f, f2, False, pa.node()),
                                   "remote copied from " + f2)
                 else:
@@ -927,7 +927,7 @@  def manifestmerge(repo, wctx, p2, pa, br
                         # new file added in a directory that was moved
                         df = dirmove[d] + f[len(d):]
                         break
-                if matcher(df) and df in m1:
+                if df is not None and df in m1:
                     actions[df] = ('m', (df, f, f, False, pa.node()),
                             "local directory rename - respect move from " + f)
                 elif acceptremote: