topic: suggest to clear a topic that becomes empty
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 23 May 2018 12:16:24 +0200
changeset 3770 eb928f5728c4
parent 3769 1bc4b0807c37
child 3771 1f339d81aabd
topic: suggest to clear a topic that becomes empty We add a hint suggesting "hg topic --clear" when a topic becomes empty. This usually happens when all its changesets get public, that is when the user does a 'phase -p' or when they pull from a server. To discriminate relevant cases for which we should display the hint (and typically exclude explicit 'hg topic --clear' operation), we look for the transaction "type" to only consider 'phase' or 'push' transaction. In the latter case, the transaction name is not simply 'push-response' but it also included the remote URL so we need to match on string content.
hgext3rd/topic/__init__.py
tests/test-topic-flow-publish-flag.t
tests/test-topic-mode.t
tests/test-topic-stack.t
tests/test-topic-tutorial.t
tests/test-topic.t
--- a/hgext3rd/topic/__init__.py	Wed May 23 11:37:37 2018 +0200
+++ b/hgext3rd/topic/__init__.py	Wed May 23 12:16:24 2018 +0200
@@ -487,6 +487,9 @@
                 empty = csetcount == 0
                 if empty and not ctwasempty:
                     ui.status('active topic %r is now empty\n' % ct)
+                    if ('phase' in tr.names
+                            or any(n.startswith('push-response') for n in tr.names)):
+                        ui.status(_("(use 'hg topic --clear' to clear it if needed)\n"))
                 hint = _("(see 'hg help topics' for more information)\n")
                 if ctwasempty and not empty:
                     if csetcount == 1:
--- a/tests/test-topic-flow-publish-flag.t	Wed May 23 11:37:37 2018 +0200
+++ b/tests/test-topic-flow-publish-flag.t	Wed May 23 12:16:24 2018 +0200
@@ -300,6 +300,7 @@
   adding file changes
   added 1 changesets with 1 changes to 1 files
   active topic 'topic_A' is now empty
+  (use 'hg topic --clear' to clear it if needed)
   $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
   @  11:d06fc4f891e8 c_dK0 public default
   |
--- a/tests/test-topic-mode.t	Wed May 23 11:37:37 2018 +0200
+++ b/tests/test-topic-mode.t	Wed May 23 12:16:24 2018 +0200
@@ -244,6 +244,7 @@
 
   $ hg phase --public -r .
   active topic 'various-dove' is now empty
+  (use 'hg topic --clear' to clear it if needed)
   $ hg up default
   clearing empty topic "various-dove"
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -307,6 +308,7 @@
 
   $ hg phase --public -r .
   active topic 'various-dove' is now empty
+  (use 'hg topic --clear' to clear it if needed)
   $ hg up default
   clearing empty topic "various-dove"
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
--- a/tests/test-topic-stack.t	Wed May 23 11:37:37 2018 +0200
+++ b/tests/test-topic-stack.t	Wed May 23 12:16:24 2018 +0200
@@ -64,6 +64,7 @@
   t1: c_a
   $ hg phase --public 'topic("other")'
   active topic 'other' is now empty
+  (use 'hg topic --clear' to clear it if needed)
 
 After changing the phase of all the changesets in "other" to public, the topic should still be active, but is empty. We should be better at informating the user about it and displaying good data in this case.
 
--- a/tests/test-topic-tutorial.t	Wed May 23 11:37:37 2018 +0200
+++ b/tests/test-topic-tutorial.t	Wed May 23 12:16:24 2018 +0200
@@ -602,6 +602,7 @@
   added 2 changesets with 2 changes to 1 files
   2 new obsolescence markers
   active topic 'food' is now empty
+  (use 'hg topic --clear' to clear it if needed)
 
   $ hg topics
    * food (0 changesets)
--- a/tests/test-topic.t	Wed May 23 11:37:37 2018 +0200
+++ b/tests/test-topic.t	Wed May 23 12:16:24 2018 +0200
@@ -535,6 +535,7 @@
   tip
   $ hg phase --public narf
   active topic 'narf' is now empty
+  (use 'hg topic --clear' to clear it if needed)
 
 POSSIBLE BUG: narf topic stays alive even though we just made all
 narf commits public: