Mercurial: fixed a few issues introduced during the recent code cleanup.

Thu, 14 Jan 2021 17:51:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 14 Jan 2021 17:51:12 +0100
changeset 7979
54b73174ab61
parent 7978
1e391f977124
child 7980
2c3f14a3c595

Mercurial: fixed a few issues introduced during the recent code cleanup.

eric6/Plugins/VcsPlugins/vcsMercurial/HgClient.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsMercurial/HgStatusDialog.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsMercurial/hg.py file | annotate | diff | comparison | revisions
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/HgClient.py	Wed Jan 13 20:13:26 2021 +0100
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/HgClient.py	Thu Jan 14 17:51:12 2021 +0100
@@ -428,3 +428,12 @@
         @rtype bool
         """
         return self.__commandRunning
+    
+    def getRepository(self):
+        """
+        Public method to get the repository path this client is serving.
+        
+        @return repository path
+        @rtype str
+        """
+        return self.__repoPath
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/HgStatusDialog.py	Wed Jan 13 20:13:26 2021 +0100
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/HgStatusDialog.py	Thu Jan 14 17:51:12 2021 +0100
@@ -312,23 +312,19 @@
         args = self.vcs.initCommand("status")
         if self.__mq:
             args.append('--mq')
-            if isinstance(fn, list):
-                self.dname, fnames = self.vcs.splitPathList(fn)
-            else:
-                self.dname, fname = self.vcs.splitPath(fn)
         else:
             if self.vcs.hasSubrepositories():
                 args.append("--subrepos")
             
             if isinstance(fn, list):
-                self.dname, fnames = self.vcs.splitPathList(fn)
                 self.vcs.addArguments(args, fn)
             else:
-                self.dname, fname = self.vcs.splitPath(fn)
                 args.append(fn)
         
         self.refreshButton.setEnabled(False)
         
+        self.__repoPath = self.__hgClient.getRepository()
+        
         out, err = self.__hgClient.runcommand(args)
         if err:
             self.__showError(err)
@@ -490,9 +486,9 @@
         Private slot to handle the Commit context menu entry.
         """
         if self.__mq:
-            self.vcs.vcsCommit(self.dname, "", mq=True)
+            self.vcs.vcsCommit(self.__repoPath, "", mq=True)
         else:
