Patchwork [2,of,2,v2] rebase: fix bug that caused transitive copy records to disappear (issue4192)

login
register
mail settings
Submitter Augie Fackler
Date June 24, 2014, 6:37 p.m.
Message ID <0deae12f924b2d8246d4.1403635034@augie-macbookair>
Download mbox | patch
Permalink /patch/5052/
State Accepted
Commit 2ba6c9b4e0ebfba72e7b3ca6468b6571a9bf8594
Headers show

Comments

Augie Fackler - June 24, 2014, 6:37 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1402168992 14400
#      Sat Jun 07 15:23:12 2014 -0400
# Node ID 0deae12f924b2d8246d43bedd5c970486fa69491
# Parent  b7af93b6c0abd7b3fa8e518062d84f8d7690e114
rebase: fix bug that caused transitive copy records to disappear (issue4192)

The defect was that copies were always duplicated against the target
revision, rather than the first parent of the revision being
rebased. This produced nominally correct results if changes were
rebased one at a time (or with --collapse), but was wrong if we
rebased a sequence of changesets which contained a sequence of copies.
Matt Mackall - July 1, 2014, 9:39 p.m.
On Tue, 2014-06-24 at 14:37 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1402168992 14400
> #      Sat Jun 07 15:23:12 2014 -0400
> # Node ID 0deae12f924b2d8246d43bedd5c970486fa69491
> # Parent  b7af93b6c0abd7b3fa8e518062d84f8d7690e114
> rebase: fix bug that caused transitive copy records to disappear (issue4192)
> 
> The defect was that copies were always duplicated against the target
> revision, rather than the first parent of the revision being
> rebased. This produced nominally correct results if changes were
> rebased one at a time (or with --collapse), but was wrong if we
> rebased a sequence of changesets which contained a sequence of copies.

These are queued for stable, thanks.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -343,7 +343,16 @@ 
                                   'resolve, then hg rebase --continue)'))
                     finally:
                         ui.setconfig('ui', 'forcemerge', '', 'rebase')
-                cmdutil.duplicatecopies(repo, rev, target)
+                if collapsef:
+                    cmdutil.duplicatecopies(repo, rev, target)
+                else:
+                    # If we're not using --collapse, we need to
+                    # duplicate copies between the revision we're
+                    # rebasing and its first parent, but *not*
+                    # duplicate any copies that have already been
+                    # performed in the destination.
+                    p1rev = repo[rev].p1().rev()
+                    cmdutil.duplicatecopies(repo, rev, p1rev, skiprev=target)
                 if not collapsef:
                     newrev = concludenode(repo, rev, p1, p2, extrafn=extrafn,
                                           editor=editor)
diff --git a/tests/test-rebase-rename.t b/tests/test-rebase-rename.t
--- a/tests/test-rebase-rename.t
+++ b/tests/test-rebase-rename.t
@@ -240,3 +240,84 @@ 
    1 files changed, 1 insertions(+), 0 deletions(-)
 
   $ cd ..
+
+Verify that copies get preserved (issue4192).
+  $ hg init copy-gets-preserved
+  $ cd copy-gets-preserved
+
+  $ echo a > a
+  $ hg add a
+  $ hg commit --message "File a created"
+  $ hg copy a b
+  $ echo b > b
+  $ hg commit --message "File b created as copy of a and modified"
+  $ hg copy b c
+  $ echo c > c
+  $ hg commit --message "File c created as copy of b and modified"
+  $ hg copy c d
+  $ echo d > d
+  $ hg commit --message "File d created as copy of c and modified"
+
+Note that there are four entries in the log for d
+  $ hg tglog --follow d
+  @  3: 'File d created as copy of c and modified'
+  |
+  o  2: 'File c created as copy of b and modified'
+  |
+  o  1: 'File b created as copy of a and modified'
+  |
+  o  0: 'File a created'
+  
+Update back to before we performed copies, and inject an unrelated change.
+  $ hg update 0
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+
+  $ echo unrelated > unrelated
+  $ hg add unrelated
+  $ hg commit --message "Unrelated file created"
+  created new head
+  $ hg update 4
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+Rebase the copies on top of the unrelated change.
+  $ hg rebase --source 1 --dest 4
+  saved backup bundle to $TESTTMP/copy-gets-preserved/.hg/*.hg (glob)
+  $ hg update 4
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+There should still be four entries in the log for d
+  $ hg tglog --follow d
+  @  4: 'File d created as copy of c and modified'
+  |
+  o  3: 'File c created as copy of b and modified'
+  |
+  o  2: 'File b created as copy of a and modified'
+  |
+  o  0: 'File a created'
+  
+Same steps as above, but with --collapse on rebase to make sure the
+copy records collapse correctly.
+  $ hg co 1
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ echo more >> unrelated
+  $ hg ci -m 'unrelated commit is unrelated'
+  created new head
+  $ hg rebase -s 2 --dest 5 --collapse
+  merging b and c to c
+  merging c and d to d
+  saved backup bundle to $TESTTMP/copy-gets-preserved/.hg/*.hg (glob)
+  $ hg co tip
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+This should show both revision 3 and 0 since 'd' was transitively a
+copy of 'a'.
+
+  $ hg tglog --follow d
+  @  3: 'Collapsed revision
+  |  * File b created as copy of a and modified
+  |  * File c created as copy of b and modified
+  |  * File d created as copy of c and modified'
+  o  0: 'File a created'
+  
+
+  $ cd ..