1# stack.py - Mercurial functions for stack definition
2#
3#  Copyright Olivia Mackall <olivia@selenic.com> and other
4#
5# This software may be used and distributed according to the terms of the
6# GNU General Public License version 2 or any later version.
7
8from __future__ import absolute_import
9
10
11def getstack(repo, rev=None):
12    """return a sorted smartrev of the stack containing either rev if it is
13    not None or the current working directory parent.
14
15    The stack will always contain all drafts changesets which are ancestors to
16    the revision and are not merges.
17    """
18    if rev is None:
19        rev = b'.'
20
21    revspec = b'only(%s) and not public() and not ::merge()'
22    revisions = repo.revs(revspec, rev)
23    revisions.sort()
24    return revisions
25