Patchwork [STABLE] rebase: move bookmark to destination for commits becoming empty (issue5627)

login
register
mail settings
Submitter Jun Wu
Date July 20, 2017, 11:40 p.m.
Message ID <3253102e6e5222a08737.1500594018@x1c>
Download mbox | patch
Permalink /patch/22535/
State Superseded
Headers show

Comments

Jun Wu - July 20, 2017, 11:40 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1500594002 25200
#      Thu Jul 20 16:40:02 2017 -0700
# Branch stable
# Node ID 3253102e6e5222a08737e7204eb672ab12e80764
# Parent  a41e0f1c9b69330a0dd8d6590787faa38d11c0ff
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 3253102e6e52
rebase: move bookmark to destination for commits becoming empty (issue5627)

When rebasing a changeset X and that changeset becomes empty, we should move
the bookmark on X to rebase destination.

This is a regression caused by scmutil.cleanupnodes refactoring.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -438,4 +438,14 @@  class rebaseruntime(object):
                                   'to commit\n') % (rev, ctx))
                         self.skipped.add(rev)
+                        # Move bookmark to destination. This cannot be handled
+                        # by scmutil.cleanupnodes since it will treat rev as
+                        # removed (no successor) and move bookmark backwards.
+                        destnode = repo[self.dest].node()
+                        bmchanges = [(name, destnode)
+                                     for name in repo.nodebookmarks(ctx.node())]
+                        if bmchanges:
+                            with repo.transaction('rebase') as tr1:
+                                repo._bookmarks.applychanges(repo, tr1,
+                                                             bmchanges)
                     self.state[rev] = p1
                     ui.debug('next revision set to %s\n' % p1)
diff --git a/tests/test-rebase-emptycommit.t b/tests/test-rebase-emptycommit.t
new file mode 100644
--- /dev/null
+++ b/tests/test-rebase-emptycommit.t
@@ -0,0 +1,40 @@ 
+  $ cat >> $HGRCPATH<<EOF
+  > [extensions]
+  > rebase=
+  > drawdag=$TESTDIR/drawdag.py
+  > EOF
+
+  $ hg init
+  $ hg debugdrawdag<<'EOS'
+  > B C
+  > |/
+  > A
+  > EOS
+
+  $ hg debugdrawdag<<'EOS'
+  > C
+  > |
+  > B
+  > EOS
+
+  $ hg bookmark -r 2 -i BOOK
+  $ hg log -G -T '{rev} {desc} {bookmarks}'
+  o  3 C
+  |
+  | o  2 C BOOK
+  | |
+  o |  1 B
+  |/
+  o  0 A
+  
+  $ hg rebase -r 2 -d 3
+  rebasing 2:dc0947a82db8 "C" (BOOK)
+  note: rebase of 2:dc0947a82db8 created no changes to commit
+  saved backup bundle to $TESTTMP/.hg/strip-backup/dc0947a82db8-d21b92a4-rebase.hg (glob)
+  $ hg log -G -T '{rev} {desc} {bookmarks}'
+  o  2 C BOOK
+  |
+  o  1 B
+  |
+  o  0 A
+