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])
return result
def getRevision(self, prefs, name, rev):
def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes:
return utils.popenRead(
self.root,
[

View File

@ -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,
[

View File

@ -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:

View File

@ -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,

View File

@ -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,
[

View File

@ -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,
[

View File

@ -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,
[

View File

@ -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,

View File

@ -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(

View File

@ -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"""