Patchwork [1,of,2,STABLE] destutil: add the ability to specify a search space for rebase destination

login
register
mail settings
Submitter Pierre-Yves David
Date April 30, 2016, 5:20 p.m.
Message ID <ff7be3798ec9465d9306.1462036853@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/14846/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Pierre-Yves David - April 30, 2016, 5:20 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1462034468 -7200
#      Sat Apr 30 18:41:08 2016 +0200
# Branch stable
# Node ID ff7be3798ec9465d9306a30e01ab976c941c0967
# Parent  cbf282da720ac907b492a2b1045288130d6d166e
# EXP-Topic issue5214
destutil: add the ability to specify a search space for rebase destination

In the 'hg pull --rebase', we don't want to pick a rebase destination unrelated
to the pull, we lay down basic infrastructure to allow such restriction on
stable (before 3.8 release) in this case. See issue 5214 for details.

Actual usage and test will be in the next patch.
Yuya Nishihara - May 1, 2016, 6:20 a.m.
On Sat, 30 Apr 2016 19:20:53 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1462034468 -7200
> #      Sat Apr 30 18:41:08 2016 +0200
> # Branch stable
> # Node ID ff7be3798ec9465d9306a30e01ab976c941c0967
> # Parent  cbf282da720ac907b492a2b1045288130d6d166e
> # EXP-Topic issue5214
> destutil: add the ability to specify a search space for rebase destination

> diff -r cbf282da720a -r ff7be3798ec9 mercurial/destutil.py
> --- a/mercurial/destutil.py	Wed Apr 27 01:07:40 2016 -0700
> +++ b/mercurial/destutil.py	Sat Apr 30 18:41:08 2016 +0200
> @@ -256,7 +256,7 @@
>          },
>      }
>  
> -def _destmergebook(repo, action='merge', sourceset=None):
> +def _destmergebook(repo, action='merge', sourceset=None, destspace=None):
>      """find merge destination in the active bookmark case"""
>      node = None
>      bmheads = repo.bookmarkheads(repo._activebookmark)
> @@ -275,7 +275,8 @@
>      assert node is not None
>      return node
>  
> -def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True):
> +def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True,
> +                     destspace=None):
>      """find merge destination based on branch heads"""
>      node = None
>  
> @@ -308,6 +309,12 @@
>      bheads = list(repo.revs('%ln - (%ld::)', bheads, sourceset))
>      # filters out bookmarked heads
>      nbhs = list(repo.revs('%ld - bookmark()', bheads))
> +
> +    if destspace is not None:
> +        # restrict search space
> +        # used in the 'hg pull --rebase' case, see issue 5214.
> +        nbhs = list(repo.revs('%ld and %ld', destspace, nbhs))
> +
>      if len(nbhs) > 1:
>          # Case B: There is more than 1 other anonymous heads
>          #
> @@ -339,18 +346,22 @@
>      assert node is not None
>      return node
>  
> -def destmerge(repo, action='merge', sourceset=None, onheadcheck=True):
> +def destmerge(repo, action='merge', sourceset=None, onheadcheck=True,
> +              destspace=None):
>      """return the default destination for a merge
>  
>      (or raise exception about why it can't pick one)
>  
>      :action: the action being performed, controls emitted error message
>      """
> +    # destspace is here to work around issues with `hg pull --rebase` see
> +    # issue5214 for details
>      if repo._activebookmark:
> -        node = _destmergebook(repo, action=action, sourceset=sourceset)
> +        node = _destmergebook(repo, action=action, sourceset=sourceset,
> +                              destspace=destspace)

