Patchwork rebase: handle succesor targets (issue5198)

login
register
mail settings
Submitter timeless@mozdev.org
Date April 11, 2016, 9:52 p.m.
Message ID <eb7a0591138f0b30f445.1460411577@waste.org>
Download mbox | patch
Permalink /patch/14528/
State Changes Requested
Headers show

Comments

timeless@mozdev.org - April 11, 2016, 9:52 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460410387 0
#      Mon Apr 11 21:33:07 2016 +0000
# Node ID eb7a0591138f0b30f445161b624293bbe605cb71
# Parent  86db5cb55d46db3984e94600f3902f47a16437ae
rebase: handle succesor targets (issue5198)
Pierre-Yves David - April 11, 2016, 10:32 p.m.
On 04/11/2016 02:52 PM, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1460410387 0
> #      Mon Apr 11 21:33:07 2016 +0000
> # Node ID eb7a0591138f0b30f445161b624293bbe605cb71
> # Parent  86db5cb55d46db3984e94600f3902f47a16437ae
> rebase: handle succesor targets (issue5198)

Can  you elaborate on what this issue is the chagneset description?

>
> diff --git a/hgext/rebase.py b/hgext/rebase.py
> --- a/hgext/rebase.py
> +++ b/hgext/rebase.py
> @@ -386,7 +386,8 @@
>                   ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, ctx)),
>                               _('changesets'), total)
>                   p1, p2, base = defineparents(repo, rev, target, state,
> -                                             targetancestors)
> +                                             targetancestors,
> +                                             obsoletenotrebased)
>                   storestatus(repo, originalwd, target, state, collapsef, keepf,
>                               keepbranchesf, external, activebookmark)
>                   storecollapsemsg(repo, collapsemsg)
> @@ -451,7 +452,8 @@
>   
>           if collapsef and not keepopen:
>               p1, p2, _base = defineparents(repo, min(state), target,
> -                                          state, targetancestors)
> +                                          state, targetancestors,
> +                                          obsoletenotrebased)
>               editopt = opts.get('edit')
>               editform = 'rebase.collapse'
>               if collapsemsg:
> @@ -737,10 +739,12 @@
>                    'experimental.rebaseskipobsolete to False')
>           raise error.Abort(msg, hint=hint)
>   
> -def defineparents(repo, rev, target, state, targetancestors):
> +def defineparents(repo, rev, target, state, targetancestors,
> +                  obsoletenotrebased):
>       'Return the new parent relationship of the revision that will be rebased'
>       parents = repo[rev].parents()
>       p1 = p2 = nullrev
> +    rp1 = None
>   
>       p1n = parents[0].rev()
>       if p1n in targetancestors:
> @@ -764,6 +768,8 @@
>           if p2n in state:
>               if p1 == target: # p1n in targetancestors or external
>                   p1 = state[p2n]
> +                if p1 == revprecursor:
> +                    rp1 = obsoletenotrebased[p2n]
>               elif state[p2n] in revskipped:
>                   p2 = nearestrebased(repo, p2n, state)
>                   if p2 is None:
> @@ -777,7 +783,7 @@
>                           'would have 3 parents') % rev)
>               p2 = p2n
>       repo.ui.debug(" future parents are %d and %d\n" %
> -                            (repo[p1].rev(), repo[p2].rev()))
> +                            (repo[rp1 or p1].rev(), repo[p2].rev()))
>   
>       if not any(p.rev() in state for p in parents):
>           # Case (1) root changeset of a non-detaching rebase set.
> @@ -821,6 +827,8 @@
>           # make it feasible to consider different cases separately. In these
>           # other cases we currently just leave it to the user to correctly
>           # resolve an impossible merge using a wrong ancestor.
> +        #
> +        # xx, p1 could be -4, and both parents could probably be -4...
>           for p in repo[rev].parents():
>               if state.get(p.rev()) == p1:
>                   base = p.rev()
> @@ -831,7 +839,7 @@
>               # Raise because this function is called wrong (see issue 4106)
>               raise AssertionError('no base found to rebase on '
>                                    '(defineparents called wrong)')
> -    return p1, p2, base
> +    return rp1 or p1, p2, base
>   
>   def isagitpatch(repo, patchname):
>       'Return true if the given patch is in git format'
> diff --git a/tests/test-rebase-obsolete.t b/tests/test-rebase-obsolete.t
> --- a/tests/test-rebase-obsolete.t
> +++ b/tests/test-rebase-obsolete.t
> @@ -863,3 +863,56 @@
>     rebasing 20:b82fb57ea638 "willconflict second version"
>     note: not rebasing 21:8b31da3c4919 "dummy change", already in destination as 19:601db7a18f51 "dummy change successor"
>     rebasing 22:7bdc8a87673d "dummy change" (tip)
> +  $ cd ..
> +
> +rebase source is obsoleted (issue5198)
> +---------------------------------
> +
> +  $ hg clone base amended
> +  updating to branch default
> +  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ cd amended
> +  $ hg up 9520eea781bc
> +  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
> +  $ echo 1 >> E
> +  $ hg commit --amend -m "E'"
> +  $ hg log -G
> +  @  9:69abe8906104 E'
> +  |
> +  | o  7:02de42196ebe H
> +  | |
> +  | | o  6:eea13746799a G
> +  | |/|
> +  | o |  5:24b6387c8c8c F
> +  |/ /
> +  | x  4:9520eea781bc E
> +  |/
> +  | o  3:32af7686d403 D
> +  | |
> +  | o  2:5fddd98957c8 C
> +  | |
> +  | o  1:42ccdea3bb16 B
> +  |/
> +  o  0:cd010b8cd998 A
> +
> +  $ hg rebase -d . -s 9520eea781bc
> +  note: not rebasing 4:9520eea781bc "E", already in destination as 9:69abe8906104 "E'"
> +  rebasing 6:eea13746799a "G"
> +  $ hg log -G
> +  o    10:17be06e82e95 G
> +  |\
> +  | @  9:69abe8906104 E'
> +  | |
> +  +---o  7:02de42196ebe H
> +  | |
> +  o |  5:24b6387c8c8c F
> +  |/
> +  | o  3:32af7686d403 D
> +  | |
> +  | o  2:5fddd98957c8 C
> +  | |
> +  | o  1:42ccdea3bb16 B
> +  |/
> +  o  0:cd010b8cd998 A
> +
> +  $ cd ..
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -386,7 +386,8 @@ 
                 ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, ctx)),
                             _('changesets'), total)
                 p1, p2, base = defineparents(repo, rev, target, state,
-                                             targetancestors)
+                                             targetancestors,
+                                             obsoletenotrebased)
                 storestatus(repo, originalwd, target, state, collapsef, keepf,
                             keepbranchesf, external, activebookmark)
                 storecollapsemsg(repo, collapsemsg)
