diff hgext3rd/topic/__init__.py @ 2986:4746b92cc1f8

topics/ui: signal when an operation entails voiding a topic Typical situations may include: * publish * push (to publishing server) * pull * fold
author Aurélien Campéas
date Fri, 22 Sep 2017 16:41:37 +0200
parents f63c97c01f92
children d59d6413bb68 53246d237373
line wrap: on
line diff
--- 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'):