Mon, 08 Jan 2024 11:50:27 +0100
Version Control
- Changed the version control state to be an 'enum.Enum' class.
--- a/src/eric7/Plugins/VcsPlugins/vcsGit/git.py Mon Jan 08 11:14:48 2024 +0100 +++ b/src/eric7/Plugins/VcsPlugins/vcsGit/git.py Mon Jan 08 11:50:27 2024 +0100 @@ -23,7 +23,7 @@ from eric7.QScintilla.MiniEditor import MiniEditor from eric7.SystemUtilities import FileSystemUtilities, PythonUtilities from eric7.VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog -from eric7.VCS.VersionControl import VersionControl +from eric7.VCS.VersionControl import VersionControl, VersionControlState from .GitDialog import GitDialog @@ -1068,8 +1068,8 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ if name.endswith(os.sep): name = name[:-1] @@ -1077,7 +1077,7 @@ dname, fname = self.splitPath(name) if fname == "." and os.path.exists(os.path.join(dname, self.adminDirOrFile)): - return self.canBeCommitted + return VersionControlState.Controlled if name in self.statusCache: return self.statusCache[name] @@ -1113,16 +1113,16 @@ if flag not in "?!": if fname == ".": if absname.startswith(dname + os.path.sep): - return self.canBeCommitted + return VersionControlState.Controlled if absname == dname: - return self.canBeCommitted + return VersionControlState.Controlled else: if absname == name: - return self.canBeCommitted + return VersionControlState.Controlled else: - return self.canBeCommitted - - return self.canBeAdded + return VersionControlState.Controlled + + return VersionControlState.Uncontrolled def vcsAllRegisteredStates(self, names, dname, shortcut=True): # noqa: U100 """ @@ -1139,8 +1139,8 @@ @type str @param shortcut flag indicating a shortcut should be taken @type bool - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ if dname.endswith(os.sep): @@ -1149,7 +1149,7 @@ # revert the logic because git status doesn't show unchanged files for name in names: - names[name] = self.canBeCommitted + names[name] = VersionControlState.Controlled found = False for name in self.statusCache: @@ -1189,19 +1189,21 @@ if isDir: name = name[:-1] if name in names: - names[name] = self.canBeAdded + names[name] = VersionControlState.Uncontrolled if isDir: # it's a directory for nname in names: if nname.startswith(name): - names[nname] = self.canBeAdded + names[nname] = VersionControlState.Uncontrolled if flag not in "?!": - self.statusCache[name] = self.canBeCommitted - self.statusCache[dirName] = self.canBeCommitted + self.statusCache[name] = VersionControlState.Controlled + self.statusCache[dirName] = VersionControlState.Controlled else: - self.statusCache[name] = self.canBeAdded + self.statusCache[name] = VersionControlState.Uncontrolled if dirName not in self.statusCache: - self.statusCache[dirName] = self.canBeAdded + self.statusCache[ + dirName + ] = VersionControlState.Uncontrolled return names
--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/hg.py Mon Jan 08 11:14:48 2024 +0100 +++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/hg.py Mon Jan 08 11:50:27 2024 +0100 @@ -21,7 +21,7 @@ from eric7.QScintilla.MiniEditor import MiniEditor from eric7.SystemUtilities import FileSystemUtilities from eric7.VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog -from eric7.VCS.VersionControl import VersionControl +from eric7.VCS.VersionControl import VersionControl, VersionControlState from .HgClient import HgClient from .HgDialog import HgDialog @@ -1098,15 +1098,15 @@ @param name file or directory name to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ if name.endswith(os.sep): name = name[:-1] name = os.path.normcase(name) if os.path.isdir(name) and os.path.isdir(os.path.join(name, self.adminDir)): - return self.canBeCommitted + return VersionControlState.Controlled if name in self.statusCache: return self.statusCache[name] @@ -1125,9 +1125,9 @@ os.path.join(repodir, path) ) if flag not in "?I" and absname == name: - return self.canBeCommitted - - return self.canBeAdded + return VersionControlState.Controlled + + return VersionControlState.Uncontrolled def vcsAllRegisteredStates(self, names, dname, shortcut=True): # noqa: U100 """ @@ -1144,8 +1144,8 @@ @type str @param shortcut flag indicating a shortcut should be taken @type bool - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ if dname.endswith(os.sep): @@ -1175,22 +1175,24 @@ dirName = os.path.dirname(name) if name.startswith(dname) and flag not in "?I": if name in names: - names[name] = self.canBeCommitted + names[name] = VersionControlState.Controlled if dirName in names: - names[dirName] = self.canBeCommitted + names[dirName] = VersionControlState.Controlled if dirs: for d in dirs: if name.startswith(d): - names[d] = self.canBeCommitted + names[d] = VersionControlState.Controlled dirs.remove(d) break if flag not in "?I": - self.statusCache[name] = self.canBeCommitted - self.statusCache[dirName] = self.canBeCommitted + self.statusCache[name] = VersionControlState.Controlled + self.statusCache[dirName] = VersionControlState.Controlled else: - self.statusCache[name] = self.canBeAdded + self.statusCache[name] = VersionControlState.Uncontrolled if dirName not in self.statusCache: - self.statusCache[dirName] = self.canBeAdded + self.statusCache[ + dirName + ] = VersionControlState.Uncontrolled return names
--- a/src/eric7/Plugins/VcsPlugins/vcsPySvn/subversion.py Mon Jan 08 11:14:48 2024 +0100 +++ b/src/eric7/Plugins/VcsPlugins/vcsPySvn/subversion.py Mon Jan 08 11:50:27 2024 +0100 @@ -25,7 +25,7 @@ from eric7.EricWidgets import EricMessageBox from eric7.EricWidgets.EricApplication import ericApp from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog -from eric7.VCS.VersionControl import VersionControl +from eric7.VCS.VersionControl import VersionControl, VersionControlState from .SvnDialog import SvnDialog from .SvnUtilities import amendConfig, createDefaultConfig, getConfigPath @@ -754,7 +754,8 @@ return # oops, project is not version controlled while os.path.normcase(dname) != os.path.normcase(repodir) and ( os.path.normcase(dname) not in self.statusCache - or self.statusCache[os.path.normcase(dname)] == self.canBeAdded + or self.statusCache[os.path.normcase(dname)] + == VersionControlState.Uncontrolled ): # add directories recursively, if they aren't in the # repository already @@ -785,7 +786,8 @@ and (d not in tree2 + tree) and ( os.path.normcase(d) not in self.statusCache - or self.statusCache[os.path.normcase(d)] == self.canBeAdded + or self.statusCache[os.path.normcase(d)] + == VersionControlState.Uncontrolled ) ): tree2.append(d) @@ -867,7 +869,8 @@ and (d not in tree) and ( os.path.normcase(d) not in self.statusCache - or self.statusCache[os.path.normcase(d)] == self.canBeAdded + or self.statusCache[os.path.normcase(d)] + == VersionControlState.Uncontrolled ) ): tree.append(d) @@ -891,7 +894,8 @@ return # oops, project is not version controlled while (os.path.normcase(dname) != os.path.normcase(repodir)) and ( os.path.normcase(dname) not in self.statusCache - or self.statusCache[os.path.normcase(dname)] == self.canBeAdded + or self.statusCache[os.path.normcase(dname)] + == VersionControlState.Uncontrolled ): # add directories recursively, if they aren't in the # repository already @@ -1483,8 +1487,8 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ if self.__wcng: return self.__vcsRegisteredState_wcng(name) @@ -1500,8 +1504,8 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ if name.endswith(os.sep): name = name[:-1] @@ -1509,7 +1513,7 @@ dname, fname = self.splitPath(name) if fname == "." and os.path.isdir(os.path.join(dname, self.adminDir)): - return self.canBeCommitted + return VersionControlState.Controlled if name in self.statusCache: return self.statusCache[name] @@ -1517,10 +1521,10 @@ name = os.path.normcase(name) states = {name: 0} states = self.vcsAllRegisteredStates(states, dname, False) - if states[name] == self.canBeCommitted: - return self.canBeCommitted + if states[name] == VersionControlState.Controlled: + return VersionControlState.Controlled else: - return self.canBeAdded + return VersionControlState.Uncontrolled def __vcsRegisteredState_wc(self, name): """ @@ -1531,24 +1535,24 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ dname, fname = self.splitPath(name) if fname == ".": if os.path.isdir(os.path.join(dname, self.adminDir)): - return self.canBeCommitted + return VersionControlState.Controlled else: - return self.canBeAdded + return VersionControlState.Uncontrolled name = os.path.normcase(name) states = {name: 0} states = self.vcsAllRegisteredStates(states, dname, False) - if states[name] == self.canBeCommitted: - return self.canBeCommitted + if states[name] == VersionControlState.Controlled: + return VersionControlState.Controlled else: - return self.canBeAdded + return VersionControlState.Uncontrolled def vcsAllRegisteredStates(self, names, dname, shortcut=True): """ @@ -1565,8 +1569,8 @@ @type str @param shortcut flag indicating a shortcut should be taken @type bool - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ if self.__wcng: @@ -1592,8 +1596,8 @@ @type str @param shortcut flag indicating a shortcut should be taken @type bool - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ from .SvnDialogMixin import SvnDialogMixin @@ -1633,26 +1637,27 @@ name = os.path.normcase(file.path) if self.__isVersioned(file): if name in names: - names[name] = self.canBeCommitted + names[name] = VersionControlState.Controlled dn = name while os.path.splitdrive(dn)[1] != os.sep and dn != repodir: dn = os.path.dirname(dn) if ( dn in self.statusCache - and self.statusCache[dn] == self.canBeCommitted + and self.statusCache[dn] + == VersionControlState.Controlled ): break - self.statusCache[dn] = self.canBeCommitted - self.statusCache[name] = self.canBeCommitted + self.statusCache[dn] = VersionControlState.Controlled + self.statusCache[name] = VersionControlState.Controlled if dirs: for d in dirs: if name.startswith(d): - names[d] = self.canBeCommitted - self.statusCache[d] = self.canBeCommitted + names[d] = VersionControlState.Controlled + self.statusCache[d] = VersionControlState.Controlled dirs.remove(d) break else: - self.statusCache[name] = self.canBeAdded + self.statusCache[name] = VersionControlState.Uncontrolled return names @@ -1674,8 +1679,8 @@ @type str @param shortcut flag indicating a shortcut should be taken @type bool - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ from .SvnDialogMixin import SvnDialogMixin @@ -1711,10 +1716,10 @@ name = os.path.normcase(file.path) if self.__isVersioned(file): if name in names: - names[name] = self.canBeCommitted - self.statusCache[name] = self.canBeCommitted + names[name] = VersionControlState.Controlled + self.statusCache[name] = VersionControlState.Controlled else: - self.statusCache[name] = self.canBeAdded + self.statusCache[name] = VersionControlState.Uncontrolled return names
--- a/src/eric7/Plugins/VcsPlugins/vcsSubversion/subversion.py Mon Jan 08 11:14:48 2024 +0100 +++ b/src/eric7/Plugins/VcsPlugins/vcsSubversion/subversion.py Mon Jan 08 11:50:27 2024 +0100 @@ -20,7 +20,7 @@ from eric7.EricWidgets import EricMessageBox from eric7.EricWidgets.EricApplication import ericApp from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog -from eric7.VCS.VersionControl import VersionControl +from eric7.VCS.VersionControl import VersionControl, VersionControlState from .SvnDialog import SvnDialog from .SvnUtilities import amendConfig, createDefaultConfig, getConfigPath @@ -702,7 +702,8 @@ return # oops, project is not version controlled while os.path.normcase(dname) != os.path.normcase(repodir) and ( os.path.normcase(dname) not in self.statusCache - or self.statusCache[os.path.normcase(dname)] == self.canBeAdded + or self.statusCache[os.path.normcase(dname)] + == VersionControlState.Uncontrolled ): # add directories recursively, if they aren't in the # repository already @@ -733,7 +734,8 @@ and (d not in tree2 + tree) and ( os.path.normcase(d) not in self.statusCache - or self.statusCache[os.path.normcase(d)] == self.canBeAdded + or self.statusCache[os.path.normcase(d)] + == VersionControlState.Uncontrolled ) ): tree2.append(d) @@ -801,7 +803,8 @@ and (d not in tree) and ( os.path.normcase(d) not in self.statusCache - or self.statusCache[os.path.normcase(d)] == self.canBeAdded + or self.statusCache[os.path.normcase(d)] + == VersionControlState.Uncontrolled ) ): tree.append(d) @@ -825,7 +828,8 @@ return # oops, project is not version controlled while os.path.normcase(dname) != os.path.normcase(repodir) and ( os.path.normcase(dname) not in self.statusCache - or self.statusCache[os.path.normcase(dname)] == self.canBeAdded + or self.statusCache[os.path.normcase(dname)] + == VersionControlState.Uncontrolled ): # add directories recursively, if they aren't in the # repository already @@ -1317,8 +1321,8 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ if self.__wcng: return self.__vcsRegisteredState_wcng(name) @@ -1334,8 +1338,8 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ if name.endswith(os.sep): name = name[:-1] @@ -1343,7 +1347,7 @@ dname, fname = self.splitPath(name) if fname == "." and os.path.isdir(os.path.join(dname, self.adminDir)): - return self.canBeCommitted + return VersionControlState.Controlled if name in self.statusCache: return self.statusCache[name] @@ -1351,10 +1355,10 @@ name = os.path.normcase(name) states = {name: 0} states = self.vcsAllRegisteredStates(states, dname, False) - if states[name] == self.canBeCommitted: - return self.canBeCommitted + if states[name] == VersionControlState.Controlled: + return VersionControlState.Controlled else: - return self.canBeAdded + return VersionControlState.Uncontrolled def __vcsRegisteredState_wc(self, name): """ @@ -1365,24 +1369,24 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState """ dname, fname = self.splitPath(name) if fname == ".": if os.path.isdir(os.path.join(dname, self.adminDir)): - return self.canBeCommitted + return VersionControlState.Controlled else: - return self.canBeAdded + return VersionControlState.Uncontrolled name = os.path.normcase(name) states = {name: 0} states = self.vcsAllRegisteredStates(states, dname, False) - if states[name] == self.canBeCommitted: - return self.canBeCommitted + if states[name] == VersionControlState.Controlled: + return VersionControlState.Controlled else: - return self.canBeAdded + return VersionControlState.Uncontrolled def vcsAllRegisteredStates(self, names, dname, shortcut=True): """ @@ -1399,8 +1403,8 @@ @type str @param shortcut flag indicating a shortcut should be taken @type bool - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ if self.__wcng: @@ -1424,8 +1428,8 @@ @type dict @param dname directory to check in @type str - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ if dname.endswith(os.sep): @@ -1474,10 +1478,10 @@ name = os.path.normcase(path) if flags[0] not in "?I": if name in names: - names[name] = self.canBeCommitted - self.statusCache[name] = self.canBeCommitted + names[name] = VersionControlState.Controlled + self.statusCache[name] = VersionControlState.Controlled else: - self.statusCache[name] = self.canBeAdded + self.statusCache[name] = VersionControlState.Uncontrolled return names @@ -1499,8 +1503,8 @@ @type str @param shortcut flag indicating a shortcut should be taken @type bool - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict """ if not os.path.isdir(os.path.join(dname, self.adminDir)): @@ -1546,10 +1550,10 @@ name = os.path.normcase(path) if flags[0] not in "?I": if name in names: - names[name] = self.canBeCommitted - self.statusCache[name] = self.canBeCommitted + names[name] = VersionControlState.Controlled + self.statusCache[name] = VersionControlState.Controlled else: - self.statusCache[name] = self.canBeAdded + self.statusCache[name] = VersionControlState.Uncontrolled return names
--- a/src/eric7/Project/Project.py Mon Jan 08 11:14:48 2024 +0100 +++ b/src/eric7/Project/Project.py Mon Jan 08 11:50:27 2024 +0100 @@ -60,6 +60,7 @@ ) from eric7.Tasks.TasksFile import TasksFile from eric7.UI.NotificationWidget import NotificationTypes +from eric7.VCS.VersionControl import VersionControlState from .DebuggerPropertiesFile import DebuggerPropertiesFile from .FileCategoryRepositoryItem import FileCategoryRepositoryItem @@ -3316,7 +3317,7 @@ self.setDirty(True) if self.vcs is not None and ( self.vcs.vcsRegisteredState(self.ppath) - != self.vcs.canBeCommitted + != VersionControlState.Controlled ): self.__pdata["VCS"] = "None" self.vcs = self.initVCS()
--- a/src/eric7/Project/ProjectBrowserModel.py Mon Jan 08 11:14:48 2024 +0100 +++ b/src/eric7/Project/ProjectBrowserModel.py Mon Jan 08 11:50:27 2024 +0100 @@ -25,6 +25,7 @@ BrowserSimpleDirectoryItem, ) from eric7.Utilities import ModuleParser +from eric7.VCS.VersionControl import VersionControlState class ProjectBrowserItemMixin: @@ -360,7 +361,7 @@ fname = f.absoluteFilePath() if ( states[os.path.normcase(fname)] - == self.project.vcs.canBeCommitted + == VersionControlState.Controlled ): node.addVcsStatus(self.project.vcs.vcsName()) self.project.clearStatusMonitorCachedState(f.absoluteFilePath()) @@ -443,7 +444,7 @@ if self.project.vcs is not None: if ( states[os.path.normcase(fname)] - == self.project.vcs.canBeCommitted + == VersionControlState.Controlled ): itm.addVcsStatus(self.project.vcs.vcsName()) else: @@ -742,7 +743,7 @@ if self.project.vcs is not None: self.project.vcs.clearStatusCache() state = self.project.vcs.vcsRegisteredState(node.name()) - if state == self.project.vcs.canBeCommitted: + if state == VersionControlState.Controlled: node.addVcsStatus(self.project.vcs.vcsName()) else: node.addVcsStatus(self.tr("local")) @@ -779,7 +780,7 @@ vcs = self.project.vcs if vcs is not None: state = vcs.vcsRegisteredState(name) - if state == vcs.canBeCommitted: + if state == VersionControlState.Controlled: item.addVcsStatus(vcs.vcsName()) else: item.addVcsStatus(self.tr("local")) @@ -801,7 +802,7 @@ if vcs is not None: vcs.clearStatusCache() state = vcs.vcsRegisteredState(name) - if state == vcs.canBeCommitted: + if state == VersionControlState.Controlled: item.setVcsStatus(vcs.vcsName()) else: item.setVcsStatus(self.tr("local"))
--- a/src/eric7/VCS/VersionControl.py Mon Jan 08 11:14:48 2024 +0100 +++ b/src/eric7/VCS/VersionControl.py Mon Jan 08 11:50:27 2024 +0100 @@ -9,6 +9,7 @@ """ import contextlib +import enum import json import os @@ -29,6 +30,15 @@ from eric7.EricWidgets.EricApplication import ericApp +class VersionControlState(enum.Enum): + """ + Class defining the global VCS states of files and directories. + """ + + Controlled = 0 + Uncontrolled = 1 + + class VersionControl(QObject): """ Class implementing an abstract base class to be subclassed by all specific @@ -56,10 +66,6 @@ vcsStatusMonitorInfo = pyqtSignal(str) vcsStatusChanged = pyqtSignal() - # TODO: change this to an enum - canBeCommitted = 1 # Indicates that a file/directory is in the vcs. - canBeAdded = 2 # Indicates that a file/directory is not in vcs. - commitHistoryLock = "commitHistory.lock" commitHistoryData = "commitHistory.json" @@ -563,8 +569,8 @@ @param name filename to check @type str - @return registered state (one of canBeCommited and canBeAdded) - @rtype int + @return registered state + @rtype VersionControlState @exception NotImplementedError to indicate that this method must be implemented by a subclass """ @@ -581,8 +587,8 @@ @type dict @param dname directory to check in @type str - @return the received dictionary completed with a combination of - canBeCommited and canBeAdded or None in order to signal an error + @return the received dictionary completed with the VCS state or None in + order to signal an error @rtype dict @exception NotImplementedError to indicate that this method must be implemented by a subclass