Patchwork [1,of,4,topic-experiment] topics: move the logic to change or clear current topic into a new function

login
register
mail settings
Submitter Pulkit Goyal
Date June 26, 2017, 8:28 a.m.
Message ID <bd206f38dda1391cb6e0.1498465730@workspace>
Download mbox | patch
Permalink /patch/21726/
State Accepted
Headers show

Comments

Pulkit Goyal - June 26, 2017, 8:28 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1498353479 -19800
#      Sun Jun 25 06:47:59 2017 +0530
# Node ID bd206f38dda1391cb6e0114d483c8f2fa00a9feb
# Parent  a51970c0749214d5d5662f15f818fefb2f0c100a
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.

Patch

diff --git a/hgext3rd/topic/__init__.py b/hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -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