From 7f5918704edbae9330edc8f4cac5fe73cf087800 Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Sun, 9 Jan 2022 13:56:43 -0500 Subject: [PATCH] Add static typing for VcsInterface.getRevision --- src/diffuse/vcs/bzr.py | 2 +- src/diffuse/vcs/cvs.py | 11 ++++++----- src/diffuse/vcs/darcs.py | 6 ++++-- src/diffuse/vcs/git.py | 2 +- src/diffuse/vcs/hg.py | 2 +- src/diffuse/vcs/mtn.py | 2 +- src/diffuse/vcs/rcs.py | 2 +- src/diffuse/vcs/svk.py | 3 ++- src/diffuse/vcs/svn.py | 2 +- src/diffuse/vcs/vcs_interface.py | 2 +- 10 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/diffuse/vcs/bzr.py b/src/diffuse/vcs/bzr.py index e7b4669..3dee6db 100644 --- a/src/diffuse/vcs/bzr.py +++ b/src/diffuse/vcs/bzr.py @@ -181,7 +181,7 @@ class Bzr(VcsInterface): result.append(m[k]) return result - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: return utils.popenRead( self.root, [ diff --git a/src/diffuse/vcs/cvs.py b/src/diffuse/vcs/cvs.py index fc90088..8b34bd5 100644 --- a/src/diffuse/vcs/cvs.py +++ b/src/diffuse/vcs/cvs.py @@ -86,10 +86,10 @@ class Cvs(VcsInterface): # sort the results return [modified[k] for k in sorted(modified.keys())] - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: if rev == 'BASE' and not os.path.exists(name): # find revision for removed files - for s in utils.popenReadLines( + lines = utils.popenReadLines( self.root, [ prefs.getString('cvs_bin'), @@ -98,9 +98,10 @@ class Cvs(VcsInterface): ], prefs, 'cvs_bash' - ): - if s.startswith(' Working revision:\t-'): - rev = s.split('\t')[1][1:] + ) + for line in lines: + if line.startswith(' Working revision:\t-'): + rev = line.split('\t')[1][1:] return utils.popenRead( self.root, [ diff --git a/src/diffuse/vcs/darcs.py b/src/diffuse/vcs/darcs.py index 0607f8f..dac7bdd 100644 --- a/src/diffuse/vcs/darcs.py +++ b/src/diffuse/vcs/darcs.py @@ -19,6 +19,8 @@ import os +from typing import List, Optional + from diffuse import utils from diffuse.preferences import Preferences from diffuse.vcs.folder_set import FolderSet @@ -136,8 +138,8 @@ class Darcs(VcsInterface): def getFolderTemplate(self, prefs, names): return self._getCommitTemplate(prefs, names, None) - def getRevision(self, prefs, name, rev): - args = [prefs.getString('darcs_bin'), 'show', 'contents'] + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: + args: List[Optional[str]] = [prefs.getString('darcs_bin'), 'show', 'contents'] try: args.extend(['-n', str(int(rev))]) except ValueError: diff --git a/src/diffuse/vcs/git.py b/src/diffuse/vcs/git.py index e741315..46b19e6 100644 --- a/src/diffuse/vcs/git.py +++ b/src/diffuse/vcs/git.py @@ -150,7 +150,7 @@ class Git(VcsInterface): result.append(m[k]) return result - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: relpath = utils.relpath(self.root, os.path.abspath(name)).replace(os.sep, '/') return utils.popenRead( self.root, diff --git a/src/diffuse/vcs/hg.py b/src/diffuse/vcs/hg.py index 88deb47..7cdb11f 100644 --- a/src/diffuse/vcs/hg.py +++ b/src/diffuse/vcs/hg.py @@ -98,7 +98,7 @@ class Hg(VcsInterface): def getFolderTemplate(self, prefs, names): return self._getCommitTemplate(prefs, names, ['status', '-q'], None) - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: return utils.popenRead( self.root, [ diff --git a/src/diffuse/vcs/mtn.py b/src/diffuse/vcs/mtn.py index 749754a..9aefbdb 100644 --- a/src/diffuse/vcs/mtn.py +++ b/src/diffuse/vcs/mtn.py @@ -218,7 +218,7 @@ class Mtn(VcsInterface): result.append(m[k]) return result - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: return utils.popenRead( self.root, [ diff --git a/src/diffuse/vcs/rcs.py b/src/diffuse/vcs/rcs.py index f6d721a..d9bda95 100644 --- a/src/diffuse/vcs/rcs.py +++ b/src/diffuse/vcs/rcs.py @@ -154,7 +154,7 @@ class Rcs(VcsInterface): # sort the results return [[(k, r[k]), (k, None)] for k in sorted(r.keys())] - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: return utils.popenRead( self.root, [ diff --git a/src/diffuse/vcs/svk.py b/src/diffuse/vcs/svk.py index 5e25e4b..8cf3ca6 100644 --- a/src/diffuse/vcs/svk.py +++ b/src/diffuse/vcs/svk.py @@ -22,6 +22,7 @@ import os from typing import Optional, Tuple from diffuse import utils +from diffuse.preferences import Preferences from diffuse.vcs.svn import Svn @@ -48,7 +49,7 @@ class Svk(Svn): return str(int(rev[:-1]) - 1) + '@' return str(int(rev) - 1) - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: relpath = utils.relpath(self.root, os.path.abspath(name)).replace(os.sep, '/') return utils.popenRead( self.root, diff --git a/src/diffuse/vcs/svn.py b/src/diffuse/vcs/svn.py index 0e4327d..cafd837 100644 --- a/src/diffuse/vcs/svn.py +++ b/src/diffuse/vcs/svn.py @@ -272,7 +272,7 @@ class Svn(VcsInterface): def getFolderTemplate(self, prefs, names): return self._getCommitTemplate(prefs, None, names) - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: vcs_bin = prefs.getString('svn_bin') if rev in ['BASE', 'COMMITTED', 'PREV']: return utils.popenRead( diff --git a/src/diffuse/vcs/vcs_interface.py b/src/diffuse/vcs/vcs_interface.py index 0cef9d3..4ba9504 100644 --- a/src/diffuse/vcs/vcs_interface.py +++ b/src/diffuse/vcs/vcs_interface.py @@ -42,5 +42,5 @@ class VcsInterface: def getFolderTemplate(self, prefs, names): """Indicates which file revisions to display for a set of folders.""" - def getRevision(self, prefs, name, rev): + def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes: """Returns the contents of the specified file revision"""