tests/test-rebase-obsolete4.t
author Anton Shestakov <av6@dwimlabs.net>
Fri, 07 Jan 2022 11:53:23 +0300
changeset 48687 f8f2ecdde4b5
parent 46864 6b42343f3cb6
permissions -rw-r--r--
branchmap: skip obsolete revisions while computing heads It's time to make this part of core Mercurial obsolescence-aware. Not considering obsolete revisions when computing heads is clearly what Mercurial should do. But there are a couple of small issues: - Let's say tip of the repo is obsolete. There are two ways of finding tiprev for branchcache (both are in use): looking at input data for update() and looking at computed heads after update(). Previously, repo tip would be tiprev of the branchcache. With this patch, an obsolete revision can no longer be tiprev. And depending on what way we use for finding tiprev (input data vs computed heads) we'll get a different result. This is relevant when recomputing cache key from cache contents, and may lead to updating cache for obsolete revisions multiple times (not from scratch, because it still would be considered valid for a subset of revisions in the repo). - If all commits on a branch are obsolete, the branchcache will include that branch, but the list of heads will be empty (that's why there's now `if not heads` when recomputing tiprev/tipnode from cache contents). Having an entry for every branch is currently required for notify extension (and test-notify.t to pass), because notify doesn't handle revsets in its subscription config very well and will throw an error if e.g. a branch doesn't exist. - Cloning static HTTP repos may try to stat() a non-existent obsstore file. The issue is that we now care about obsolescence during clone, but statichttpvfs doesn't implement a stat method, so a regular vfs.stat() is used, and it assumes that file is local and calls os.stat(). During a clone, we're trying to stat() .hg/store/obsstore, but in static HTTP case we provide a literal URL to the obsstore file on the remote as if it were a local file path. On windows it actually results in a failure in test-static-http.t. The first issue is going to be addressed in a series dedicated to making sure branchcache is properly and timely written on disk (it wasn't perfect even before this patch, but there aren't enough tests to demonstrate that). The second issue will be addressed in a future patch for notify extension that will make it not raise an exception if a branch doesn't exist. And the third one was partially addressed in the previous patch in this series and will be properly fixed in a future patch when this series is accepted. filteredhash() grows a keyword argument to make sure that branchcache is also invalidated when there are new obsolete revisions in its repo view. This way the on-disk cache format is unchanged and compatible between versions (although it will obviously be recomputed when switching versions before/after this patch and the repo has obsolete revisions). There's one test that uses plain `hg up` without arguments while updated to a pruned commit. To make this test pass, simply return current working directory parent. Later in this series this code will be replaced by what prune command does: updating to the closest non-obsolete ancestor. Test changes: test-branch-change.t: update branch head and cache update message. The head of default listed in hg heads is changed because revision 2 was rewritten as 7, and 1 is the closest ancestor on the same branch, so it's the head of default now. The cache invalidation message appears now because of the cache hash change, since we're now accounting for obsolete revisions. Here's some context: "served.hidden" repo filter means everything is visible (no filtered revisions), so before this series branch2-served.hidden file would not contain any cache hash, only revnum and node. Now it also has a hash when there are obsolete changesets in the repo. The command that the message appears for is changing branch of 5 and 6, which are now obsolete, so the cache hash changes. In general, when cache is simply out-of-date, it can be updated using the old version as a base. But if cache hash differs, then the cache for that particular repo filter is recomputed (at least with the current implementation). This is what happens here. test-obsmarker-template.t: the pull reports 2 heads changed, but after that the repo correctly sees only 1. The new message could be better, but it's still an improvement over the previous one where hg pull suggested merging with an obsolete revision. test-obsolete.t: we can see these revisions in hg log --hidden, but they shouldn't be considered heads even with --hidden. test-rebase-obsolete{,2}.t: there were new heads created previously after making new orphan changesets, but they weren't detected. Now we are properly detecting and reporting them. test-rebase-obsolete4.t: there's only one head now because the other head is pruned and was falsely reported before. test-static-http.t: add obsstore to the list of requested files. This file doesn't exist on the remotes, but clients want it anyway (they get 404). This is fine, because there are other nonexistent files that clients request, like .hg/bookmarks or .hg/cache/tags2-served. Differential Revision: https://phab.mercurial-scm.org/D12097

==========================
Test rebase with obsolete
==========================

Enable obsolete

  $ cat >> $HGRCPATH << EOF
  > [command-templates]
  > log= {rev}:{node|short} {desc|firstline}{if(obsolete,' ({obsfate})')}
  > [experimental]
  > evolution.createmarkers=True
  > evolution.allowunstable=True
  > [phases]
  > publish=False
  > [extensions]
  > rebase=
  > drawdag=$TESTDIR/drawdag.py
  > strip=
  > EOF

