Patchwork [3,of,4,V2] destutil: allow to disable the "on head check" in destmerge

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 14, 2016, 3:38 p.m.
Message ID <e025ec586bdf3111bb1c.1455464295@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/13183/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 14, 2016, 3:38 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1454972295 0
#      Mon Feb 08 22:58:15 2016 +0000
# Node ID e025ec586bdf3111bb1ca85672c7cab3b407cf46
# Parent  6b38d0c01aeca0d3c2a2bbf3a0eadd04e37803e8
# EXP-Topic destination
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r e025ec586bdf
destutil: allow to disable the "on head check" in destmerge

'hg merge' refuses to pick a default destination if the working copy is not on
a head. This is a very sensible default for 'hg merge' but 'hg rebase' should
work in this situation. So we introduce a way to disable this check. It will
soon be used by rebase.
Martin von Zweigbergk - Feb. 15, 2016, 5:22 a.m.
On Sun, Feb 14, 2016 at 7:38 AM, Pierre-Yves David
<pierre-yves.david@ens-lyon.org> wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1454972295 0
> #      Mon Feb 08 22:58:15 2016 +0000
> # Node ID e025ec586bdf3111bb1ca85672c7cab3b407cf46
> # Parent  6b38d0c01aeca0d3c2a2bbf3a0eadd04e37803e8
> # EXP-Topic destination
> # Available At http://hg.netv6.net/marmoute-wip/mercurial/
> #              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r e025ec586bdf
> destutil: allow to disable the "on head check" in destmerge
>
> 'hg merge' refuses to pick a default destination if the working copy is not on
> a head. This is a very sensible default for 'hg merge' but 'hg rebase' should
> work in this situation. So we introduce a way to disable this check. It will
> soon be used by rebase.
>
> diff --git a/mercurial/destutil.py b/mercurial/destutil.py
> --- a/mercurial/destutil.py
> +++ b/mercurial/destutil.py
> @@ -214,11 +214,11 @@ def _destmergebook(repo, action='merge',
>          msg, hint = msgdestmerge['nootherbookmarks'][action]
>          raise error.Abort(msg, hint=hint)
>      assert node is not None
>      return node
>
> -def _destmergebranch(repo, action='merge', sourceset=None):
> +def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True):
>      """find merge destination based on branch heads"""
>      node = None
>
>      if sourceset is None:
>          sourceset = [repo[repo.dirstate.p1()].rev()]
> @@ -233,11 +233,11 @@ def _destmergebranch(repo, action='merge
>                  msg, hint = msgdestmerge['multiplebranchessourceset'][action]
>                  raise error.Abort(msg, hint=hint)
>              branch = ctx.branch()
>
>      bheads = repo.branchheads(branch)
> -    if not repo.revs('%ld and %ln', sourceset, bheads):
> +    if onheadcheck and not repo.revs('%ld and %ln', sourceset, bheads):
>          # Case A: working copy if not on a head. (merge only)

Just a question (i.e., not implying you should change anything): Do
you foresee onheadcheck=True being decoupled from action='merge' in
the future?

>          #
>          # This is probably a user mistake We bailout pointing at 'hg update'
>          if len(repo.heads()) <= 1:
>              msg, hint = msgdestmerge['nootherheadsbehind'][action]
> @@ -273,21 +273,22 @@ def _destmergebranch(repo, action='merge
>      else:
>          node = nbhs[0]
>      assert node is not None
>      return node
>
> -def destmerge(repo, action='merge', sourceset=None):
> +def destmerge(repo, action='merge', sourceset=None, onheadcheck=True):
>      """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
>      """
>      if repo._activebookmark:
>          node = _destmergebook(repo, action=action, sourceset=sourceset)
>      else:
> -        node = _destmergebranch(repo, action=action, sourceset=sourceset)
> +        node = _destmergebranch(repo, action=action, sourceset=sourceset,
> +                                onheadcheck=onheadcheck)
>      return repo[node].rev()
>
>  histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())'
>
>  def desthistedit(ui, repo):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Pierre-Yves David - Feb. 15, 2016, 10:34 a.m.
On 02/15/2016 05:22 AM, Martin von Zweigbergk wrote:
> On Sun, Feb 14, 2016 at 7:38 AM, Pierre-Yves David
> <pierre-yves.david@ens-lyon.org> wrote:
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@fb.com>
>> # Date 1454972295 0
>> #      Mon Feb 08 22:58:15 2016 +0000
>> # Node ID e025ec586bdf3111bb1ca85672c7cab3b407cf46
>> # Parent  6b38d0c01aeca0d3c2a2bbf3a0eadd04e37803e8
>> # EXP-Topic destination
>> # Available At http://hg.netv6.net/marmoute-wip/mercurial/
>> #              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r e025ec586bdf
>> destutil: allow to disable the "on head check" in destmerge
>>
>> 'hg merge' refuses to pick a default destination if the working copy is not on
>> a head. This is a very sensible default for 'hg merge' but 'hg rebase' should
>> work in this situation. So we introduce a way to disable this check. It will
>> soon be used by rebase.
>>
>> diff --git a/mercurial/destutil.py b/mercurial/destutil.py
>> --- a/mercurial/destutil.py
>> +++ b/mercurial/destutil.py
>> @@ -214,11 +214,11 @@ def _destmergebook(repo, action='merge',
>>           msg, hint = msgdestmerge['nootherbookmarks'][action]
>>           raise error.Abort(msg, hint=hint)
>>       assert node is not None
>>       return node
>>
>> -def _destmergebranch(repo, action='merge', sourceset=None):
>> +def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True):
>>       """find merge destination based on branch heads"""
>>       node = None
>>
>>       if sourceset is None:
>>           sourceset = [repo[repo.dirstate.p1()].rev()]
>> @@ -233,11 +233,11 @@ def _destmergebranch(repo, action='merge
>>                   msg, hint = msgdestmerge['multiplebranchessourceset'][action]
>>                   raise error.Abort(msg, hint=hint)
>>               branch = ctx.branch()
>>
>>       bheads = repo.branchheads(branch)
>> -    if not repo.revs('%ld and %ln', sourceset, bheads):
>> +    if onheadcheck and not repo.revs('%ld and %ln', sourceset, bheads):
>>           # Case A: working copy if not on a head. (merge only)
>
> Just a question (i.e., not implying you should change anything): Do
> you foresee onheadcheck=True being decoupled from action='merge' in
> the future?

Maybe, first potential usage would be through the revset. On a more 
general approach we have been bitten by coupling a bit too much this 
past month so I decided to be safe.

Patch

diff --git a/mercurial/destutil.py b/mercurial/destutil.py
--- a/mercurial/destutil.py
+++ b/mercurial/destutil.py
@@ -214,11 +214,11 @@  def _destmergebook(repo, action='merge',
         msg, hint = msgdestmerge['nootherbookmarks'][action]
         raise error.Abort(msg, hint=hint)
     assert node is not None
     return node
 
-def _destmergebranch(repo, action='merge', sourceset=None):
+def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True):
     """find merge destination based on branch heads"""
     node = None
 
     if sourceset is None:
         sourceset = [repo[repo.dirstate.p1()].rev()]
@@ -233,11 +233,11 @@  def _destmergebranch(repo, action='merge
                 msg, hint = msgdestmerge['multiplebranchessourceset'][action]
                 raise error.Abort(msg, hint=hint)
             branch = ctx.branch()
 
     bheads = repo.branchheads(branch)
-    if not repo.revs('%ld and %ln', sourceset, bheads):
+    if onheadcheck and not repo.revs('%ld and %ln', sourceset, bheads):
         # Case A: working copy if not on a head. (merge only)
         #
         # This is probably a user mistake We bailout pointing at 'hg update'
         if len(repo.heads()) <= 1:
             msg, hint = msgdestmerge['nootherheadsbehind'][action]
@@ -273,21 +273,22 @@  def _destmergebranch(repo, action='merge
     else:
         node = nbhs[0]
     assert node is not None
     return node
 
-def destmerge(repo, action='merge', sourceset=None):
+def destmerge(repo, action='merge', sourceset=None, onheadcheck=True):
     """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
     """
     if repo._activebookmark:
         node = _destmergebook(repo, action=action, sourceset=sourceset)
     else:
-        node = _destmergebranch(repo, action=action, sourceset=sourceset)
+        node = _destmergebranch(repo, action=action, sourceset=sourceset,
+                                onheadcheck=onheadcheck)
     return repo[node].rev()
 
 histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())'
 
 def desthistedit(ui, repo):