@@ -451,7 +452,8 @@ 
 
         if collapsef and not keepopen:
             p1, p2, _base = defineparents(repo, min(state), target,
-                                          state, targetancestors)
+                                          state, targetancestors,
+                                          obsoletenotrebased)
             editopt = opts.get('edit')
             editform = 'rebase.collapse'
             if collapsemsg:
@@ -737,10 +739,12 @@ 
                  'experimental.rebaseskipobsolete to False')
         raise error.Abort(msg, hint=hint)
 
-def defineparents(repo, rev, target, state, targetancestors):
+def defineparents(repo, rev, target, state, targetancestors,
+                  obsoletenotrebased):
     'Return the new parent relationship of the revision that will be rebased'
     parents = repo[rev].parents()
     p1 = p2 = nullrev
+    rp1 = None
 
     p1n = parents[0].rev()
     if p1n in targetancestors:
@@ -764,6 +768,8 @@ 
         if p2n in state:
             if p1 == target: # p1n in targetancestors or external
                 p1 = state[p2n]
+                if p1 == revprecursor:
+                    rp1 = obsoletenotrebased[p2n]
             elif state[p2n] in revskipped:
                 p2 = nearestrebased(repo, p2n, state)
                 if p2 is None:
@@ -777,7 +783,7 @@ 
                         'would have 3 parents') % rev)
             p2 = p2n
     repo.ui.debug(" future parents are %d and %d\n" %
-                            (repo[p1].rev(), repo[p2].rev()))
+                            (repo[rp1 or p1].rev(), repo[p2].rev()))
 
     if not any(p.rev() in state for p in parents):
         # Case (1) root changeset of a non-detaching rebase set.
@@ -821,6 +827,8 @@ 
         # make it feasible to consider different cases separately. In these
         # other cases we currently just leave it to the user to correctly
         # resolve an impossible merge using a wrong ancestor.
+        #
+        # xx, p1 could be -4, and both parents could probably be -4...
         for p in repo[rev].parents():
             if state.get(p.rev()) == p1:
                 base = p.rev()
@@ -831,7 +839,7 @@ 
             # Raise because this function is called wrong (see issue 4106)
             raise AssertionError('no base found to rebase on '
                                  '(defineparents called wrong)')
-    return p1, p2, base
+    return rp1 or p1, p2, base
 
 def isagitpatch(repo, patchname):
     'Return true if the given patch is in git format'
diff --git a/tests/test-rebase-obsolete.t b/tests/test-rebase-obsolete.t
--- a/tests/test-rebase-obsolete.t
+++ b/tests/test-rebase-obsolete.t
@@ -863,3 +863,56 @@ 
   rebasing 20:b82fb57ea638 "willconflict second version"
   note: not rebasing 21:8b31da3c4919 "dummy change", already in destination as 19:601db7a18f51 "dummy change successor"
   rebasing 22:7bdc8a87673d "dummy change" (tip)
+  $ cd ..
+
+rebase source is obsoleted (issue5198)
+---------------------------------
+
+  $ hg clone base amended
+  updating to branch default
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd amended
+  $ hg up 9520eea781bc
+  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ echo 1 >> E
+  $ hg commit --amend -m "E'"
+  $ hg log -G
+  @  9:69abe8906104 E'
+  |
+  | o  7:02de42196ebe H
+  | |
+  | | o  6:eea13746799a G
+  | |/|
+  | o |  5:24b6387c8c8c F
+  |/ /
+  | x  4:9520eea781bc E
+  |/
+  | o  3:32af7686d403 D
+  | |
+  | o  2:5fddd98957c8 C
+  | |
+  | o  1:42ccdea3bb16 B
+  |/
+  o  0:cd010b8cd998 A
+  
+  $ hg rebase -d . -s 9520eea781bc
+  note: not rebasing 4:9520eea781bc "E", already in destination as 9:69abe8906104 "E'"
+  rebasing 6:eea13746799a "G"
+  $ hg log -G
+  o    10:17be06e82e95 G
+  |\
+  | @  9:69abe8906104 E'
+  | |
+  +---o  7:02de42196ebe H
+  | |
+  o |  5:24b6387c8c8c F
+  |/
+  | o  3:32af7686d403 D
+  | |
+  | o  2:5fddd98957c8 C
+  | |
+  | o  1:42ccdea3bb16 B
+  |/
+  o  0:cd010b8cd998 A
+  
+  $ cd ..