view tests/test-topic-stack-data.t @ 3846:f9dad99a90d5

evolve: create a new commit instead of amending one of the divergents This patch changes the behavior of evolve command while resolving content-divergence to create a new commit instead of amending one of the divergent ones. In past, I have made this change, backed out this change and now today again I am doing this change, so let's dive in some history. Using cmdrewrite.amend() was never a good option as that requires hack to delete the evolvestate and also gives us less control over things. We can't make the commit on top of different parents as that of content-divergent ones. Due to all these, I first made this change to create a new commit instead of amending one. But, after few days, there was flakiness observed in the tests and turned out that we need to do some dirstate dance as repo.dirstate.setparents() does not always fix the dirstate. That flakiness was a blocker for progress at that time and we decided to switch to amend back so that we can have things working with some hacks and we can later fix the implementation part. Now, yesterday while tackling resolving content-divergence of a stack which is as follows: C1 C2 | | B1 B2 | | A1 A2 \/ base where, A1-A2, B1-B2, C1-C2 are content-divergent with each other. Now we can resolve A1-A2 very well because they have the same parent and let's say that resolution leads to A3. Now, we want to resolve B1-B2 and make the new resolution commit on top of A3 so that we can end up something like: C3 | B3 | A3 | base however, amending one of the divergent changesets, it's not possible to create a commit on a different parent like A3 here without some relocation. We should prevent relocation as that may leads to some conflicts and should change the parent before committing. So, looking ahead, we can't move with using amend as still using that we will need some relocation hacks making code ugly and prone to bad behaviors, bugs. Let's change back to creating a new commit so that we can move forward in a good way. About repo.dirstate.setparents() not setting the dirstate, I have researched yesterday night about how we can do that and found out that we can use cmdrewrite._uncommitdirstate() here. Expect upcoming patches to improve the documentation of that function. There are lot of test changes because of change in hash but there is no behavior change. The only behavior change is in test-evolve-abort-contentdiv.t which is nice because creating a new commit helps us in stripping that while aborting. We have a lot of testing of content-divergence and no behavior change gives enough confidence for making this change. I reviewed the patch carefully to make sure there is no behavior change and I suggest reviewer to do the same.
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 13 Jun 2018 17:15:10 +0530
parents 1bc4b0807c37
children d00f0c369bc7 fb4801478d5d
line wrap: on
line source

Setup
=====

  $ . "$TESTDIR/testlib/topic_setup.sh"

  $ hg init test-list
  $ cd test-list
  $ cat <<EOF >> .hg/hgrc
  > [phases]
  > publish=false
  > EOF
  $ cat <<EOF >> $HGRCPATH
  > [experimental]
  > # disable the new graph style until we drop 3.7 support
  > graphstyle.missing = |
  > # turn evolution on
  > evolution=all
  > EOF


  $ mkcommit() {
  >    echo "$1" > "$1"
  >    hg add "$1"
  >    hg ci -m "add $1"
  > }

Build some basic graph
----------------------

  $ for x in base_a base_b base_c base_d base_e ; do
  >   mkcommit $x
  > done

Add another branch with two heads

  $ hg up 'desc(base_a)'
  0 files updated, 0 files merged, 4 files removed, 0 files unresolved
  $ hg branch lake
  marked working directory as branch lake
  (branches are permanent and global, did you want a bookmark?)
  $ mkcommit lake_a
  $ mkcommit lake_b
  $ hg up 'desc(lake_a)'
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ mkcommit lake_c
  created new head
  (consider using topic for lightweight branches. See 'hg help topic')


Add some topics
---------------

A simple topic that need rebasing

  $ hg up 'desc(base_c)'
  2 files updated, 0 files merged, 2 files removed, 0 files unresolved
  $ hg topic baz
  marked working directory as topic: baz
  $ mkcommit baz_a
  active topic 'baz' grew its first changeset
  (see 'hg help topics' for more information)
  $ mkcommit baz_b

A simple topic with unstability

  $ hg up 'desc(base_d)'
  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
  $ hg topic fuz
  marked working directory as topic: fuz
  $ mkcommit fuz_a
  active topic 'fuz' grew its first changeset
  (see 'hg help topics' for more information)
  $ mkcommit fuz_b
  $ mkcommit fuz_c
  $ hg up 'desc(fuz_a)'
  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
  $ hg commit --amend --message 'fuz1_a'
  2 new orphan changesets

A topic with multiple heads

  $ hg up 'desc(base_e)'
  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ hg topic bar
  marked working directory as topic: bar
  $ mkcommit bar_a
  active topic 'bar' grew its first changeset
  (see 'hg help topics' for more information)
  $ mkcommit bar_b
  $ mkcommit bar_c
  $ hg up 'desc(bar_b)'
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ mkcommit bar_d
  $ mkcommit bar_e
  $ hg up 'desc(bar_d)'
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ hg commit --amend --message 'bar1_d'
  1 new orphan changesets

topic 'foo' on the multi headed branch

  $ hg up 'desc(lake_a)'
  1 files updated, 0 files merged, 7 files removed, 0 files unresolved
  $ hg topic foo
  marked working directory as topic: foo
  $ mkcommit foo_a
  active topic 'foo' grew its first changeset
  (see 'hg help topics' for more information)
  $ mkcommit foo_b

Summary
-------

  $ hg summary
  parent: 21:3e54b49a3113 tip
   add foo_b
  branch: lake
  commit: (clean)
  update: 2 new changesets (update)
  phases: 22 draft
  orphan: 3 changesets
  topic:  foo
  $ hg log --graph -T '{desc} ({branch}) [{topic}]'
  @  add foo_b (lake) [foo]
  |
  o  add foo_a (lake) [foo]
  |
  | o  bar1_d (default) [bar]
  | |
  | | *  add bar_e (default) [bar]
  | | |
  | | x  add bar_d (default) [bar]
  | |/
  | | o  add bar_c (default) [bar]
  | |/
  | o  add bar_b (default) [bar]
  | |
  | o  add bar_a (default) [bar]
  | |
  | | o  fuz1_a (default) [fuz]
  | | |
  | | | *  add fuz_c (default) [fuz]
  | | | |
  | | | *  add fuz_b (default) [fuz]
  | | | |
  | | | x  add fuz_a (default) [fuz]
  | | |/
  | | | o  add baz_b (default) [baz]
  | | | |
  | | | o  add baz_a (default) [baz]
  | | | |
  +-------o  add lake_c (lake) []
  | | | |
  +-------o  add lake_b (lake) []
  | | | |
  o | | |  add lake_a (lake) []
  | | | |
  | o | |  add base_e (default) []
  | |/ /
  | o /  add base_d (default) []
  | |/
  | o  add base_c (default) []
  | |
  | o  add base_b (default) []
  |/
  o  add base_a (default) []
  

Actual Testing
==============

basic output

  $ hg topic
     bar (5 changesets, 1 troubled, 2 heads)
     baz (2 changesets)
   * foo (2 changesets)
     fuz (3 changesets, 2 troubled)

quiet version

  $ hg topic --quiet
  bar
  baz
  foo
  fuz

verbose

  $ hg topic --verbose
     bar (on branch: default, 5 changesets, 1 troubled, 2 heads)
     baz (on branch: default, 2 changesets, 2 behind)
   * foo (on branch: lake, 2 changesets, ambiguous destination: branch 'lake' has 2 heads)
     fuz (on branch: default, 3 changesets, 2 troubled, 1 behind)

json

  $ hg topic -T json
  [
   {
    "active": false,
    "changesetcount": 5,
    "headcount": 2,
    "topic": "bar",
    "troubledcount": 1
   },
   {
    "active": false,
    "changesetcount": 2,
    "topic": "baz"
   },
   {
    "active": true,
    "changesetcount": 2,
    "topic": "foo"
   },
   {
    "active": false,
    "changesetcount": 3,
    "topic": "fuz",
    "troubledcount": 2
   }
  ]

json --verbose

  $ hg topic -T json --verbose
  [
   {
    "active": false,
    "branches+": "default",
    "changesetcount": 5,
    "headcount": 2,
    "topic": "bar",
    "troubledcount": 1
   },
   {
    "active": false,
    "behindcount": 2,
    "branches+": "default",
    "changesetcount": 2,
    "topic": "baz"
   },
   {
    "active": true,
    "behinderror": "ambiguous destination: branch 'lake' has 2 heads",
    "branches+": "lake",
    "changesetcount": 2,
    "topic": "foo"
   },
   {
    "active": false,
    "behindcount": 1,
    "branches+": "default",
    "changesetcount": 3,
    "topic": "fuz",
    "troubledcount": 2
   }
  ]

Also test this situation with 'hg stack'
=======================================

  $ hg stack bar
  ### topic: bar (2 heads)
  ### target: default (branch)
  t5: add bar_c
  t2^ add bar_b (base)
  t4$ add bar_e (unstable)
  t3: bar1_d
  t2: add bar_b
  t1: add bar_a
  t0^ add base_e (base)
  $ hg stack bar -v
  ### topic: bar (2 heads)
  ### target: default (branch)
  t5(9cbadf11b44d): add bar_c
  t2(e555c7e8c767)^ add bar_b (base)
  t4(a920412b5a05)$ add bar_e (unstable)
  t3(6915989374b1): bar1_d
  t2(e555c7e8c767): add bar_b
  t1(a5c2b4e00bbf): add bar_a
  t0(92f489a6251f)^ add base_e (base)
  $ hg stack baz
  ### topic: baz
  ### target: default (branch), 2 behind
  t2: add baz_b
  t1: add baz_a
  t0^ add base_c (base)
  $ hg stack foo
  ### topic: foo
  ### target: lake (branch), ambiguous rebase destination - branch 'lake' has 2 heads
  t2@ add foo_b (current)
  t1: add foo_a
  t0^ add lake_a (base)
  $ hg stack fuz
  ### topic: fuz
  ### target: default (branch), 1 behind
  t3$ add fuz_c (unstable)
  t2$ add fuz_b (unstable)
  t1: fuz1_a
  t0^ add base_d (base)