Add static typing for VcsInterface.getRevision

This commit is contained in:
Romain Failliot 2022-01-09 13:56:43 -05:00
parent bf53f3c417
commit 7f5918704e
10 changed files with 19 additions and 15 deletions

View File

@ -181,7 +181,7 @@ class Bzr(VcsInterface):
result.append(m[k]) result.append(m[k])
return result return result
def getRevision(self, prefs, name, rev): def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes:
return utils.popenRead( return utils.popenRead(
self.root, self.root,
[ [

View File

@ -86,10 +86,10 @@ class Cvs(VcsInterface):
# sort the results # sort the results
return [modified[k] for k in sorted(modified.keys())] 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): if rev == 'BASE' and not os.path.exists(name):
# find revision for removed files # find revision for removed files
for s in utils.popenReadLines( lines = utils.popenReadLines(
self.root, self.root,
[ [
prefs.getString('cvs_bin'), prefs.getString('cvs_bin'),
@ -98,9 +98,10 @@ class Cvs(VcsInterface):
], ],
prefs, prefs,
'cvs_bash' 'cvs_bash'
): )
if s.startswith(' Working revision:\t-'): for line in lines:
rev = s.split('\t')[1][1:] if line.startswith(' Working revision:\t-'):
rev = line.split('\t')[1][1:]
return utils.popenRead( return utils.popenRead(
self.root, self.root,
[ [

View File

@ -19,6 +19,8 @@
import os import os
from typing import List, Optional
from diffuse import utils from diffuse import utils
from diffuse.preferences import Preferences from diffuse.preferences import Preferences
from diffuse.vcs.folder_set import FolderSet from diffuse.vcs.folder_set import FolderSet
@ -136,8 +138,8 @@ class Darcs(VcsInterface):
def getFolderTemplate(self, prefs, names): def getFolderTemplate(self, prefs, names):
return self._getCommitTemplate(prefs, names, None) return self._getCommitTemplate(prefs, names, None)
def getRevision(self, prefs, name, rev): def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes:
args = [prefs.getString('darcs_bin'), 'show', 'contents'] args: List[Optional[str]] = [prefs.getString('darcs_bin'), 'show', 'contents']
try: try:
args.extend(['-n', str(int(rev))]) args.extend(['-n', str(int(rev))])
except ValueError: except ValueError:

View File

@ -150,7 +150,7 @@ class Git(VcsInterface):
result.append(m[k]) result.append(m[k])
return result 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, '/') relpath = utils.relpath(self.root, os.path.abspath(name)).replace(os.sep, '/')
return utils.popenRead( return utils.popenRead(
self.root, self.root,

View File

@ -98,7 +98,7 @@ class Hg(VcsInterface):
def getFolderTemplate(self, prefs, names): def getFolderTemplate(self, prefs, names):
return self._getCommitTemplate(prefs, names, ['status', '-q'], None) 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( return utils.popenRead(
self.root, self.root,
[ [

View File

@ -218,7 +218,7 @@ class Mtn(VcsInterface):
result.append(m[k]) result.append(m[k])
return result return result
def getRevision(self, prefs, name, rev): def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes:
return utils.popenRead( return utils.popenRead(
self.root, self.root,
[ [

View File

@ -154,7 +154,7 @@ class Rcs(VcsInterface):
# sort the results # sort the results
return [[(k, r[k]), (k, None)] for k in sorted(r.keys())] 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( return utils.popenRead(
self.root, self.root,
[ [

View File

@ -22,6 +22,7 @@ import os
from typing import Optional, Tuple from typing import Optional, Tuple
from diffuse import utils from diffuse import utils
from diffuse.preferences import Preferences
from diffuse.vcs.svn import Svn from diffuse.vcs.svn import Svn
@ -48,7 +49,7 @@ class Svk(Svn):
return str(int(rev[:-1]) - 1) + '@' return str(int(rev[:-1]) - 1) + '@'
return str(int(rev) - 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, '/') relpath = utils.relpath(self.root, os.path.abspath(name)).replace(os.sep, '/')
return utils.popenRead( return utils.popenRead(
self.root, self.root,

View File

@ -272,7 +272,7 @@ class Svn(VcsInterface):
def getFolderTemplate(self, prefs, names): def getFolderTemplate(self, prefs, names):
return self._getCommitTemplate(prefs, None, 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') vcs_bin = prefs.getString('svn_bin')
if rev in ['BASE', 'COMMITTED', 'PREV']: if rev in ['BASE', 'COMMITTED', 'PREV']:
return utils.popenRead( return utils.popenRead(

View File

@ -42,5 +42,5 @@ class VcsInterface:
def getFolderTemplate(self, prefs, names): def getFolderTemplate(self, prefs, names):
"""Indicates which file revisions to display for a set of folders.""" """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""" """Returns the contents of the specified file revision"""