eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7924
8a96736d465e
parent 7979
54b73174ab61
child 8176
31965986ecd1
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py	Sun Jan 17 13:53:08 2021 +0100
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py	Mon Feb 01 10:38:16 2021 +0100
@@ -7,8 +7,6 @@
 Module implementing the queues extension interface.
 """
 
-import os
-
 from PyQt5.QtWidgets import QDialog, QApplication, QInputDialog
 
 from E5Gui import E5MessageBox
@@ -71,11 +69,10 @@
         if self.queueStatusDialog is not None:
             self.queueStatusDialog.close()
     
-    def __getPatchesList(self, repodir, listType, withSummary=False):
+    def __getPatchesList(self, listType, withSummary=False):
         """
         Private method to get a list of patches of a given type.
         
-        @param repodir directory name of the repository (string)
         @param listType type of patches list to get
             (Queues.APPLIED_LIST, Queues.UNAPPLIED_LIST, Queues.SERIES_LIST)
         @param withSummary flag indicating to get a summary as well (boolean)
@@ -111,11 +108,10 @@
         
         return patchesList
     
-    def __getCurrentPatch(self, repodir):
+    def __getCurrentPatch(self):
         """
         Private method to get the name of the current patch.
         
-        @param repodir directory name of the repository (string)
         @return name of the current patch (string)
         """
         currentPatch = ""
@@ -127,11 +123,10 @@
         
         return currentPatch
     
-    def __getCommitMessage(self, repodir):
+    def __getCommitMessage(self):
         """
         Private method to get the commit message of the current patch.
         
-        @param repodir directory name of the repository (string)
         @return name of the current patch (string)
         """
         message = ""
@@ -143,11 +138,10 @@
         
         return message
     
-    def getGuardsList(self, repodir, allGuards=True):
+    def getGuardsList(self, allGuards=True):
         """
         Public method to get a list of all guards defined.
         
-        @param repodir directory name of the repository (string)
         @param allGuards flag indicating to get all guards (boolean)
         @return sorted list of guards (list of strings)
         """
@@ -169,19 +163,10 @@
         
         return sorted(guardsList)
     
-    def hgQueueNewPatch(self, name):
+    def hgQueueNewPatch(self):
         """
         Public method to create a new named patch.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog
         dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialog.NEW_MODE)
         if dlg.exec() == QDialog.Accepted:
@@ -208,30 +193,22 @@
             args.append(name)
             
             dia = HgDialog(self.tr('New Patch'), self.vcs)
-            res = dia.startProcess(args, repodir)
+            res = dia.startProcess(args)
             if res:
                 dia.exec()
                 self.vcs.checkVCSStatus()
     
-    def hgQueueRefreshPatch(self, name, editMessage=False):
+    def hgQueueRefreshPatch(self, editMessage=False):
         """
         Public method to refresh the current patch.
         
-        @param name file/directory name (string)
         @param editMessage flag indicating to edit the current
             commit message (boolean)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         args = self.vcs.initCommand("qrefresh")
         
         if editMessage:
-            currentMessage = self.__getCommitMessage(repodir)
+            currentMessage = self.__getCommitMessage()
             from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog
             dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialog.REFRESH_MODE,
                                          currentMessage)
@@ -258,7 +235,7 @@
                 return
         
         dia = HgDialog(self.tr('Update Current Patch'), self.vcs)
-        res = dia.startProcess(args, repodir)
+        res = dia.startProcess(args)
         if res:
             dia.exec()
             self.vcs.checkVCSStatus()
@@ -275,41 +252,31 @@
         QApplication.processEvents()
         self.qdiffDialog.start(name, qdiff=True)
     
-    def hgQueueShowHeader(self, name):
+    def hgQueueShowHeader(self):
         """
         Public method to show the commit message of the current patch.
-        
-        @param name file/directory name (string)
         """
         from .HgQueuesHeaderDialog import HgQueuesHeaderDialog
         self.qheaderDialog = HgQueuesHeaderDialog(self.vcs)
         self.qheaderDialog.show()
         QApplication.processEvents()
-        self.qheaderDialog.start(name)
+        self.qheaderDialog.start()
     