-            names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+            names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                      for itm in self.__getCommitableItems()]
             if not names:
                 E5MessageBox.information(
@@ -532,7 +528,7 @@
         """
         Private slot to handle the Add context menu entry.
         """
-        names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+        names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                  for itm in self.__getUnversionedItems()]
         if not names:
             E5MessageBox.information(
@@ -556,7 +552,7 @@
         
         @param mode add mode (string one of 'normal' or 'large')
         """
-        names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+        names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                  for itm in self.__getUnversionedItems()]
         if not names:
             E5MessageBox.information(
@@ -579,7 +575,7 @@
         """
         Private slot to handle the Remove context menu entry.
         """
-        names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+        names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                  for itm in self.__getMissingItems()]
         if not names:
             E5MessageBox.information(
@@ -596,7 +592,7 @@
         """
         Private slot to handle the Revert context menu entry.
         """
-        names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+        names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                  for itm in self.__getModifiedItems()]
         if not names:
             E5MessageBox.information(
@@ -620,7 +616,7 @@
         """
         Private slot to handle the Restore Missing context menu entry.
         """
-        names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+        names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                  for itm in self.__getMissingItems()]
         if not names:
             E5MessageBox.information(
@@ -638,7 +634,7 @@
         """
         Private slot to handle the Diff context menu entry.
         """
-        names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+        names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                  for itm in self.__getModifiedItems()]
         if not names:
             E5MessageBox.information(
@@ -658,7 +654,7 @@
         """
         Private slot to handle the Diff context menu entry.
         """
-        names = [os.path.join(self.dname, itm.text(self.__pathColumn))
+        names = [os.path.join(self.__repoPath, itm.text(self.__pathColumn))
                  for itm in self.__getModifiedItems()]
         if not names:
             E5MessageBox.information(
@@ -762,7 +758,7 @@
         """
         Private slot to handle the Commit Merge context menu entry.
         """
-        self.vcs.vcsCommit(self.dname, self.tr('Merge'), merge=True)
+        self.vcs.vcsCommit(self.__repoPath, self.tr('Merge'), merge=True)
         self.__committed()
 
     def __abortMerge(self):
@@ -786,7 +782,7 @@
         if not self.__mq:
             selectedItems = self.statusList.selectedItems()
             if len(selectedItems) == 1:
-                fn = os.path.join(self.dname,
+                fn = os.path.join(self.__repoPath,
                                   selectedItems[0].text(self.__pathColumn))
                 self.__diffGenerator.start(fn)
     
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py	Wed Jan 13 20:13:26 2021 +0100
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py	Thu Jan 14 17:51:12 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
@@ -677,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)
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py	Wed Jan 13 20:13:26 2021 +0100
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py	Thu Jan 14 17:51:12 2021 +0100
@@ -1003,27 +1003,23 @@
         """
         Public method used to get the registered state of a file in the vcs.
         
-        @param name filename to check (string)
+        @param name file or directory name to check
+        @type str
         @return a combination of canBeCommited and canBeAdded
+        @rtype int
         """
         if name.endswith(os.sep):
             name = name[:-1]
         name = os.path.normcase(name)
-        dname, fname = self.splitPath(name)
         
-        if fname == '.' and os.path.isdir(os.path.join(dname, self.adminDir)):
+        if (
+            os.path.isdir(name) and
+            os.path.isdir(os.path.join(name, self.adminDir))
+        ):
             return self.canBeCommitted
         
         if name in self.statusCache:
             return self.statusCache[name]
-        
-        # find the root of the repo
-        repodir = dname
-        while not os.path.isdir(os.path.join(repodir, self.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return 0
-        
         args = self.initCommand("status")
         args.append('--all')
         args.append('--noninteractive')
@@ -1031,19 +1027,14 @@
         output, error = self.__client.runcommand(args)
         
         if output:
+            repodir = self.getClient().getRepository()
             for line in output.splitlines():
                 if len(line) > 2 and line[0] in "MARC!?I" and line[1] == " ":
                     flag, path = line.split(" ", 1)
-                    absname = os.path.join(repodir, os.path.normcase(path))
-                    if flag not in "?I":
-                        if fname == '.':
-                            if absname.startswith(dname + os.path.sep):
-                                return self.canBeCommitted
-                            if absname == dname:
-                                return self.canBeCommitted
-                        else:
-                            if absname == name:
-                                return self.canBeCommitted
+                    absname = Utilities.normcasepath(
+                        os.path.join(repodir, path))
+                    if flag not in "?I" and absname == name:
+                        return self.canBeCommitted
         
         return self.canBeAdded
     
@@ -1073,13 +1064,6 @@
                 names[name] = self.statusCache[name]
         
         if not found:
-            # find the root of the repo
-            repodir = dname
-            while not os.path.isdir(os.path.join(repodir, self.adminDir)):
-                repodir = os.path.dirname(repodir)
-                if os.path.splitdrive(repodir)[1] == os.sep:
-                    return names
-        
             args = self.initCommand("status")
             args.append('--all')
             args.append('--noninteractive')
@@ -1087,11 +1071,12 @@
             output, error = self.__client.runcommand(args)
             
             if output:
+                repoPath = self.getClient().getRepository()
                 dirs = [x for x in names.keys() if os.path.isdir(x)]
                 for line in output.splitlines():
                     if line and line[0] in "MARC!?I":
                         flag, path = line.split(" ", 1)
-                        name = os.path.normcase(os.path.join(repodir, path))
+                        name = os.path.normcase(os.path.join(repoPath, path))
                         dirName = os.path.dirname(name)
                         if name.startswith(dname):
                             if flag not in "?I":
@@ -1594,7 +1579,7 @@
         @param isFile flag indicating log for a file is to be shown
             (boolean)
         """
-        if name == self.__repoDir:
+        if name == self.getClient().getRepository():
             name = None
         
         if self.logBrowser is None:
@@ -1913,7 +1898,7 @@
         @type dict
         """
         if repoName is None:
-            repoName = self.__repoDir
+            repoName = self.getClient().getRepository()
         
         cfgFile = os.path.join(repoName, self.adminDir, "hgrc")
         if not os.path.exists(cfgFile):
@@ -2328,23 +2313,15 @@
             if res:
                 dia.exec()
 
-    def hgServe(self, name):
+    def hgServe(self, repoPath):
         """
         Public method used to serve the project.
         
-        @param name directory name (string)
+        @param repoPath directory containing the repository
+        @type str
         """
-        dname, fname = self.splitPath(name)
-        
-        # find the root of the repo
-        repodir = dname
-        while not os.path.isdir(os.path.join(repodir, self.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         from .HgServeDialog import HgServeDialog
-        self.serveDlg = HgServeDialog(self, repodir)
+        self.serveDlg = HgServeDialog(self, repoPath)
         self.serveDlg.show()
     
     def hgImport(self):
@@ -2607,7 +2584,8 @@
         """
         Public method to delete all backup bundles in the backup area.
         """
-        backupdir = os.path.join(self.__repodir, self.adminDir, "strip-backup")
+        backupdir = os.path.join(self.getClient().getRepository(),
+                                 self.adminDir, "strip-backup")
         yes = E5MessageBox.yesNo(
             self.__ui,
             self.tr("Delete All Backups"),
@@ -2842,22 +2820,14 @@
         
         self.iniFileChanged.emit()
     
-    def __monitorRepoIniFile(self, name):
+    def __monitorRepoIniFile(self, repodir):
         """
         Private slot to add a repository configuration file to the list of
         monitored files.
         
-        @param name directory name pointing into the repository (string)
+        @param repodir directory name of the repository
+        @type str
         """
-        dname, fname = self.splitPath(name)
-        
-        # find the root of the repo
-        repodir = dname
-        while not os.path.isdir(os.path.join(repodir, self.adminDir)):
-            repodir = os.path.dirname(repodir)
-            if not repodir or os.path.splitdrive(repodir)[1] == os.sep:
-                return
-        
         cfgFile = os.path.join(repodir, self.adminDir, "hgrc")
         if os.path.exists(cfgFile):
             self.__iniWatcher.addPath(cfgFile)

eric ide

mercurial