Test that bookmark is moved and working dir is updated when all changesets have
equivalents in destination
  $ hg init rbsrepo && cd rbsrepo
  $ echo "[experimental]" > .hg/hgrc
  $ echo "evolution=true" >> .hg/hgrc
  $ echo root > root && hg ci -Am root
  adding root
  $ echo a > a && hg ci -Am a
  adding a
  $ hg up 0
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ echo b > b && hg ci -Am b
  adding b
  created new head
  $ hg rebase -r 2 -d 1
  rebasing 2:1e9a3c00cbe9 tip "b"
  $ hg log -r .  # working dir is at rev 3 (successor of 2)
  3:be1832deae9a b (no-eol)
  $ hg book -r 2 mybook --hidden  # rev 2 has a bookmark on it now
  bookmarking hidden changeset 1e9a3c00cbe9
  (hidden revision '1e9a3c00cbe9' was rewritten as: be1832deae9a)
  $ hg up 2 && hg log -r .  # working dir is at rev 2 again
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  2:1e9a3c00cbe9 b (rewritten using rebase as 3:be1832deae9a) (no-eol)
  $ hg rebase -r 2 -d 3 --config experimental.evolution.track-operation=1
  note: not rebasing 2:1e9a3c00cbe9 mybook "b", already in destination as 3:be1832deae9a tip "b"
Check that working directory and bookmark was updated to rev 3 although rev 2
was skipped
  $ hg log -r .
  3:be1832deae9a b (no-eol)
  $ hg bookmarks
     mybook                    3:be1832deae9a
  $ hg debugobsolete --rev tip
  1e9a3c00cbe90d236ac05ef61efcc5e40b7412bc be1832deae9ac531caa7438b8dcf6055a122cd8e 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '4', 'operation': 'rebase', 'user': 'test'}

Obsoleted working parent and bookmark could be moved if an ancestor of working
parent gets moved:

  $ hg init $TESTTMP/ancestor-wd-move
  $ cd $TESTTMP/ancestor-wd-move
  $ hg debugdrawdag <<'EOS'
  >  E D1  # rebase: D1 -> D2
  >  | |
  >  | C
  > D2 |
  >  | B
  >  |/
  >  A
  > EOS
  $ hg update D1 -q
  $ hg bookmark book -i
  $ hg rebase -r B+D1 -d E
  rebasing 1:112478962961 B "B"
  note: not rebasing 5:15ecf15e0114 book D1 tip "D1", already in destination as 2:0807738e0be9 D2 "D2"
  1 new orphan changesets
  $ hg log -G -T '{desc} {bookmarks}'
  @  B book
  |
  | x  D1
  | |
  o |  E
  | |
  | *  C
  | |
  o |  D2
  | |
  | x  B
  |/
  o  A
  
Rebasing a merge with one of its parent having a hidden successor

  $ hg init $TESTTMP/merge-p1-hidden-successor
  $ cd $TESTTMP/merge-p1-hidden-successor

  $ hg debugdrawdag <<'EOS'
  >  E
  >  |
  > B3 B2 # amend: B1 -> B2 -> B3
  >  |/   # B2 is hidden
  >  |  D
  >  |  |\
  >  | B1 C
  >  |/
  >  A
  > EOS
  1 new orphan changesets

  $ eval `hg tags -T '{tag}={node}\n'`
  $ rm .hg/localtags

  $ hg rebase -r $D -d $E
  rebasing 5:9e62094e4d94 "D"

  $ hg log -G
  o    7:a699d059adcf D
  |\
  | o  6:ecc93090a95c E
  | |
  | o  4:0dc878468a23 B3
  | |
  o |  1:96cc3511f894 C
   /
  o  0:426bada5c675 A
  
For some reasons (--hidden, directaccess, etc.),
rebasestate may contain hidden hashes. "rebase --abort" should work regardless.

  $ hg init $TESTTMP/hidden-state1
  $ cd $TESTTMP/hidden-state1

  $ hg debugdrawdag <<'EOS'
  >    C
  >    |
  >  D B # B/D=B
  >  |/  
  >  A
  > EOS

  $ eval `hg tags -T '{tag}={node}\n'`
  $ rm .hg/localtags

  $ hg update -q $C
  $ hg rebase -s $B -d $D
  rebasing 1:2ec65233581b "B"
  merging D
  warning: conflicts while merging D! (edit, then use 'hg resolve --mark')
  unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
  [240]

  $ hg debugobsolete $B
  1 new obsolescence markers
  obsoleted 1 changesets
  1 new orphan changesets
  $ hg debugobsolete $C
  1 new obsolescence markers
  obsoleted 1 changesets
  $ cp -R . $TESTTMP/hidden-state2

  $ hg log -G
  @  2:b18e25de2cf5 D
  |
  | %  1:2ec65233581b B (pruned)
  |/
  o  0:426bada5c675 A
  
  $ hg summary
  parent: 2:b18e25de2cf5 tip
   D
  branch: default
  commit: 1 modified, 1 added, 1 unknown, 1 unresolved
  update: (current)
  phases: 3 draft
  rebase: 0 rebased, 2 remaining (rebase --continue)

  $ hg rebase --abort
  rebase aborted

