Patchwork [1,of,2] copies: create and use _loose_next function for _related

login
register
mail settings
Submitter Gábor Stefanik
Date April 4, 2018, 1:35 p.m.
Message ID <d72ca973100a1f1a4451.1522848933@GSTEFANIK.NavnGo.local>
Download mbox | patch
Permalink /patch/30295/
State New
Headers show

Comments

Gábor Stefanik - April 4, 2018, 1:35 p.m.
# HG changeset patch
# User Gábor Stefanik <gabor.stefanik@nng.com>
# Date 1522848489 -7200
#      Wed Apr 04 15:28:09 2018 +0200
# Node ID d72ca973100a1f1a4451a7d1efdc3e43ebc2912e
# Parent  656ac240f39284eec4435d25c01d71056aa4e8a5
copies: create and use _loose_next function for _related

_loose_next is going to be a variant of the next function that tries to follow
grafts and similar relationship when the regular next raises StopIteration.
This is needed for bug 5834.

________________________________
 This message, including its attachments, is confidential and the property of NNG Llc. For more information please read NNG's email policy here:
https://www.nng.com/email-policy/
By responding to this email you accept the email policy.
Yuya Nishihara - April 5, 2018, 12:52 p.m.
On Wed, 04 Apr 2018 15:35:33 +0200, Gábor Stefanik wrote:
> # HG changeset patch
> # User Gábor Stefanik <gabor.stefanik@nng.com>
> # Date 1522848489 -7200
> #      Wed Apr 04 15:28:09 2018 +0200
> # Node ID d72ca973100a1f1a4451a7d1efdc3e43ebc2912e
> # Parent  656ac240f39284eec4435d25c01d71056aa4e8a5
> copies: create and use _loose_next function for _related
> 
> _loose_next is going to be a variant of the next function that tries to follow
> grafts and similar relationship when the regular next raises StopIteration.
> This is needed for bug 5834.

Can you send this with the actual fix? It's unclear how _loose_next() will
be used to address the problem.

> +def _loose_next(g):

s/_loose_next/_loosenext/ per coding style.

> @@ -748,16 +754,16 @@
>          f1r, f2r = f1.linkrev(), f2.linkrev()
> 
>          if f1r is None:
> -            f1 = next(g1)
> +            f1, g1 = _loose_next(g1)
>          if f2r is None:
> -            f2 = next(g2)
> +            f1, g1 = _loose_next(g1)

s/g1/g2/g

>          while True:
>              f1r, f2r = f1.linkrev(), f2.linkrev()
>              if f1r > f2r:
> -                f1 = next(g1)
> +                f1, g1 = _loose_next(g1)
>              elif f2r > f1r:
> -                f2 = next(g2)
> +                f1, g1 = _loose_next(g1)

s/g1/g2/g

Patch

diff -r 656ac240f392 -r d72ca973100a mercurial/copies.py

--- a/mercurial/copies.py       Sat Mar 24 01:30:50 2018 -0400

+++ b/mercurial/copies.py       Wed Apr 04 15:28:09 2018 +0200

@@ -731,6 +731,12 @@ 


     return copies, {}, {}, {}, {}

+def _loose_next(g):

+    try:

+        return next(g), g

+    except StopIteration:

+        raise

+

 def _related(f1, f2, limit):
     """return True if f1 and f2 filectx have a common ancestor

@@ -748,16 +754,16 @@ 

         f1r, f2r = f1.linkrev(), f2.linkrev()

         if f1r is None:
-            f1 = next(g1)

+            f1, g1 = _loose_next(g1)

         if f2r is None:
-            f2 = next(g2)

+            f1, g1 = _loose_next(g1)


         while True:
             f1r, f2r = f1.linkrev(), f2.linkrev()
             if f1r > f2r:
-                f1 = next(g1)

+                f1, g1 = _loose_next(g1)

             elif f2r > f1r:
-                f2 = next(g2)

+                f1, g1 = _loose_next(g1)

             elif f1 == f2:
                 return f1 # a match
             elif f1r == f2r or f1r < limit or f2r < limit: