Commits

Yuya Nishihara committed f310b2e

mq: split core functions to mqutil in order to avoid circular import

The original code has circular import path, commit -> mq -> thgimport
-> commit.

  • Participants
  • Parent commits 51cabf0

Comments (0)

Files changed (3)

File tortoisehg/hgqt/commit.py

 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt.messageentry import MessageEntry
 from tortoisehg.hgqt import qtlib, qscilib, status, cmdui, branchop, revpanel
-from tortoisehg.hgqt import hgrcutil, mq, lfprompt, i18n
+from tortoisehg.hgqt import hgrcutil, mqutil, lfprompt, i18n
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
             pnhbox = QHBoxLayout()
             self.pnlabel = QLabel()
             pnhbox.addWidget(self.pnlabel)
-            self.pnedit = mq.getPatchNameLineEdit()
+            self.pnedit = mqutil.getPatchNameLineEdit()
             self.pnedit.setMaximumWidth(250)
             pnhbox.addWidget(self.pnedit)
             pnhbox.addStretch()
             self.pnlabel.setVisible(True)
             self.pnedit.setVisible(True)
             self.pnedit.setFocus()
-            self.pnedit.setText(mq.defaultNewPatchName(self.repo))
+            self.pnedit.setText(mqutil.defaultNewPatchName(self.repo))
             self.pnedit.selectAll()
             self.stwidget.setPatchContext(None)
             refreshwctx = refresh and oldpctx is not None
             wholecmdlines.extend(cmdlines)
 
         olist = ('user', 'date')
-        cmdlines = mq.mqNewRefreshCommand(self.repo,
-                                          curraction._name == 'qnew',
-                                          self.stwidget, self.pnedit,
-                                          self.msgte.text(), self.opts, olist)
+        cmdlines = mqutil.mqNewRefreshCommand(self.repo,
+                                              curraction._name == 'qnew',
+                                              self.stwidget, self.pnedit,
+                                              self.msgte.text(), self.opts,
+                                              olist)
         if not cmdlines:
             return
         wholecmdlines.extend(cmdlines)

File tortoisehg/hgqt/mq.py

 
 import os
 import re
-import time
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 from tortoisehg.util import hglib
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import qtlib, cmdui, rejects, qscilib, thgrepo, status
-from tortoisehg.hgqt import qqueue, qreorder, thgimport, messageentry
+from tortoisehg.hgqt import qqueue, qreorder, thgimport, messageentry, mqutil
 from tortoisehg.hgqt.qtlib import geticon
 
 # TODO
 # keep original file name in file list item
 # more wctx functions
 
-def defaultNewPatchName(repo):
-    t = time.strftime('%Y-%m-%d_%H-%M-%S')
-    return t + '_r%d+.diff' % repo['.'].rev()
-
-def getPatchNameLineEdit():
-    patchNameLE = QLineEdit()
-    if hasattr(patchNameLE, 'setPlaceholderText'): # Qt >= 4.7
-        patchNameLE.setPlaceholderText(_('### patch name ###'))
-    return patchNameLE
-
-def getUserOptions(opts, *optionlist):
-    out = []
-    for opt in optionlist:
-        if opt not in opts:
-            continue
-        val = opts[opt]
-        if val is False:
-            continue
-        elif val is True:
-            out.append('--' + opt)
-        else:
-            out.append('--' + opt)
-            out.append(val)
-    return out
-
-def mqNewRefreshCommand(repo, isnew, stwidget, pnwidget, message, opts, olist):
-    if isnew:
-        name = hglib.fromunicode(pnwidget.text())
-        if not name:
-            qtlib.ErrorMsgBox(_('Patch Name Required'),
-                              _('You must enter a patch name'))
-            pnwidget.setFocus()
-            return
-        cmdline = ['qnew', '--repository', repo.root, name]
-    else:
-        cmdline = ['qrefresh', '--repository', repo.root]
-    if message:
-        cmdline += ['--message=' + hglib.fromunicode(message)]
-    cmdline += getUserOptions(opts, *olist)
-    files = ['--'] + [repo.wjoin(x) for x in stwidget.getChecked()]
-    addrem = [repo.wjoin(x) for x in stwidget.getChecked('!?')]
-    if len(files) > 1:
-        cmdline += files
-    else:
-        cmdline += ['--exclude', repo.root]
-    if addrem:
-        cmdlines = [ ['addremove', '-R', repo.root] + addrem, cmdline]
-    else:
-        cmdlines = [cmdline]
-    return cmdlines
-
 class MQPatchesWidget(QDockWidget):
     showMessage = pyqtSignal(unicode)
     output = pyqtSignal(QString, QString)
         layout.addLayout(mtbarhbox, 0)
         mtbarhbox.setContentsMargins(0, 0, 0, 0)
         self.newCheckBox = QCheckBox(_('New Patch'))
-        self.patchNameLE = getPatchNameLineEdit()
+        self.patchNameLE = mqutil.getPatchNameLineEdit()
         mtbarhbox.addWidget(self.newCheckBox)
         mtbarhbox.addWidget(self.patchNameLE, 1)
 
         super(MQWidget, self).closeEvent(event)
 
     def getUserOptions(self, *optionlist):
-        return getUserOptions(self.opts, *optionlist)
+        return mqutil.getUserOptions(self.opts, *optionlist)
 
     @pyqtSlot()
     def onConfigChanged(self):
         if self.newCheckBox.isChecked():
             self.finishfunc = lambda ret: self.newCheckBox.setChecked(False)
         optionlist = ('user', 'currentuser', 'git', 'date', 'currentdate')
-        cmdlines = mqNewRefreshCommand(self.repo, self.newCheckBox.isChecked(),
-                                       self.stwidget, self.patchNameLE,
-                                       self.messageEditor.text(), self.opts,
-                                       optionlist)
+        cmdlines = mqutil.mqNewRefreshCommand(self.repo, self.newCheckBox.isChecked(),
+                                              self.stwidget, self.patchNameLE,
+                                              self.messageEditor.text(), self.opts,
+                                              optionlist)
         self.repo.incrementBusyCount()
         self.cmd.run(*cmdlines)
 
             self.messageEditor.setEnabled(True)
             self.patchNameLE.setEnabled(True)
             self.patchNameLE.setFocus()
-            self.patchNameLE.setText(defaultNewPatchName(self.repo))
+            self.patchNameLE.setText(mqutil.defaultNewPatchName(self.repo))
             self.patchNameLE.selectAll()
             self.setMessage('')
         else:

File tortoisehg/hgqt/mqutil.py

+# mqutil.py - Common functionality for TortoiseHg MQ widget
+#
+# Copyright 2011 Steve Borho <steve@borho.org>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+import time
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+from tortoisehg.util import hglib
+from tortoisehg.hgqt.i18n import _
+from tortoisehg.hgqt import qtlib
+
+def defaultNewPatchName(repo):
+    t = time.strftime('%Y-%m-%d_%H-%M-%S')
+    return t + '_r%d+.diff' % repo['.'].rev()
+
+def getPatchNameLineEdit():
+    patchNameLE = QLineEdit()
+    if hasattr(patchNameLE, 'setPlaceholderText'): # Qt >= 4.7
+        patchNameLE.setPlaceholderText(_('### patch name ###'))
+    return patchNameLE
+
+def getUserOptions(opts, *optionlist):
+    out = []
+    for opt in optionlist:
+        if opt not in opts:
+            continue
+        val = opts[opt]
+        if val is False:
+            continue
+        elif val is True:
+            out.append('--' + opt)
+        else:
+            out.append('--' + opt)
+            out.append(val)
+    return out
+
+def mqNewRefreshCommand(repo, isnew, stwidget, pnwidget, message, opts, olist):
+    if isnew:
+        name = hglib.fromunicode(pnwidget.text())
+        if not name:
+            qtlib.ErrorMsgBox(_('Patch Name Required'),
+                              _('You must enter a patch name'))
+            pnwidget.setFocus()
+            return
+        cmdline = ['qnew', '--repository', repo.root, name]
+    else:
+        cmdline = ['qrefresh', '--repository', repo.root]
+    if message:
+        cmdline += ['--message=' + hglib.fromunicode(message)]
+    cmdline += getUserOptions(opts, *olist)
+    files = ['--'] + [repo.wjoin(x) for x in stwidget.getChecked()]
+    addrem = [repo.wjoin(x) for x in stwidget.getChecked('!?')]
+    if len(files) > 1:
+        cmdline += files
+    else:
+        cmdline += ['--exclude', repo.root]
+    if addrem:
+        cmdlines = [ ['addremove', '-R', repo.root] + addrem, cmdline]
+    else:
+        cmdlines = [cmdline]
+    return cmdlines