topics/ui: signal when an operation entails voiding a topic
authorAurélien Campéas
Fri, 22 Sep 2017 16:41:37 +0200
changeset 2986 4746b92cc1f8
parent 2985 f63c97c01f92
child 2987 d59d6413bb68
child 2989 53246d237373
topics/ui: signal when an operation entails voiding a topic Typical situations may include: * publish * push (to publishing server) * pull * fold
hgext3rd/topic/__init__.py
tests/test-topic-fold.t
tests/test-topic-stack.t
tests/test-topic-tutorial.t
tests/test-topic.t
--- a/hgext3rd/topic/__init__.py	Tue Sep 26 12:29:15 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Sep 22 16:41:37 2017 +0200
@@ -54,6 +54,7 @@
 
 import re
 import time
+import weakref
 
 from mercurial.i18n import _
 from mercurial import (
@@ -311,6 +312,24 @@
                 peer.__class__ = topicpeer
             return peer
 
+        def transaction(self, *a, **k):
+            tr = super(topicrepo, self).transaction(*a, **k)
+
+            reporef = weakref.ref(self)
+
+            def currenttopicempty(tr):
+                # check active topic emptyness
+                ct = self.currenttopic
+                if not ct:
+                    return
+                repo = reporef()
+                empty = stack.stackdata(repo, topic=ct)['changesetcount'] == 0
+                if empty:
+                    ui.status('active topic %r is now empty\n' % ct)
+
+            tr.addpostclose('signalcurrenttopicempty', currenttopicempty)
+            return tr
+
     repo.__class__ = topicrepo
     repo._topics = None
     if util.safehasattr(repo, 'names'):
--- a/tests/test-topic-fold.t	Tue Sep 26 12:29:15 2017 +0200
+++ b/tests/test-topic-fold.t	Fri Sep 22 16:41:37 2017 +0200
@@ -90,6 +90,7 @@
   o  0:3e7df3b3b17c6deb4a1c70e790782fdf17af96a7
      topics:
   $ hg fold --exact -r "(tip~1)::" -m "folded 2"
+  active topic 'myotherfeature' is now empty
   2 changesets folded
   clearing empty topic "myotherfeature"
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
--- a/tests/test-topic-stack.t	Tue Sep 26 12:29:15 2017 +0200
+++ b/tests/test-topic-stack.t	Fri Sep 22 16:41:37 2017 +0200
@@ -59,6 +59,7 @@
   t2@ c_b (current)
   t1: c_a
   $ hg phase --public 'topic("other")'
+  active topic 'other' is now empty
 
 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	Tue Sep 26 12:29:15 2017 +0200
+++ b/tests/test-topic-tutorial.t	Fri Sep 22 16:41:37 2017 +0200
@@ -584,6 +584,7 @@
   adding file changes
   added 2 changesets with 2 changes to 1 files
   2 new obsolescence markers
+  active topic 'food' is now empty
 
   $ hg topics
    * food
--- a/tests/test-topic.t	Tue Sep 26 12:29:15 2017 +0200
+++ b/tests/test-topic.t	Fri Sep 22 16:41:37 2017 +0200
@@ -401,6 +401,7 @@
   query
   tip
   $ hg phase --public narf
+  active topic 'narf' is now empty
 
 POSSIBLE BUG: narf topic stays alive even though we just made all
 narf commits public:
@@ -461,6 +462,7 @@
   adding manifests
   adding file changes
   added 3 changesets with 3 changes to 1 files
+  active topic 'query' is now empty
   (run 'hg update' to get a working copy)
   $ hg topics
    * query
@@ -474,6 +476,7 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
+  active topic 'query' is now empty
   (run 'hg heads' to see heads)
   $ hg topics
      fran