Also test --continue for the above case

  $ cd $TESTTMP/hidden-state2
  $ hg resolve -m
  (no more unresolved files)
  continue: hg rebase --continue
  $ hg rebase --continue
  note: not rebasing 1:2ec65233581b "B", it has no successor
  note: not rebasing 3:7829726be4dc tip "C", it has no successor
  $ hg log -G
  @  2:b18e25de2cf5 D
  |
  o  0:426bada5c675 A
  
====================
Test --stop option |
====================
  $ cd ..
  $ hg init rbstop
  $ cd rbstop
  $ echo a>a
  $ hg ci -Aqma
  $ echo b>b
  $ hg ci -Aqmb
  $ echo c>c
  $ hg ci -Aqmc
  $ echo d>d
  $ hg ci -Aqmd
  $ hg up 0 -q
  $ echo f>f
  $ hg ci -Aqmf
  $ echo D>d
  $ hg ci -Aqm "conflict with d"
  $ hg up 3 -q
  $ hg log -G --template "{rev}:{short(node)} {person(author)}\n{firstline(desc)} {topic}\n\n"
  o  5:00bfc9898aeb test
  |  conflict with d
  |
  o  4:dafd40200f93 test
  |  f
  |
  | @  3:055a42cdd887 test
  | |  d
  | |
  | o  2:177f92b77385 test
  | |  c
  | |
  | o  1:d2ae7f538514 test
  |/   b
  |
  o  0:cb9a9f314b8b test
     a
  
  $ hg rebase -s 1 -d 5
  rebasing 1:d2ae7f538514 "b"
  rebasing 2:177f92b77385 "c"
  rebasing 3:055a42cdd887 "d"
  merging d
  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
  unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
  [240]
  $ hg rebase --stop
  1 new orphan changesets
  $ hg log -G --template "{rev}:{short(node)} {person(author)}\n{firstline(desc)} {topic}\n\n"
  o  7:7fffad344617 test
  |  c
  |
  o  6:b15528633407 test
  |  b
  |
  o  5:00bfc9898aeb test
  |  conflict with d
  |
  o  4:dafd40200f93 test
  |  f
  |
  | @  3:055a42cdd887 test
  | |  d
  | |
  | x  2:177f92b77385 test
  | |  c
  | |
  | x  1:d2ae7f538514 test
  |/   b
  |
  o  0:cb9a9f314b8b test
     a
  
Test it aborts if unstable csets is not allowed:
===============================================
  $ cat >> $HGRCPATH << EOF
  > [experimental]
  > evolution.allowunstable=False
  > EOF

  $ hg strip 6 --no-backup -q
  $ hg log -G --template "{rev}:{short(node)} {person(author)}\n{firstline(desc)} {topic}\n\n"
  o  5:00bfc9898aeb test
  |  conflict with d
  |
  o  4:dafd40200f93 test
  |  f
  |
  | @  3:055a42cdd887 test
  | |  d
  | |
  | o  2:177f92b77385 test
  | |  c
  | |
  | o  1:d2ae7f538514 test
  |/   b
  |
  o  0:cb9a9f314b8b test
     a
  
  $ hg rebase -s 1 -d 5
  rebasing 1:d2ae7f538514 "b"
  rebasing 2:177f92b77385 "c"
  rebasing 3:055a42cdd887 "d"
  merging d
  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
  unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
  [240]
  $ hg rebase --stop
  abort: cannot remove original changesets with unrebased descendants
  (either enable obsmarkers to allow unstable revisions or use --keep to keep original changesets)
  [20]
  $ hg rebase --abort
  saved backup bundle to $TESTTMP/rbstop/.hg/strip-backup/b15528633407-6eb72b6f-backup.hg
  rebase aborted

Test --stop when --keep is passed:
==================================
  $ hg rebase -s 1 -d 5 --keep
  rebasing 1:d2ae7f538514 "b"
  rebasing 2:177f92b77385 "c"
  rebasing 3:055a42cdd887 "d"
  merging d
  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
  unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
  [240]
  $ hg rebase --stop
  $ hg log -G --template "{rev}:{short(node)} {person(author)}\n{firstline(desc)} {topic}\n\n"
  o  7:7fffad344617 test
  |  c
  |
  o  6:b15528633407 test
  |  b
  |
  o  5:00bfc9898aeb test
  |  conflict with d
  |
  o  4:dafd40200f93 test
  |  f
  |
  | @  3:055a42cdd887 test
  | |  d
  | |
  | o  2:177f92b77385 test
  | |  c
  | |
  | o  1:d2ae7f538514 test
  |/   b
  |
  o  0:cb9a9f314b8b test
     a
  