I noticed _destmergebook() doesn't handle destspace, but it is documented in
the next patch and the BTS. So it should be okay.
Pierre-Yves David - May 2, 2016, 8:59 a.m.
On 05/01/2016 08:20 AM, Yuya Nishihara wrote:
> On Sat, 30 Apr 2016 19:20:53 +0200, Pierre-Yves David wrote:
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
>> # Date 1462034468 -7200
>> #      Sat Apr 30 18:41:08 2016 +0200
>> # Branch stable
>> # Node ID ff7be3798ec9465d9306a30e01ab976c941c0967
>> # Parent  cbf282da720ac907b492a2b1045288130d6d166e
>> # EXP-Topic issue5214
>> destutil: add the ability to specify a search space for rebase destination
>> diff -r cbf282da720a -r ff7be3798ec9 mercurial/destutil.py
>> --- a/mercurial/destutil.py	Wed Apr 27 01:07:40 2016 -0700
>> +++ b/mercurial/destutil.py	Sat Apr 30 18:41:08 2016 +0200
>> @@ -256,7 +256,7 @@
>>           },
>>       }
>>
>> -def _destmergebook(repo, action='merge', sourceset=None):
>> +def _destmergebook(repo, action='merge', sourceset=None, destspace=None):
>>       """find merge destination in the active bookmark case"""
>>       node = None
>>       bmheads = repo.bookmarkheads(repo._activebookmark)
>> @@ -275,7 +275,8 @@
>>       assert node is not None
>>       return node
>>
>> -def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True):
>> +def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True,
>> +                     destspace=None):
>>       """find merge destination based on branch heads"""
>>       node = None
>>
>> @@ -308,6 +309,12 @@
>>       bheads = list(repo.revs('%ln - (%ld::)', bheads, sourceset))
>>       # filters out bookmarked heads
>>       nbhs = list(repo.revs('%ld - bookmark()', bheads))
>> +
>> +    if destspace is not None:
>> +        # restrict search space
>> +        # used in the 'hg pull --rebase' case, see issue 5214.
>> +        nbhs = list(repo.revs('%ld and %ld', destspace, nbhs))
>> +
>>       if len(nbhs) > 1:
>>           # Case B: There is more than 1 other anonymous heads
>>           #
>> @@ -339,18 +346,22 @@
>>       assert node is not None
>>       return node
>>
>> -def destmerge(repo, action='merge', sourceset=None, onheadcheck=True):
>> +def destmerge(repo, action='merge', sourceset=None, onheadcheck=True,
>> +              destspace=None):
>>       """return the default destination for a merge
>>
>>       (or raise exception about why it can't pick one)
>>
>>       :action: the action being performed, controls emitted error message
>>       """
>> +    # destspace is here to work around issues with `hg pull --rebase` see
>> +    # issue5214 for details
>>       if repo._activebookmark:
>> -        node = _destmergebook(repo, action=action, sourceset=sourceset)
>> +        node = _destmergebook(repo, action=action, sourceset=sourceset,
>> +                              destspace=destspace)
> I noticed _destmergebook() doesn't handle destspace, but it is documented in
> the next patch and the BTS. So it should be okay.

Yes, we should probably adjust something in the bookmark case too,but I 
saw it a less critical and I delayed more work on this until next week.

Patch

diff -r cbf282da720a -r ff7be3798ec9 hgext/rebase.py
--- a/hgext/rebase.py	Wed Apr 27 01:07:40 2016 -0700
+++ b/hgext/rebase.py	Sat Apr 30 18:41:08 2016 +0200
@@ -69,12 +69,12 @@ 
             c(ctx, extra)
     return extrafn
 
-def _destrebase(repo, sourceset):
+def _destrebase(repo, sourceset, destspace=None):
     """small wrapper around destmerge to pass the right extra args
 
     Please wrap destutil.destmerge instead."""
     return destutil.destmerge(repo, action='rebase', sourceset=sourceset,
-                              onheadcheck=False)
+                              onheadcheck=False, destspace=destspace)
 
 revsetpredicate = registrar.revsetpredicate()
 
@@ -222,6 +222,9 @@ 
         srcf = opts.get('source', None)
         basef = opts.get('base', None)
         revf = opts.get('rev', [])
+        # search default destination in this space
+        # used in the 'hg pull --rebase' case, see issue 5214.
+        destspace = opts.get('_destspace')
         contf = opts.get('continue')
         abortf = opts.get('abort')
         collapsef = opts.get('collapse', False)
@@ -296,7 +299,8 @@ 
                 _checkobsrebase(repo, ui, rebaseobsrevs, rebasesetrevs,
                                 rebaseobsskipped)
         else:
-            dest, rebaseset = _definesets(ui, repo, destf, srcf, basef, revf)
+            dest, rebaseset = _definesets(ui, repo, destf, srcf, basef, revf,
+                                          destspace=destspace)
             if dest is None:
                 return _nothingtorebase()
 
@@ -525,9 +529,12 @@ 
     finally:
         release(lock, wlock)
 
-def _definesets(ui, repo, destf=None, srcf=None, basef=None, revf=[]):
+def _definesets(ui, repo, destf=None, srcf=None, basef=None, revf=[],
+                destspace=None):
     """use revisions argument to define destination and rebase set
     """
+    # destspace is here to work around issues with `hg pull --rebase` see
+    # issue5214 for details
     if srcf and basef:
         raise error.Abort(_('cannot specify both a source and a base'))
     if revf and basef:
@@ -560,7 +567,7 @@ 
                         "can't compute rebase set\n"))
             return None, None
         if not destf:
-            dest = repo[_destrebase(repo, base)]
+            dest = repo[_destrebase(repo, base, destspace=destspace)]
             destf = str(dest)
 
         commonanc = repo.revs('ancestor(%ld, %d)', base, dest).first()
@@ -598,7 +605,7 @@ 
             return None, None
 
     if not destf:
-        dest = repo[_destrebase(repo, rebaseset)]
+        dest = repo[_destrebase(repo, rebaseset, destspace=destspace)]
         destf = str(dest)
 
     return dest, rebaseset
diff -r cbf282da720a -r ff7be3798ec9 mercurial/destutil.py
--- a/mercurial/destutil.py	Wed Apr 27 01:07:40 2016 -0700
+++ b/mercurial/destutil.py	Sat Apr 30 18:41:08 2016 +0200
@@ -256,7 +256,7 @@ 
         },
     }
 
-def _destmergebook(repo, action='merge', sourceset=None):
+def _destmergebook(repo, action='merge', sourceset=None, destspace=None):
     """find merge destination in the active bookmark case"""
     node = None
     bmheads = repo.bookmarkheads(repo._activebookmark)
@@ -275,7 +275,8 @@ 
     assert node is not None
     return node
 
-def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True):
+def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True,
+                     destspace=None):
     """find merge destination based on branch heads"""
     node = None
 
@@ -308,6 +309,12 @@ 
     bheads = list(repo.revs('%ln - (%ld::)', bheads, sourceset))
     # filters out bookmarked heads
     nbhs = list(repo.revs('%ld - bookmark()', bheads))
+
+    if destspace is not None:
+        # restrict search space
+        # used in the 'hg pull --rebase' case, see issue 5214.
+        nbhs = list(repo.revs('%ld and %ld', destspace, nbhs))
+
     if len(nbhs) > 1:
         # Case B: There is more than 1 other anonymous heads
         #
@@ -339,18 +346,22 @@ 
     assert node is not None
     return node
 
-def destmerge(repo, action='merge', sourceset=None, onheadcheck=True):
+def destmerge(repo, action='merge', sourceset=None, onheadcheck=True,
+              destspace=None):
     """return the default destination for a merge
 
     (or raise exception about why it can't pick one)
 
     :action: the action being performed, controls emitted error message
     """
+    # destspace is here to work around issues with `hg pull --rebase` see
+    # issue5214 for details
     if repo._activebookmark:
-        node = _destmergebook(repo, action=action, sourceset=sourceset)
+        node = _destmergebook(repo, action=action, sourceset=sourceset,
+                              destspace=destspace)
     else:
         node = _destmergebranch(repo, action=action, sourceset=sourceset,
-                                onheadcheck=onheadcheck)
+                                onheadcheck=onheadcheck, destspace=destspace)
     return repo[node].rev()
 
 histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())'