diff --git a/src/diffuse/vcs/bzr.py b/src/diffuse/vcs/bzr.py index 3277f01..e7b4669 100644 --- a/src/diffuse/vcs/bzr.py +++ b/src/diffuse/vcs/bzr.py @@ -20,13 +20,14 @@ import os from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.folder_set import FolderSet from diffuse.vcs.vcs_interface import VcsInterface # Bazaar support class Bzr(VcsInterface): - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: # merge conflict left = name + '.OTHER' right = name + '.THIS' diff --git a/src/diffuse/vcs/cvs.py b/src/diffuse/vcs/cvs.py index 306f2e2..fc90088 100644 --- a/src/diffuse/vcs/cvs.py +++ b/src/diffuse/vcs/cvs.py @@ -22,13 +22,14 @@ import os from gettext import gettext as _ from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.folder_set import FolderSet from diffuse.vcs.vcs_interface import VcsInterface # CVS support class Cvs(VcsInterface): - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: return [(name, 'BASE'), (name, None)] def getCommitTemplate(self, prefs, rev, names): diff --git a/src/diffuse/vcs/darcs.py b/src/diffuse/vcs/darcs.py index 28331f3..0607f8f 100644 --- a/src/diffuse/vcs/darcs.py +++ b/src/diffuse/vcs/darcs.py @@ -20,13 +20,14 @@ import os from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.folder_set import FolderSet from diffuse.vcs.vcs_interface import VcsInterface # Darcs support class Darcs(VcsInterface): - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: return [(name, ''), (name, None)] def _getCommitTemplate(self, prefs, names, rev): diff --git a/src/diffuse/vcs/git.py b/src/diffuse/vcs/git.py index 20b2d5f..e741315 100644 --- a/src/diffuse/vcs/git.py +++ b/src/diffuse/vcs/git.py @@ -27,7 +27,7 @@ from diffuse.vcs.vcs_interface import VcsInterface # Git support class Git(VcsInterface): - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: return [(name, 'HEAD'), (name, None)] def getCommitTemplate(self, prefs, rev, names): diff --git a/src/diffuse/vcs/hg.py b/src/diffuse/vcs/hg.py index 6dc540e..88deb47 100644 --- a/src/diffuse/vcs/hg.py +++ b/src/diffuse/vcs/hg.py @@ -22,6 +22,7 @@ import os from typing import Optional from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.folder_set import FolderSet from diffuse.vcs.vcs_interface import VcsInterface @@ -51,7 +52,7 @@ class Hg(VcsInterface): return self.working_rev return f'p1({rev})' - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: return [(name, self._getPreviousRevision(prefs, None)), (name, None)] def _getCommitTemplate(self, prefs, names, cmd, rev): diff --git a/src/diffuse/vcs/mtn.py b/src/diffuse/vcs/mtn.py index 7330e32..749754a 100644 --- a/src/diffuse/vcs/mtn.py +++ b/src/diffuse/vcs/mtn.py @@ -21,27 +21,28 @@ import os import shlex from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.folder_set import FolderSet from diffuse.vcs.vcs_interface import VcsInterface # Monotone support class Mtn(VcsInterface): - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: # FIXME: merge conflicts? return [(name, 'h:'), (name, None)] def getCommitTemplate(self, prefs, rev, names): # build command vcs_bin = prefs.getString('mtn_bin') - ss = utils.popenReadLines( + lines = utils.popenReadLines( self.root, [vcs_bin, 'automate', 'select', '-q', rev], prefs, 'mtn_bash') - if len(ss) != 1: + if len(lines) != 1: raise IOError('Ambiguous revision specifier') - args = [vcs_bin, 'automate', 'get_revision', ss[0]] + args = [vcs_bin, 'automate', 'get_revision', lines[0]] # build list of interesting files fs = FolderSet(names) pwd, isabs = os.path.abspath(os.curdir), False @@ -50,15 +51,15 @@ class Mtn(VcsInterface): # run command prev = None removed, added, modified, renamed = {}, {}, {}, {} - ss = utils.popenReadLines(self.root, args, prefs, 'mtn_bash') + lines = utils.popenReadLines(self.root, args, prefs, 'mtn_bash') i = 0 - while i < len(ss): + while i < len(lines): # process results - s = shlex.split(ss[i]) + line_args = shlex.split(lines[i]) i += 1 - if len(s) < 2: + if len(line_args) < 2: continue - arg, arg1 = s[0], s[1] + arg, arg1 = line_args[0], line_args[1] if arg == 'old_revision' and len(arg1) > 2: if prev is not None: break @@ -82,26 +83,27 @@ class Mtn(VcsInterface): if fs.contains(k): modified[arg1] = k elif arg == 'rename': - s = shlex.split(ss[i]) + line_args = shlex.split(lines[i]) i += 1 - if len(s) > 1 and s[0] == 'to': + if len(line_args) > 1 and line_args[0] == 'to': # renamed file k0 = os.path.join(self.root, prefs.convertToNativePath(arg1)) - k1 = os.path.join(self.root, prefs.convertToNativePath(s[1])) + k1 = os.path.join(self.root, prefs.convertToNativePath(line_args[1])) if fs.contains(k0) or fs.contains(k1): - renamed[s[1]] = (arg1, k0, k1) + renamed[line_args[1]] = (arg1, k0, k1) if removed or renamed: # remove directories removed_dirs = set() - for s in utils.popenReadLines( + lines = utils.popenReadLines( self.root, [vcs_bin, 'automate', 'get_manifest_of', prev], prefs, 'mtn_bash' - ): - s = shlex.split(s) - if len(s) > 1 and s[0] == 'dir': - removed_dirs.add(s[1]) + ) + for line in lines: + line_args = shlex.split(line) + if len(line_args) > 1 and line_args[0] == 'dir': + removed_dirs.add(line_args[1]) for k in removed_dirs: for m in removed, modified: if k in m: diff --git a/src/diffuse/vcs/rcs.py b/src/diffuse/vcs/rcs.py index 41fa203..f6d721a 100644 --- a/src/diffuse/vcs/rcs.py +++ b/src/diffuse/vcs/rcs.py @@ -22,12 +22,13 @@ import os from gettext import gettext as _ from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.vcs_interface import VcsInterface # RCS support class Rcs(VcsInterface): - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: args = [ prefs.getString('rcs_bin_rlog'), '-L', diff --git a/src/diffuse/vcs/svk.py b/src/diffuse/vcs/svk.py index bd8dfe5..5e25e4b 100644 --- a/src/diffuse/vcs/svk.py +++ b/src/diffuse/vcs/svk.py @@ -19,7 +19,7 @@ import os -from typing import Tuple +from typing import Optional, Tuple from diffuse import utils from diffuse.vcs.svn import Svn @@ -41,7 +41,7 @@ class Svk(Svn): return s[0], s[4:] @staticmethod - def _getPreviousRevision(rev: str) -> str: + def _getPreviousRevision(rev: Optional[str]) -> str: if rev is None: return 'HEAD' if rev.endswith('@'): diff --git a/src/diffuse/vcs/svn.py b/src/diffuse/vcs/svn.py index fc14a56..0e4327d 100644 --- a/src/diffuse/vcs/svn.py +++ b/src/diffuse/vcs/svn.py @@ -24,6 +24,7 @@ from gettext import gettext as _ from typing import Optional, Tuple from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.folder_set import FolderSet from diffuse.vcs.vcs_interface import VcsInterface @@ -54,7 +55,7 @@ class Svn(VcsInterface): return s[0], s[k:] @staticmethod - def _getPreviousRevision(rev: str) -> str: + def _getPreviousRevision(rev: Optional[str]) -> str: if rev is None: return 'BASE' m = int(rev) @@ -71,7 +72,7 @@ class Svn(VcsInterface): break return self.url - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList: # FIXME: verify this # merge conflict escaped_name = utils.globEscape(name) diff --git a/src/diffuse/vcs/vcs_interface.py b/src/diffuse/vcs/vcs_interface.py index 63800e8..0cef9d3 100644 --- a/src/diffuse/vcs/vcs_interface.py +++ b/src/diffuse/vcs/vcs_interface.py @@ -17,14 +17,22 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from typing import List, Optional, Tuple + +from diffuse.preferences import Preferences + + class VcsInterface: """Interface for the VCSs.""" + PathRevisionPair = Tuple[Optional[str], Optional[str]] + PathRevisionList = List[PathRevisionPair] + def __init__(self, root: str): """The object will initialized with the repository's root folder.""" self.root = root - def getFileTemplate(self, prefs, name): + def getFileTemplate(self, prefs: Preferences, name: str) -> PathRevisionList: """Indicates which revisions to display for a file when none were explicitly requested."""