-    def hgQueuePushPopPatches(self, name, operation, doAll=False, named=False,
+    def hgQueuePushPopPatches(self, operation, doAll=False, named=False,
                               force=False):
         """
         Public method to push patches onto the stack or pop patches off the
         stack.
         
-        @param name file/directory name (string)
         @param operation operation type to be performed (Queues.POP,
             Queues.PUSH, Queues.GOTO)
-        @keyparam doAll flag indicating to push/pop all (boolean)
-        @keyparam named flag indicating to push/pop until a named patch
+        @param doAll flag indicating to push/pop all (boolean)
+        @param named flag indicating to push/pop until a named patch
             is at the top of the stack (boolean)
-        @keyparam force flag indicating a forceful pop (boolean)
+        @param force flag indicating a forceful pop (boolean)
         @return flag indicating that the project should be reread (boolean)
         @exception ValueError raised to indicate an invalid operation
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return False
-        
         if operation == Queues.POP:
             args = self.vcs.initCommand("qpop")
             title = self.tr("Pop Patches")
@@ -330,7 +297,7 @@
         if doAll and operation in (Queues.POP, Queues.PUSH):
             args.append("--all")
         elif named or operation == Queues.GOTO:
-            patchnames = self.__getPatchesList(repodir, listType)
+            patchnames = self.__getPatchesList(listType)
             if patchnames:
                 patch, ok = QInputDialog.getItem(
                     None,
@@ -350,63 +317,43 @@
                 return False
         
         dia = HgDialog(title, self.vcs)
-        res = dia.startProcess(args, repodir)
+        res = dia.startProcess(args)
         if res:
             dia.exec()
             res = dia.hasAddOrDelete()
             self.vcs.checkVCSStatus()
         return res
     
-    def hgQueueListPatches(self, name):
+    def hgQueueListPatches(self):
         """
         Public method to show a list of all patches.
-        
-        @param name file/directory name (string)
         """
         from .HgQueuesListDialog import HgQueuesListDialog
         self.queuesListDialog = HgQueuesListDialog(self.vcs)
         self.queuesListDialog.show()
-        self.queuesListDialog.start(name)
+        self.queuesListDialog.start()
     
-    def hgQueueFinishAppliedPatches(self, name):
+    def hgQueueFinishAppliedPatches(self):
         """
         Public method to finish all applied patches.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         args = self.vcs.initCommand("qfinish")
         args.append("--applied")
         
         dia = HgDialog(self.tr('Finish Applied Patches'), self.vcs)
-        res = dia.startProcess(args, repodir)
+        res = dia.startProcess(args)
         if res:
             dia.exec()
             self.vcs.checkVCSStatus()
     
-    def hgQueueRenamePatch(self, name):
+    def hgQueueRenamePatch(self):
         """
         Public method to rename the current or a selected patch.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         args = self.vcs.initCommand("qrename")
-        patchnames = sorted(self.__getPatchesList(repodir, Queues.SERIES_LIST))
+        patchnames = sorted(self.__getPatchesList(Queues.SERIES_LIST))
         if patchnames:
-            currentPatch = self.__getCurrentPatch(repodir)
+            currentPatch = self.__getCurrentPatch()
             if currentPatch:
                 from .HgQueuesRenamePatchDialog import (
                     HgQueuesRenamePatchDialog
@@ -419,26 +366,16 @@
                     args.append(newName)
                     
                     dia = HgDialog(self.tr("Rename Patch"), self.vcs)
-                    res = dia.startProcess(args, repodir)
+                    res = dia.startProcess(args)
                     if res:
                         dia.exec()
     
-    def hgQueueDeletePatch(self, name):
+    def hgQueueDeletePatch(self):
         """
         Public method to delete a selected unapplied patch.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         args = self.vcs.initCommand("qdelete")
-        patchnames = sorted(self.__getPatchesList(repodir,
-                                                  Queues.UNAPPLIED_LIST))
+        patchnames = sorted(self.__getPatchesList(Queues.UNAPPLIED_LIST))
         if patchnames:
             patch, ok = QInputDialog.getItem(
                 None,
@@ -450,7 +387,7 @@
                 args.append(patch)
                 
                 dia = HgDialog(self.tr("Delete Patch"), self.vcs)
-                res = dia.startProcess(args, repodir)
+                res = dia.startProcess(args)
                 if res:
                     dia.exec()
         else:
@@ -459,23 +396,13 @@
                 self.tr("Select Patch"),
                 self.tr("""No patches to select from."""))
     
-    def hgQueueFoldUnappliedPatches(self, name):
+    def hgQueueFoldUnappliedPatches(self):
         """
         Public method to fold patches into the current patch.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         args = self.vcs.initCommand("qfold")
         patchnames = sorted(
-            self.__getPatchesList(repodir, Queues.UNAPPLIED_LIST,
-                                  withSummary=True))
+            self.__getPatchesList(Queues.UNAPPLIED_LIST, withSummary=True))
         if patchnames:
             from .HgQueuesFoldDialog import HgQueuesFoldDialog
             dlg = HgQueuesFoldDialog(patchnames)
@@ -488,7 +415,7 @@
                     args.extend(patchesList)
                     
                     dia = HgDialog(self.tr("Fold Patches"), self.vcs)
-                    res = dia.startProcess(args, repodir)
+                    res = dia.startProcess(args)
                     if res:
                         dia.exec()
                 else:
@@ -502,86 +429,55 @@
                 self.tr("Fold Patches"),
                 self.tr("""No patches available to be folded."""))
     
-    def hgQueueGuardsList(self, name):
+    def hgQueueGuardsList(self):
         """
         Public method to list the guards for the current or a named patch.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
-        patchnames = sorted(
-            self.__getPatchesList(repodir, Queues.SERIES_LIST))
+        patchnames = sorted(self.__getPatchesList(Queues.SERIES_LIST))
         if patchnames:
             from .HgQueuesListGuardsDialog import HgQueuesListGuardsDialog
             self.queuesListGuardsDialog = HgQueuesListGuardsDialog(
                 self.vcs, patchnames)
             self.queuesListGuardsDialog.show()
-            self.queuesListGuardsDialog.start(name)
+            self.queuesListGuardsDialog.start()
         else:
             E5MessageBox.information(
                 None,
                 self.tr("List Guards"),
                 self.tr("""No patches available to list guards for."""))
     
-    def hgQueueGuardsListAll(self, name):
+    def hgQueueGuardsListAll(self):
         """
         Public method to list all guards of all patches.
-        
-        @param name file/directory name (string)
         """
         from .HgQueuesListAllGuardsDialog import HgQueuesListAllGuardsDialog
         self.queuesListAllGuardsDialog = HgQueuesListAllGuardsDialog(self.vcs)
         self.queuesListAllGuardsDialog.show()
-        self.queuesListAllGuardsDialog.start(name)
+        self.queuesListAllGuardsDialog.start()
     
-    def hgQueueGuardsDefine(self, name):
+    def hgQueueGuardsDefine(self):
         """
         Public method to define guards for the current or a named patch.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
-        patchnames = sorted(
-            self.__getPatchesList(repodir, Queues.SERIES_LIST))
+        patchnames = sorted(self.__getPatchesList(Queues.SERIES_LIST))
         if patchnames:
             from .HgQueuesDefineGuardsDialog import HgQueuesDefineGuardsDialog
             self.queuesDefineGuardsDialog = HgQueuesDefineGuardsDialog(
                 self.vcs, self, patchnames)
             self.queuesDefineGuardsDialog.show()
-            self.queuesDefineGuardsDialog.start(name)
+            self.queuesDefineGuardsDialog.start()
         else:
             E5MessageBox.information(
                 None,
                 self.tr("Define Guards"),
                 self.tr("""No patches available to define guards for."""))
     
-    def hgQueueGuardsDropAll(self, name):
+    def hgQueueGuardsDropAll(self):
         """
         Public method to drop all guards of the current or a named patch.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         patchnames = sorted(
-            self.__getPatchesList(repodir, Queues.SERIES_LIST))
+            self.__getPatchesList(Queues.SERIES_LIST))
         if patchnames:
             patch, ok = QInputDialog.getItem(
                 None,
@@ -604,22 +500,13 @@
                 self.tr("Drop All Guards"),
                 self.tr("""No patches available to define guards for."""))
     
