Patchwork [3,of,6,V2] merge: move foreground logic earlier

login
register
mail settings
Submitter Sean Farley
Date Jan. 12, 2014, 10:25 p.m.
Message ID <460212c85977dbeec500.1389565551@laptop.local>
Download mbox | patch
Permalink /patch/3311/
State Superseded
Headers show

Comments

Sean Farley - Jan. 12, 2014, 10:25 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1389549596 21600
#      Sun Jan 12 11:59:56 2014 -0600
# Node ID 460212c85977dbeec5007558fa26293a4a0d11f4
# Parent  1908bcdb50a7b4be9eca3e90274365355783efe7
merge: move foreground logic earlier

This changeset doesn't change any previous logic. It is mainly prepatory work
for the next few changesets which will use this foreground calculation for
guessing which head to update to.

This earlier check for foreground changes is protected by two conditions: it
only happens in a bare update (no node is provided) *and* if the head that was
previously guessed (using branchtip or tip concepts without knowledge of
obsolesence) is currently obsolete.
Pierre-Yves David - Jan. 13, 2014, 9:49 a.m.
On 01/12/2014 02:25 PM, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1389549596 21600
> #      Sun Jan 12 11:59:56 2014 -0600
> # Node ID 460212c85977dbeec5007558fa26293a4a0d11f4
> # Parent  1908bcdb50a7b4be9eca3e90274365355783efe7
> merge: move foreground logic earlier
>
> This changeset doesn't change any previous logic. It is mainly prepatory work
> for the next few changesets which will use this foreground calculation for
> guessing which head to update to.

I would like more details on the motivation to move this forward.
This is preparatory work for a high-level goal. But how will it helps 
its implementation?

> […]
> diff --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> […]
> @@ -733,14 +742,12 @@ def update(repo, node, branchmerge, forc
>                   return 0, 0, 0, 0
>   
>               if pa not in (p1, p2):  # nonlinear
>                   dirty = wc.dirty(missing=True)
>                   if dirty or onode is None:
> -                    # Branching is a bit strange to ensure we do the minimal
> -                    # amount of call to obsolete.background.
> -                    foreground = obsolete.foreground(repo, [p1.node()])
> -                    # note: the <node> variable contains a random identifier
> +                    if foreground is None:
> +                        foreground = obsolete.foreground(repo, [p1.node()])

You want a comment here about when and why foreground can be None.
Sean Farley - Jan. 13, 2014, 5:09 p.m.
pierre-yves.david@ens-lyon.org writes:

> On 01/12/2014 02:25 PM, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@gmail.com>
>> # Date 1389549596 21600
>> #      Sun Jan 12 11:59:56 2014 -0600
>> # Node ID 460212c85977dbeec5007558fa26293a4a0d11f4
>> # Parent  1908bcdb50a7b4be9eca3e90274365355783efe7
>> merge: move foreground logic earlier
>>
>> This changeset doesn't change any previous logic. It is mainly prepatory work
>> for the next few changesets which will use this foreground calculation for
>> guessing which head to update to.
>
> I would like more details on the motivation to move this forward.
> This is preparatory work for a high-level goal. But how will it helps 
> its implementation?

I don't know how much more explicit "will use this foreground
calculation for guessing which head to update to" can be, man.

>> […]
>> diff --git a/mercurial/merge.py b/mercurial/merge.py
>> --- a/mercurial/merge.py
>> +++ b/mercurial/merge.py
>> […]
>> @@ -733,14 +742,12 @@ def update(repo, node, branchmerge, forc
>>                   return 0, 0, 0, 0
>>   
>>               if pa not in (p1, p2):  # nonlinear
>>                   dirty = wc.dirty(missing=True)
>>                   if dirty or onode is None:
>> -                    # Branching is a bit strange to ensure we do the minimal
>> -                    # amount of call to obsolete.background.
>> -                    foreground = obsolete.foreground(repo, [p1.node()])
>> -                    # note: the <node> variable contains a random identifier
>> +                    if foreground is None:
>> +                        foreground = obsolete.foreground(repo, [p1.node()])
>
> You want a comment here about when and why foreground can be None.

That's fair.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -695,10 +695,19 @@  def update(repo, node, branchmerge, forc
             except error.RepoLookupError:
                 if wc.branch() == "default": # no default branch!
                     node = repo.lookup("tip") # update to tip
                 else:
                     raise util.Abort(_("branch %s not found") % wc.branch())
+
+            # We only check for foreground (successor) changesets if the node
+            # found by the above logic is obsolete
+            if repo[node].obsolete():
+                # Branching is a bit strange to ensure we do the minimal
+                # amount of call to obsolete.background.
+                foreground = obsolete.foreground(repo, [p1.node()])
+                # note: the <node> variable contains a random identifier
+
         overwrite = force and not branchmerge
 
         p2 = repo[node]
         if pa is None:
             pa = p1.ancestor(p2)
@@ -733,14 +742,12 @@  def update(repo, node, branchmerge, forc
                 return 0, 0, 0, 0
 
             if pa not in (p1, p2):  # nonlinear
                 dirty = wc.dirty(missing=True)
                 if dirty or onode is None:
-                    # Branching is a bit strange to ensure we do the minimal
-                    # amount of call to obsolete.background.
-                    foreground = obsolete.foreground(repo, [p1.node()])
-                    # note: the <node> variable contains a random identifier
+                    if foreground is None:
+                        foreground = obsolete.foreground(repo, [p1.node()])
                     if repo[node].node() in foreground:
                         pa = p1  # allow updating to successors
                     elif dirty:
                         msg = _("uncommitted changes")
                         if onode is None: