stack: add a very first version of stack display with 'hg topic --list'
This mark the first step toward a set of feature dedicated to displaying and
moving within the current stack of work. Everything is still super basic so
don't look too much at the feature.
The goals of this changeset are:
* having a flag to trigger the feature
* having a basic (imperfect selection mechanism)
--- a/src/topic/__init__.py Mon Mar 14 17:09:02 2016 +0000
+++ b/src/topic/__init__.py Mon Mar 14 17:37:39 2016 +0000
@@ -38,6 +38,7 @@
from . import constants
from . import revset as topicrevset
from . import destination
+from . import stack
from . import topicmap
from . import discovery
@@ -165,9 +166,15 @@
@command('topics [TOPIC]', [
('', 'clear', False, 'clear active topic if any'),
('', 'change', '', 'revset of existing revisions to change topic'),
+ ('l', 'list', False, 'show the stack of changeset in the topic'),
])
-def topics(ui, repo, topic='', clear=False, change=None):
+def topics(ui, repo, topic='', clear=False, change=None, list=False):
"""View current topic, set current topic, or see all topics."""
+ if list:
+ if clear or change:
+ raise error.Abort(_("cannot use --clear or --change with --list"))
+ return stack.showstack(ui, repo, topic)
+
if change:
if not obsolete.isenabled(repo, obsolete.createmarkersopt):
raise error.Abort(_('must have obsolete enabled to use --change'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/topic/stack.py Mon Mar 14 17:37:39 2016 +0000
@@ -0,0 +1,20 @@
+# stack.py - code related to stack workflow
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+from mercurial.i18n import _
+from mercurial import error
+
+def _getstack(repo, topic):
+ # XXX need to exclude obsolete changesets
+ # XXX need sorting
+ return repo.revs("topic(%s)", topic)
+
+def showstack(ui, repo, topic):
+ if not topic:
+ topic = repo.currenttopic
+ if not topic:
+ raise error.Abort(_('no active topic to list'))
+ for r in _getstack(repo, topic):
+ # super crude initial version
+ ui.write(repo[r].description().splitlines()[0] + '\n')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-topic-stack.t Mon Mar 14 17:37:39 2016 +0000
@@ -0,0 +1,68 @@
+ $ . "$TESTDIR/testlib"
+
+Initial setup
+
+
+ $ cat << EOF >> $HGRCPATH
+ > [ui]
+ > logtemplate = {rev} {branch} \{{get(namespaces, "topics")}} {phase} {desc|firstline}\n
+ > EOF
+
+(new head warning seems buggy)
+ $ hg init main
+ $ cd main
+ $ echo aaa > aaa
+ $ hg add aaa
+ $ hg commit -m c_a
+ $ echo aaa > bbb
+ $ hg add bbb
+ $ hg commit -m c_b
+ $ hg topic foo
+ $ echo aaa > ccc
+ $ hg add ccc
+ $ hg commit -m c_c
+ $ echo aaa > ddd
+ $ hg add ddd
+ $ hg commit -m c_d
+ created new head
+ $ echo aaa > eee
+ $ hg add eee
+ $ hg commit -m c_e
+ created new head
+ $ echo aaa > fff
+ $ hg add fff
+ $ hg commit -m c_f
+ created new head
+ $ hg log -G
+ @ 5 default {foo} draft c_f
+ |
+ o 4 default {foo} draft c_e
+ |
+ o 3 default {foo} draft c_d
+ |
+ o 2 default {foo} draft c_c
+ |
+ o 1 default {} draft c_b
+ |
+ o 0 default {} draft c_a
+
+
+Simple test
+-----------
+
+hg topic -l list all changeset in the topic
+
+ $ hg topic
+ * foo
+ $ hg topic --list
+ c_c
+ c_d
+ c_e
+ c_f
+
+error case, nothing to list
+
+ $ hg topic --clear
+ $ hg topic --list
+ abort: no active topic to list
+ [255]
--- a/tests/test-topic.t Mon Mar 14 17:09:02 2016 +0000
+++ b/tests/test-topic.t Mon Mar 14 17:37:39 2016 +0000
@@ -14,8 +14,9 @@
options:
- --clear clear active topic if any
- --change VALUE revset of existing revisions to change topic
+ --clear clear active topic if any
+ --change VALUE revset of existing revisions to change topic
+ -l --list show the stack of changeset in the topic
(some details hidden, use --verbose to show complete help)
$ hg topics