-    def hgQueueGuardsSetActive(self, name):
+    def hgQueueGuardsSetActive(self):
         """
         Public method to set the active guards.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
-        guardsList = self.getGuardsList(repodir)
+        guardsList = self.getGuardsList()
         if guardsList:
-            activeGuardsList = self.getGuardsList(repodir, allGuards=False)
+            activeGuardsList = self.getGuardsList(allGuards=False)
             from .HgQueuesGuardsSelectionDialog import (
                 HgQueuesGuardsSelectionDialog
             )
@@ -632,7 +519,7 @@
                     args.extend(guards)
                     
                     dia = HgDialog(self.tr('Set Active Guards'), self.vcs)
-                    res = dia.startProcess(args, repodir)
+                    res = dia.startProcess(args)
                     if res:
                         dia.exec()
         else:
@@ -642,41 +529,23 @@
                 self.tr("""No guards available to select from."""))
             return
     
-    def hgQueueGuardsDeactivate(self, name):
+    def hgQueueGuardsDeactivate(self):
         """
         Public method to deactivate all active guards.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         args = self.vcs.initCommand("qselect")
         args.append("--none")
         
         dia = HgDialog(self.tr('Deactivate Guards'), self.vcs)
-        res = dia.startProcess(args, repodir)
+        res = dia.startProcess(args)
         if res:
             dia.exec()
     
-    def hgQueueGuardsIdentifyActive(self, name):
+    def hgQueueGuardsIdentifyActive(self):
         """
         Public method to list all active guards.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
-        guardsList = self.getGuardsList(repodir, allGuards=False)
+        guardsList = self.getGuardsList(allGuards=False)
         if guardsList:
             from .HgQueuesGuardsSelectionDialog import (
                 HgQueuesGuardsSelectionDialog
@@ -684,20 +553,12 @@
             dlg = HgQueuesGuardsSelectionDialog(guardsList, listOnly=True)
             dlg.exec()
     
-    def hgQueueCreateRenameQueue(self, name, isCreate):
+    def hgQueueCreateRenameQueue(self, isCreate):
         """
         Public method to create a new queue or rename the active queue.
         
-        @param name file/directory name (string)
         @param isCreate flag indicating to create a new queue (boolean)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         if isCreate:
             title = self.tr("Create New Queue")
         else:
@@ -707,7 +568,7 @@
         )
         dlg = HgQueuesQueueManagementDialog(
             HgQueuesQueueManagementDialog.NAME_INPUT,
-            title, False, repodir, self.vcs)
+            title, False, self.vcs)
         if dlg.exec() == QDialog.Accepted:
             queueName = dlg.getData()
             if queueName:
@@ -739,23 +600,15 @@
                     ):
                         self.queuesListQueuesDialog.refresh()
     
-    def hgQueueDeletePurgeActivateQueue(self, name, operation):
+    def hgQueueDeletePurgeActivateQueue(self, operation):
         """
         Public method to delete the reference to a queue and optionally
         remove the patch directory or set the active queue.
         
-        @param name file/directory name (string)
         @param operation operation to be performed (Queues.QUEUE_DELETE,
             Queues.QUEUE_PURGE, Queues.QUEUE_ACTIVATE)
         @exception ValueError raised to indicate an invalid operation
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         if operation == Queues.QUEUE_PURGE:
             title = self.tr("Purge Queue")
         elif operation == Queues.QUEUE_DELETE:
@@ -770,7 +623,7 @@
         )
         dlg = HgQueuesQueueManagementDialog(
             HgQueuesQueueManagementDialog.QUEUE_INPUT,
-            title, True, repodir, self.vcs)
+            title, True, self.vcs)
         if dlg.exec() == QDialog.Accepted:
             queueName = dlg.getData()
             if queueName:
@@ -803,26 +656,17 @@
                     ):
                         self.queuesListQueuesDialog.refresh()
     
-    def hgQueueListQueues(self, name):
+    def hgQueueListQueues(self):
         """
         Public method to list available queues.
-        
-        @param name file/directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         from .HgQueuesQueueManagementDialog import (
             HgQueuesQueueManagementDialog
         )
         self.queuesListQueuesDialog = HgQueuesQueueManagementDialog(
             HgQueuesQueueManagementDialog.NO_INPUT,
             self.tr("Available Queues"),
-            False, repodir, self.vcs)
+            False, self.vcs)
         self.queuesListQueuesDialog.show()
     
     def hgQueueInit(self, name):
@@ -831,16 +675,9 @@
         
         @param name directory name (string)
         """
-        # find the root of the repo
-        repodir = self.vcs.splitPath(name)[0]
-        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         args = self.vcs.initCommand("init")
         args.append('--mq')
-        args.append(repodir)
+        args.append(self.vcs.getClient().getRepository())
         # init is not possible with the command server
         dia = HgDialog(
             self.tr('Initializing new queue repository'), self.vcs)

eric ide

mercurial