# HG changeset patch # User Boris Feld # Date 1516379390 -3600 # Node ID 68fcc5503ec55bda2d6be2887f8fc3f61000c666 # Parent 2987726085c641f12a4fcef5594d516967c1a6e3 stack: return a sorted smartrev by default Most stack customers will display a list of revisions, sort it by default. Differential Revision: https://phab.mercurial-scm.org/D2399 diff -r 2987726085c6 -r 68fcc5503ec5 mercurial/destutil.py --- a/mercurial/destutil.py Fri Jan 19 17:09:24 2018 +0100 +++ b/mercurial/destutil.py Fri Jan 19 17:29:50 2018 +0100 @@ -359,7 +359,7 @@ def stackbase(ui, repo): revs = stack.getstack(repo) - return revs.last() if revs else None + return revs.first() if revs else None def _statusotherbook(ui, repo): bmheads = bookmarks.headsforactive(repo) diff -r 2987726085c6 -r 68fcc5503ec5 mercurial/stack.py --- a/mercurial/stack.py Fri Jan 19 17:09:24 2018 +0100 +++ b/mercurial/stack.py Fri Jan 19 17:29:50 2018 +0100 @@ -13,8 +13,8 @@ ) def getstack(repo, rev=None): - """return a smartrev of the stack containing either rev if it is not None - or the current working directory parent. + """return a sorted smartrev of the stack containing either rev if it is + not None or the current working directory parent. The stack will always contain all drafts changesets which are ancestors to the revision and are not merges. @@ -24,4 +24,6 @@ revspec = 'reverse(only(%s) and not public() and not ::merge())' revset = revsetlang.formatspec(revspec, rev) - return scmutil.revrange(repo, [revset]) + revisions = scmutil.revrange(repo, [revset]) + revisions.sort() + return revisions diff -r 2987726085c6 -r 68fcc5503ec5 tests/test-stack.t --- a/tests/test-stack.t Fri Jan 19 17:09:24 2018 +0100 +++ b/tests/test-stack.t Fri Jan 19 17:29:50 2018 +0100 @@ -205,13 +205,13 @@ ~ Check the stack order $ hg log -r "first(stack())" - 10 foo draft c_h + 9 foo draft c_g $ hg log -r "first(stack(10))" - 10 foo draft c_h + 9 foo draft c_g $ hg log -r "first(stack(8))" - 8 foo draft c_f + 7 foo draft c_e $ hg log -r "first(stack(head()))" - 8 foo draft c_f + 7 foo draft c_e Case with multiple heads with unstability involved --------------------------------------------------