Test --stop aborts when --collapse was passed:
=============================================
  $ cat >> $HGRCPATH << EOF
  > [experimental]
  > evolution.allowunstable=True
  > EOF

  $ hg strip 6
  saved backup bundle to $TESTTMP/rbstop/.hg/strip-backup/b15528633407-6eb72b6f-backup.hg
  $ hg log -G --template "{rev}:{short(node)} {person(author)}\n{firstline(desc)} {topic}\n\n"
  o  5:00bfc9898aeb test
  |  conflict with d
  |
  o  4:dafd40200f93 test
  |  f
  |
  | @  3:055a42cdd887 test
  | |  d
  | |
  | o  2:177f92b77385 test
  | |  c
  | |
  | o  1:d2ae7f538514 test
  |/   b
  |
  o  0:cb9a9f314b8b test
     a
  
  $ hg rebase -s 1 -d 5 --collapse -m "collapsed b c d"
  rebasing 1:d2ae7f538514 "b"
  rebasing 2:177f92b77385 "c"
  rebasing 3:055a42cdd887 "d"
  merging d
  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
  unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
  [240]
  $ hg rebase --stop
  abort: cannot stop in --collapse session
  [20]
  $ hg rebase --abort
  rebase aborted
  $ hg diff
  $ hg log -G --template "{rev}:{short(node)} {person(author)}\n{firstline(desc)} {topic}\n\n"
  o  5:00bfc9898aeb test
  |  conflict with d
  |
  o  4:dafd40200f93 test
  |  f
  |
  | @  3:055a42cdd887 test
  | |  d
  | |
  | o  2:177f92b77385 test
  | |  c
  | |
  | o  1:d2ae7f538514 test
  |/   b
  |
  o  0:cb9a9f314b8b test
     a
  
Test --stop raise errors with conflicting options:
=================================================
  $ hg rebase -s 3 -d 5
  rebasing 3:055a42cdd887 "d"
  merging d
  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
  unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
  [240]
  $ hg rebase --stop --dry-run
  abort: cannot specify both --stop and --dry-run
  [10]

  $ hg rebase -s 3 -d 5
  abort: rebase in progress
  (use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
  [20]
  $ hg rebase --stop --continue
  abort: cannot specify both --stop and --continue
  [10]

Test --stop moves bookmarks of original revisions to new rebased nodes:
======================================================================
  $ cd ..
  $ hg init repo
  $ cd repo

  $ echo a > a
  $ hg ci -Am A
  adding a

  $ echo b > b
  $ hg ci -Am B
  adding b
  $ hg book X
  $ hg book Y

  $ echo c > c
  $ hg ci -Am C
  adding c
  $ hg book Z

  $ echo d > d
  $ hg ci -Am D
  adding d

  $ hg up 0 -q
  $ echo e > e
  $ hg ci -Am E
  adding e
  created new head

  $ echo doubt > d
  $ hg ci -Am "conflict with d"
  adding d

  $ hg log -GT "{rev}: {node|short} '{desc}' bookmarks: {bookmarks}\n"
  @  5: 39adf30bc1be 'conflict with d' bookmarks:
  |
  o  4: 9c1e55f411b6 'E' bookmarks:
  |
  | o  3: 67a385d4e6f2 'D' bookmarks: Z
  | |
  | o  2: 49cb3485fa0c 'C' bookmarks: Y
  | |
  | o  1: 6c81ed0049f8 'B' bookmarks: X
  |/
  o  0: 1994f17a630e 'A' bookmarks:
  
  $ hg rebase -s 1 -d 5
  rebasing 1:6c81ed0049f8 X "B"
  rebasing 2:49cb3485fa0c Y "C"
  rebasing 3:67a385d4e6f2 Z "D"
  merging d
  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
  unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
  [240]
  $ hg rebase --stop
  1 new orphan changesets
  $ hg log -GT "{rev}: {node|short} '{desc}' bookmarks: {bookmarks}\n"
  o  7: 9c86c650b686 'C' bookmarks: Y
  |
  o  6: 9b87b54e5fd8 'B' bookmarks: X
  |
  @  5: 39adf30bc1be 'conflict with d' bookmarks:
  |
  o  4: 9c1e55f411b6 'E' bookmarks:
  |
  | *  3: 67a385d4e6f2 'D' bookmarks: Z
  | |
  | x  2: 49cb3485fa0c 'C' bookmarks:
  | |
  | x  1: 6c81ed0049f8 'B' bookmarks:
  |/
  o  0: 1994f17a630e 'A' bookmarks: