changeset 2662:9c0b293c2785

topics: move the logic to change or clear current topic into a new function It adds a new _changecurrenttopic which changes or clears the current topic.
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 25 Jun 2017 06:47:59 +0530
parents 914757c70217
children c01dc624b358
files hgext3rd/topic/__init__.py
diffstat 1 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Mon Jun 26 17:20:17 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Sun Jun 25 06:47:59 2017 +0530
@@ -288,14 +288,11 @@
             raise error.Abort("can't change topic of a public change")
         _changetopics(ui, repo, rev, topic)
     if clear:
-        if repo.vfs.exists('topic'):
-            repo.vfs.unlink('topic')
-        return
+        return _changecurrenttopic(repo, None)
+
     if topic:
-        with repo.wlock():
-            with repo.vfs.open('topic', 'w') as f:
-                f.write(topic)
-        return
+        return _changecurrenttopic(repo, topic)
+
     _listtopics(ui, repo, opts)
 
 @command('stack [TOPIC]', [] + commands.formatteropts)
@@ -309,6 +306,17 @@
         raise error.Abort(_('no active topic to list'))
     return stack.showstack(ui, repo, topic, opts)
 
+def _changecurrenttopic(repo, newtopic):
+    """changes the current topic."""
+
+    if newtopic:
+        with repo.wlock():
+            with repo.vfs.open('topic', 'w') as f:
+                f.write(newtopic)
+    else:
+        if repo.vfs.exists('topic'):
+            repo.vfs.unlink('topic')
+
 def _changetopics(ui, repo, revset, newtopic):
     rewrote = 0
     needevolve = False