evolve: move _orderrevs() function evolvecmd.py
_orderrevs() is a function which is used to order the revs in which the
instability needs to be solved if we have multiple revisions to resolve.
Testscriptbasedonsharing.rst:ensurethatallscenariosinthatdocumentworkasadvertised.Settingthingsup$cat>>$HGRCPATH<<EOF>[alias]>shortlog=log--template'{rev}:{node|short}{phase}{desc|firstline}\n'>[extensions]>rebase=>EOF$echo"evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/">>$HGRCPATH$hginitpublic$hgclonepublictest-repoupdatingtobranchdefault0filesupdated,0filesmerged,0filesremoved,0filesunresolved$hgclonetest-repodev-repoupdatingtobranchdefault0filesupdated,0filesmerged,0filesremoved,0filesunresolved$cat>>test-repo/.hg/hgrc<<EOF>[phases]>publish=false>EOFTostartthingsoff,let's make one public, immutable changeset:: $ cd test-repo $ echo 'mynewproject' > file1 $ hg add file1 $ hg commit -m'createnewproject' $ hg push pushing to $TESTTMP/public (glob) searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 filesand pull that into the development repository:: $ cd ../dev-repo $ hg pull -u pulling from $TESTTMP/test-repo (glob) requesting all changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files new changesets 0dc9c9f6ab91 1 files updated, 0 files merged, 0 files removed, 0 files unresolvedLet'scommitapreliminarychangeandpushitto``test-repo``fortesting.::$echo'fix fix fix'>file1$hgcommit-m'prelim change'$hgpush-q../test-repoFigureSG01(roughly)$hgshortlog-G@1:f6490818a721draftprelimchange|o0:0dc9c9f6ab91publiccreatenewprojectNowlet's switch to test-repo to test our change and amend:: $ cd ../test-repo $ hg update -q $ echo 'Fixfixfix.' > file1 $ hg amend -m'fixbug37'Figure SG02 $ hg shortlog --hidden -G @ 2:60ffde5765c5 draft fix bug 37 | | x 1:f6490818a721 draft prelim change |/ o 0:0dc9c9f6ab91 public create new projectPull into dev-repo: obsolescence markers are transferred, but notthe new obsolete changeset. $ cd ../dev-repo $ hg pull -u pulling from $TESTTMP/test-repo (glob) searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (+1 heads) 1 new obsolescence markers obsoleted 1 changesets new changesets 60ffde5765c5 1 files updated, 0 files merged, 0 files removed, 0 files unresolved updated to "60ffde5765c5: fix bug 37" 1 other heads for branch "default"Figure SG03 $ hg shortlog --hidden -G @ 2:60ffde5765c5 draft fix bug 37 | | x 1:f6490818a721 draft prelim change |/ o 0:0dc9c9f6ab91 public create new projectAmend again in dev-repo $ echo 'Fix,fix,andfix.' > file1 $ hg amend $ hg push -qFigure SG04 (dev-repo) $ hg shortlog --hidden -G @ 3:de6151c48e1c draft fix bug 37 | | x 2:60ffde5765c5 draft fix bug 37 |/ | x 1:f6490818a721 draft prelim change |/ o 0:0dc9c9f6ab91 public create new projectFigure SG04 (test-repo) $ cd ../test-repo $ hg update 1 files updated, 0 files merged, 0 files removed, 0 files unresolved updated to "de6151c48e1c: fix bug 37" 1 other heads for branch "default" $ hg shortlog --hidden -G @ 3:de6151c48e1c draft fix bug 37 | | x 2:60ffde5765c5 draft fix bug 37 |/ | x 1:f6490818a721 draft prelim change |/ o 0:0dc9c9f6ab91 public create new projectThis bug fix is finished. We can push it to the public repository. $ hg push pushing to $TESTTMP/public (glob) searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files 2 new obsolescence markersNow that the fix is public, we cannot amend it any more. $ hg amend -m 'fixbug37' abort: cannot amend public changesets: de6151c48e1c (see 'hghelpphases' for details) [255]Figure SG05 $ hg -R ../public shortlog -G o 1:de6151c48e1c public fix bug 37 | o 0:0dc9c9f6ab91 public create new projectOops, still have draft changesets in dev-repo: push the phase change there. $ hg -R ../dev-repo shortlog -r 'draft()' 3:de6151c48e1c draft fix bug 37 $ hg push ../dev-repo pushing to ../dev-repo searching for changes no changes found [1] $ hg -R ../dev-repo shortlog -r 'draft()'Sharing with multiple developers: code review $ cd .. $ hg clone public review updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg clone review alice updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg clone review bob updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cat >> review/.hg/hgrc <<EOF>[phases]>publish=false>EOFAlicecommitsadraftbugfix,pushestoreviewrepo.$cdalice$hgbookmarkbug15$echo'fix'>file2$hgcommit-A-ualice-m'fix bug 15 (v1)'addingfile2$hgpush-Bbug15pushingto$TESTTMP/review(glob)searchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1filesexportingbookmarkbug15$hg-R../reviewbookmarksbug152:f91e97234c2bAlicereceivescodereview,amendsherfix,andgoesouttolunchtoawaitsecondreview.$echo'Fix.'>file2$hgamend-m'fix bug 15 (v2)'$hgpushpushingto$TESTTMP/review(glob)searchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files(+1heads)1newobsolescencemarkersobsoleted1changesetsupdatingbookmarkbug15$hg-R../reviewbookmarksbug153:cbdfbd5a5db2FigureSG06:reviewrepositoryafterAlicepushesheramendedchangeset.$hg--hidden-R../reviewshortlog-G-r1::o3:cbdfbd5a5db2draftfixbug15(v2)||x2:f91e97234c2bdraftfixbug15(v1)|/@1:de6151c48e1cpublicfixbug37|~Bobcommitsadraftchangeset,pushestoreviewrepo.$cd../bob$echo'stuff'>file1$hgbookmarkfeatureX$hgcommit-ubob-m'implement feature X (v1)'$hgpush-BfeatureXpushingto$TESTTMP/review(glob)searchingforchangesremotehasheadsonbranch'default'thatarenotknownlocally:cbdfbd5a5db2addingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files(+1heads)exportingbookmarkfeatureX$hg-R../reviewbookmarksbug153:cbdfbd5a5db2featureX4:193657d1e852Bobreceivesfirstreview,amendsandpushes.$echo'do stuff'>file1$hgamend-m'implement feature X (v2)'$hgpushpushingto$TESTTMP/review(glob)searchingforchangesremotehasheadsonbranch'default'thatarenotknownlocally:cbdfbd5a5db2addingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files(+1heads)1newobsolescencemarkersobsoleted1changesetsupdatingbookmarkfeatureXBobreceivessecondreview,amends,andpushestopublic:thistime,he's sure he got it right! $ echo 'Dostuff.' > file1 $ hg amend -m 'implementfeatureX(v3)' $ hg push ../public pushing to ../public searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files 2 new obsolescence markers $ hg -R ../public bookmarks no bookmarks set $ hg push ../review pushing to ../review searching for changes remote has heads on branch 'default' that are not known locally: cbdfbd5a5db2 adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (+1 heads) 1 new obsolescence markers obsoleted 1 changesets updating bookmark featureX $ hg -R ../review bookmarks bug15 3:cbdfbd5a5db2 featureX 6:540ba8f317e6Figure SG07: review and public repos after Bob implements feature X. $ hg --hidden -R ../review shortlog -G -r 1:: o 6:540ba8f317e6 public implement feature X (v3) | | x 5:0eb74a7b6698 draft implement feature X (v2) |/ | x 4:193657d1e852 draft implement feature X (v1) |/ | o 3:cbdfbd5a5db2 draft fix bug 15 (v2) |/ | x 2:f91e97234c2b draft fix bug 15 (v1) |/ @ 1:de6151c48e1c public fix bug 37 | ~ $ hg --hidden -R ../public shortlog -G -r 1:: o 2:540ba8f317e6 public implement feature X (v3) | o 1:de6151c48e1c public fix bug 37 | ~How do things look in the review repo? $ cd ../review $ hg --hidden shortlog -G -r 1:: o 6:540ba8f317e6 public implement feature X (v3) | | x 5:0eb74a7b6698 draft implement feature X (v2) |/ | x 4:193657d1e852 draft implement feature X (v1) |/ | o 3:cbdfbd5a5db2 draft fix bug 15 (v2) |/ | x 2:f91e97234c2b draft fix bug 15 (v1) |/ @ 1:de6151c48e1c public fix bug 37 | ~Meantime, Alice is back from lunch. While she was away, Bob approvedher change, so now she can publish it. $ cd ../alice $ hg --hidden shortlog -G -r 1:: @ 3:cbdfbd5a5db2 draft fix bug 15 (v2) | | x 2:f91e97234c2b draft fix bug 15 (v1) |/ o 1:de6151c48e1c public fix bug 37 | ~ $ hg outgoing -q ../public 3:cbdfbd5a5db2 $ hg push ../public pushing to ../public searching for changes remote has heads on branch 'default' that are not known locally: 540ba8f317e6 abort: push creates new remote head cbdfbd5a5db2 with bookmark 'bug15'! (pull and merge or see 'hghelppush' for details about pushing new heads) [255] $ hg pull ../public pulling from ../public searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (+1 heads) 2 new obsolescence markers new changesets 540ba8f317e6 (run 'hgheads' to see heads, 'hgmerge' to merge) $ hg log -G -q -r 'head()' o 4:540ba8f317e6 | ~ @ 3:cbdfbd5a5db2 | ~ $ hg --hidden shortlog -G -r 1:: o 4:540ba8f317e6 public implement feature X (v3) | | @ 3:cbdfbd5a5db2 draft fix bug 15 (v2) |/ | x 2:f91e97234c2b draft fix bug 15 (v1) |/ o 1:de6151c48e1c public fix bug 37 | ~Alice rebases her draft changeset on top of Bob'spublicchangesetandpublishestheresult.$hgrebase-d5rebasing3:cbdfbd5a5db2"fix bug 15 (v2)"(bug15)$hgpush../publicpushingto../publicsearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files2newobsolescencemarkers$hgpush../reviewpushingto../reviewsearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith0changesto1files1newobsolescencemarkersobsoleted1changesetsupdatingbookmarkbug15FigureSG08:reviewandpublicchangesetsafterAlicepushes.$hg--hidden-R../reviewshortlog-G-r1::o7:a06ec1bf97bdpublicfixbug15(v2)|o6:540ba8f317e6publicimplementfeatureX(v3)||x5:0eb74a7b6698draftimplementfeatureX(v2)|/|x4:193657d1e852draftimplementfeatureX(v1)|/|x3:cbdfbd5a5db2draftfixbug15(v2)|/|x2:f91e97234c2bdraftfixbug15(v1)|/@1:de6151c48e1cpublicfixbug37|~$hg--hidden-R../publicshortlog-G-r1::o3:a06ec1bf97bdpublicfixbug15(v2)|o2:540ba8f317e6publicimplementfeatureX(v3)|o1:de6151c48e1cpublicfixbug37|~$cd..Setupfor"cowboy mode"sharedmutablehistory(toillustratedivergentandbumpedchangesets).$rm-rfreviewalicebob$hgclonepublicaliceupdatingtobranchdefault2filesupdated,0filesmerged,0filesremoved,0filesunresolved$hgclonepublicbobupdatingtobranchdefault2filesupdated,0filesmerged,0filesremoved,0filesunresolved$cat>> alice/.hg/hgrc <<EOF>[phases]>publish=false>EOF$cpalice/.hg/hgrcbob/.hg/hgrcNowwe'll have Bob commit a bug fix that could still be improved:: $ cd bob $ echo 'prettygoodfix' >> file1 $ hg commit -u bob -m 'fixbug24(v1)' $ hg shortlog -r . 4:2fe6c4bd32d0 draft fix bug 24 (v1)Since Alice and Bob are now in cowboy mode, Alice pulls Bob'sdraftchangesetandamendsitherself.::$cd../alice$hgpull-u../bobpullingfrom../bobsearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1filesnewchangesets2fe6c4bd32d01filesupdated,0filesmerged,0filesremoved,0filesunresolved$echo'better fix (alice)'>> file1 $ hg amend -u alice -m 'fixbug24(v2byalice)'Bob implements a better fix of his own:: $ cd ../bob $ echo 'betterfix(bob)' >> file1 $ hg amend -u bob -m 'fixbug24(v2bybob)' $ hg --hidden shortlog -G -r 3:: @ 5:a360947f6faf draft fix bug 24 (v2 by bob) | | x 4:2fe6c4bd32d0 draft fix bug 24 (v1) |/ o 3:a06ec1bf97bd public fix bug 15 (v2) | ~Bob discovers the divergence. $ hg pull ../alice pulling from ../alice searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (+1 heads) 1 new obsolescence markers 2 new content-divergent changesets new changesets e3f99ce9d9cd (run 'hgheads' to see heads, 'hgmerge' to merge)Figure SG09: multiple heads! divergence! oh my! $ hg --hidden shortlog -G -r 3:: * 6:e3f99ce9d9cd draft fix bug 24 (v2 by alice) | | @ 5:a360947f6faf draft fix bug 24 (v2 by bob) |/ | x 4:2fe6c4bd32d0 draft fix bug 24 (v1) |/ o 3:a06ec1bf97bd public fix bug 15 (v2) | ~ $ hg --hidden shortlog -r 'successors(2fe6)' 5:a360947f6faf draft fix bug 24 (v2 by bob) 6:e3f99ce9d9cd draft fix bug 24 (v2 by alice)Use evolve to fix the divergence. $ HGMERGE=internal:other hg evolve --content-divergent merge:[5] fix bug 24 (v2 by bob) with: [6] fix bug 24 (v2 by alice) base: [4] fix bug 24 (v1) 0 files updated, 1 files merged, 0 files removed, 0 files unresolved working directory is now at 5ad6037c046c $ hg log -q -r 'contentdivergent()'Figure SG10: Bob'srepositoryafterfixingdivergence.$hg--hiddenshortlog-G-r3::@7:5ad6037c046cdraftfixbug24(v2bybob)||x6:e3f99ce9d9cddraftfixbug24(v2byalice)|/|x5:a360947f6fafdraftfixbug24(v2bybob)|/|x4:2fe6c4bd32d0draftfixbug24(v1)|/o3:a06ec1bf97bdpublicfixbug15(v2)|~$hg--hiddenshortlog-r'precursors(5ad6037c046c)'5:a360947f6fafdraftfixbug24(v2bybob)6:e3f99ce9d9cddraftfixbug24(v2byalice)$catfile1Dostuff.prettygoodfixbetterfix(alice)