Source

thg-qt-mq / move.diff

# HG changeset patch
# Parent b0d15930286f5f16bfa5af098ba4eff1984d6463
docklog: change _commandComplete() to a free function

It does not depend on self.

diff --git a/tortoisehg/hgqt/docklog.py b/tortoisehg/hgqt/docklog.py
--- a/tortoisehg/hgqt/docklog.py
+++ b/tortoisehg/hgqt/docklog.py
@@ -238,6 +238,57 @@ def _searchhistory(items, text, directio
         idx += direction
     return None, idx
 
+def _findsubcommands(cmdtype, cmdline):
+    matches = []
+    cmd = cmdline.split()
+    if cmdtype == 'hg':
+        cmdtable = commands.table
+    else:
+        cmdtable = run.table
+    subcmd = ''
+    if len(cmd) >= 2:
+        subcmd = cmd[1].lower()
+    def findhgcmd(cmdstart):
+        matchinfo = {}
+        for cmdspec in cmdtable:
+            for cmdname in cmdspec.split('|'):
+                if cmdname[0] == '^':
+                    cmdname = cmdname[1:]
+                if cmdname.startswith(cmdstart):
+                    matchinfo[cmdname] = cmdspec
+        return matchinfo
+    matchingcmds = findhgcmd(subcmd)
+    if not matchingcmds:
+        return matches
+    if len(matchingcmds) > 1:
+        basecmdline = '%s %%s' % (cmdtype)
+        matches = [basecmdline % c for c in matchingcmds]
+    else:
+        scmdtype = matchingcmds.keys()[0]
+        cmdspec = matchingcmds[scmdtype]
+        opts = cmdtable[cmdspec][1]
+        def findcmdopt(cmdopt):
+            cmdopt = cmdopt.lower()
+            while(cmdopt.startswith('-')):
+                cmdopt = cmdopt[1:]
+            matchingopts = []
+            for opt in opts:
+                if opt[1].startswith(cmdopt):
+                    matchingopts.append(opt)
+            return matchingopts
+        basecmdline = '%s %s --%%s' % (cmdtype, scmdtype)
+        if len(cmd) == 2:
+            matches = ['%s %s ' % (cmdtype, scmdtype)]
+            matches += [basecmdline % opt[1] for opt in opts]
+        else:
+            cmdopt = cmd[-1]
+            if cmdopt.startswith('-'):
+                # find the matching options
+                basecmdline = ' '.join(cmd[:-1]) + ' --%s'
+                cmdopts = findcmdopt(cmdopt)
+                matches = [basecmdline % opt[1] for opt in cmdopts]
+    return sorted(matches)
+
 class _ConsoleCmdTable(dict):
     """Command table for ConsoleWidget"""
     _cmdfuncprefix = '_cmd_'
@@ -294,57 +345,6 @@ class ConsoleWidget(QWidget):
         else:
             self._logwidget.flash()
 
-    def _commandComplete(self, cmdtype, cmdline):
-        matches = []
-        cmd = cmdline.split()
-        if cmdtype == 'hg':
-            cmdtable = commands.table
-        else:
-            cmdtable = run.table
-        subcmd = ''
-        if len(cmd) >= 2:
-            subcmd = cmd[1].lower()
-        def findhgcmd(cmdstart):
-            matchinfo = {}
-            for cmdspec in cmdtable:
-                for cmdname in cmdspec.split('|'):
-                    if cmdname[0] == '^':
-                        cmdname = cmdname[1:]
-                    if cmdname.startswith(cmdstart):
-                        matchinfo[cmdname] = cmdspec
-            return matchinfo
-        matchingcmds = findhgcmd(subcmd)
-        if not matchingcmds:
-            return matches
-        if len(matchingcmds) > 1:
-            basecmdline = '%s %%s' % (cmdtype)
-            matches = [basecmdline % c for c in matchingcmds]
-        else:
-            scmdtype = matchingcmds.keys()[0]
-            cmdspec = matchingcmds[scmdtype]
-            opts = cmdtable[cmdspec][1]
-            def findcmdopt(cmdopt):
-                cmdopt = cmdopt.lower()
-                while(cmdopt.startswith('-')):
-                    cmdopt = cmdopt[1:]
-                matchingopts = []
-                for opt in opts:
-                    if opt[1].startswith(cmdopt):
-                        matchingopts.append(opt)
-                return matchingopts
-            basecmdline = '%s %s --%%s' % (cmdtype, scmdtype)
-            if len(cmd) == 2:
-                matches = ['%s %s ' % (cmdtype, scmdtype)]
-                matches += [basecmdline % opt[1] for opt in opts]
-            else:
-                cmdopt = cmd[-1]
-                if cmdopt.startswith('-'):
-                    # find the matching options
-                    basecmdline = ' '.join(cmd[:-1]) + ' --%s'
-                    cmdopts = findcmdopt(cmdopt)
-                    matches = [basecmdline % opt[1] for opt in cmdopts]
-        return sorted(matches)
-
     @pyqtSlot(unicode)
     def completeCommandText(self, text):
         """Show the list of history or known commands matching the search text
@@ -367,7 +367,7 @@ class ConsoleWidget(QWidget):
         cmd = text.split()
         cmdtype = cmd[0].lower()
         if cmdtype in ('hg', 'thg'):
-            hgcommandmatches = self._commandComplete(cmdtype, text)
+            hgcommandmatches = _findsubcommands(cmdtype, text)
             if hgcommandmatches:
                 if not commonprefix:
                     commonprefix = os.path.commonprefix(hgcommandmatches)