# HG changeset patch # User Matt Harbison # Date 1602612981 14400 # Node ID 1703a7f9d5b8e4a04a76eec60a5c140b8c613222 # Parent 1f9736eb0e656f059c42a996c867a1223c14fa2c rebase: update commit hash references in the new commits This excludes the --collapse case because degenerating to p1 is almost certainly as wrong as leaving the old hashes in place. I expect most people to amend the message explicitly when using that. Differential Revision: https://phab.mercurial-scm.org/D9229 diff -r 1f9736eb0e65 -r 1703a7f9d5b8 hgext/rebase.py --- a/hgext/rebase.py Thu Oct 22 23:35:04 2020 -0700 +++ b/hgext/rebase.py Tue Oct 13 14:16:21 2020 -0400 @@ -515,6 +515,21 @@ ctx = repo[rev] if commitmsg is None: commitmsg = ctx.description() + + # Skip replacement if collapsing, as that degenerates to p1 for all + # nodes. + if not self.collapsef: + cl = repo.changelog + commitmsg = rewriteutil.update_hash_refs( + repo, + commitmsg, + { + cl.node(oldrev): [cl.node(newrev)] + for oldrev, newrev in self.state.items() + if newrev != revtodo + }, + ) + date = self.date if date is None: date = ctx.date() diff -r 1f9736eb0e65 -r 1703a7f9d5b8 tests/test-rebase-rename.t --- a/tests/test-rebase-rename.t Thu Oct 22 23:35:04 2020 -0700 +++ b/tests/test-rebase-rename.t Tue Oct 13 14:16:21 2020 -0400 @@ -312,14 +312,14 @@ $ 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 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" + $ hg commit --message "File d created as copy of c and modified (child of 327f772bc074)" Note that there are four entries in the log for d $ hg tglog --follow d - @ 3: 421b7e82bb85 'File d created as copy of c and modified' + @ 3: 6be224292cfa 'File d created as copy of c and modified (child of 327f772bc074)' | o 2: 327f772bc074 'File c created as copy of b and modified' | @@ -342,14 +342,14 @@ $ hg rebase --source 1 --dest 4 rebasing 1:79d255d24ad2 "File b created as copy of a and modified" rebasing 2:327f772bc074 "File c created as copy of b and modified" - rebasing 3:421b7e82bb85 "File d created as copy of c and modified" - saved backup bundle to $TESTTMP/copy-gets-preserved/.hg/strip-backup/79d255d24ad2-a2265555-rebase.hg + rebasing 3:6be224292cfa "File d created as copy of c and modified (child of 327f772bc074)" + saved backup bundle to $TESTTMP/copy-gets-preserved/.hg/strip-backup/79d255d24ad2-a3e674e3-rebase.hg $ 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: dbb9ba033561 'File d created as copy of c and modified' + @ 4: afbdde3a60d5 'File d created as copy of c and modified (child of af74b229bc02)' | o 3: af74b229bc02 'File c created as copy of b and modified' | @@ -368,9 +368,9 @@ rebasing 2:68bf06433839 "File b created as copy of a and modified" rebasing 3:af74b229bc02 "File c created as copy of b and modified" merging b and c to c - rebasing 4:dbb9ba033561 "File d created as copy of c and modified" + rebasing 4:afbdde3a60d5 "File d created as copy of c and modified (child of af74b229bc02)" merging c and d to d - saved backup bundle to $TESTTMP/copy-gets-preserved/.hg/strip-backup/68bf06433839-dde37595-rebase.hg + saved backup bundle to $TESTTMP/copy-gets-preserved/.hg/strip-backup/68bf06433839-29d5057f-rebase.hg $ hg co tip 3 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -378,11 +378,24 @@ copy of 'a'. $ hg tglog --follow d - @ 3: 5a46b94210e5 'Collapsed revision + @ 3: 75708a266e56 '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' + : * File d created as copy of c and modified (child of af74b229bc02)' o 0: b220cd6d2326 'File a created' + $ hg log -G -Tcompact + @ 3[tip] 75708a266e56 1970-01-01 00:00 +0000 test + | Collapsed revision + | + o 2 15258cf0cf10 1970-01-01 00:00 +0000 test + | unrelated commit is unrelated + | + o 1 1d689898494b 1970-01-01 00:00 +0000 test + | Unrelated file created + | + o 0 b220cd6d2326 1970-01-01 00:00 +0000 test + File a created + $ cd ..