Add static typing for VcsInterface.getFileTemplate
This commit is contained in:
parent
c224d17e9a
commit
bf53f3c417
|
@ -20,13 +20,14 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from diffuse import utils
|
from diffuse import utils
|
||||||
|
from diffuse.preferences import Preferences
|
||||||
from diffuse.vcs.folder_set import FolderSet
|
from diffuse.vcs.folder_set import FolderSet
|
||||||
from diffuse.vcs.vcs_interface import VcsInterface
|
from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
|
|
||||||
# Bazaar support
|
# Bazaar support
|
||||||
class Bzr(VcsInterface):
|
class Bzr(VcsInterface):
|
||||||
def getFileTemplate(self, prefs, name):
|
def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList:
|
||||||
# merge conflict
|
# merge conflict
|
||||||
left = name + '.OTHER'
|
left = name + '.OTHER'
|
||||||
right = name + '.THIS'
|
right = name + '.THIS'
|
||||||
|
|
|
@ -22,13 +22,14 @@ import os
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from diffuse import utils
|
from diffuse import utils
|
||||||
|
from diffuse.preferences import Preferences
|
||||||
from diffuse.vcs.folder_set import FolderSet
|
from diffuse.vcs.folder_set import FolderSet
|
||||||
from diffuse.vcs.vcs_interface import VcsInterface
|
from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
|
|
||||||
# CVS support
|
# CVS support
|
||||||
class Cvs(VcsInterface):
|
class Cvs(VcsInterface):
|
||||||
def getFileTemplate(self, prefs, name):
|
def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList:
|
||||||
return [(name, 'BASE'), (name, None)]
|
return [(name, 'BASE'), (name, None)]
|
||||||
|
|
||||||
def getCommitTemplate(self, prefs, rev, names):
|
def getCommitTemplate(self, prefs, rev, names):
|
||||||
|
|
|
@ -20,13 +20,14 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from diffuse import utils
|
from diffuse import utils
|
||||||
|
from diffuse.preferences import Preferences
|
||||||
from diffuse.vcs.folder_set import FolderSet
|
from diffuse.vcs.folder_set import FolderSet
|
||||||
from diffuse.vcs.vcs_interface import VcsInterface
|
from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
|
|
||||||
# Darcs support
|
# Darcs support
|
||||||
class Darcs(VcsInterface):
|
class Darcs(VcsInterface):
|
||||||
def getFileTemplate(self, prefs, name):
|
def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList:
|
||||||
return [(name, ''), (name, None)]
|
return [(name, ''), (name, None)]
|
||||||
|
|
||||||
def _getCommitTemplate(self, prefs, names, rev):
|
def _getCommitTemplate(self, prefs, names, rev):
|
||||||
|
|
|
@ -27,7 +27,7 @@ from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
# Git support
|
# Git support
|
||||||
class Git(VcsInterface):
|
class Git(VcsInterface):
|
||||||
def getFileTemplate(self, prefs, name):
|
def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList:
|
||||||
return [(name, 'HEAD'), (name, None)]
|
return [(name, 'HEAD'), (name, None)]
|
||||||
|
|
||||||
def getCommitTemplate(self, prefs, rev, names):
|
def getCommitTemplate(self, prefs, rev, names):
|
||||||
|
|
|
@ -22,6 +22,7 @@ import os
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from diffuse import utils
|
from diffuse import utils
|
||||||
|
from diffuse.preferences import Preferences
|
||||||
from diffuse.vcs.folder_set import FolderSet
|
from diffuse.vcs.folder_set import FolderSet
|
||||||
from diffuse.vcs.vcs_interface import VcsInterface
|
from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ class Hg(VcsInterface):
|
||||||
return self.working_rev
|
return self.working_rev
|
||||||
return f'p1({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)]
|
return [(name, self._getPreviousRevision(prefs, None)), (name, None)]
|
||||||
|
|
||||||
def _getCommitTemplate(self, prefs, names, cmd, rev):
|
def _getCommitTemplate(self, prefs, names, cmd, rev):
|
||||||
|
|
|
@ -21,27 +21,28 @@ import os
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from diffuse import utils
|
from diffuse import utils
|
||||||
|
from diffuse.preferences import Preferences
|
||||||
from diffuse.vcs.folder_set import FolderSet
|
from diffuse.vcs.folder_set import FolderSet
|
||||||
from diffuse.vcs.vcs_interface import VcsInterface
|
from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
|
|
||||||
# Monotone support
|
# Monotone support
|
||||||
class Mtn(VcsInterface):
|
class Mtn(VcsInterface):
|
||||||
def getFileTemplate(self, prefs, name):
|
def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList:
|
||||||
# FIXME: merge conflicts?
|
# FIXME: merge conflicts?
|
||||||
return [(name, 'h:'), (name, None)]
|
return [(name, 'h:'), (name, None)]
|
||||||
|
|
||||||
def getCommitTemplate(self, prefs, rev, names):
|
def getCommitTemplate(self, prefs, rev, names):
|
||||||
# build command
|
# build command
|
||||||
vcs_bin = prefs.getString('mtn_bin')
|
vcs_bin = prefs.getString('mtn_bin')
|
||||||
ss = utils.popenReadLines(
|
lines = utils.popenReadLines(
|
||||||
self.root,
|
self.root,
|
||||||
[vcs_bin, 'automate', 'select', '-q', rev],
|
[vcs_bin, 'automate', 'select', '-q', rev],
|
||||||
prefs,
|
prefs,
|
||||||
'mtn_bash')
|
'mtn_bash')
|
||||||
if len(ss) != 1:
|
if len(lines) != 1:
|
||||||
raise IOError('Ambiguous revision specifier')
|
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
|
# build list of interesting files
|
||||||
fs = FolderSet(names)
|
fs = FolderSet(names)
|
||||||
pwd, isabs = os.path.abspath(os.curdir), False
|
pwd, isabs = os.path.abspath(os.curdir), False
|
||||||
|
@ -50,15 +51,15 @@ class Mtn(VcsInterface):
|
||||||
# run command
|
# run command
|
||||||
prev = None
|
prev = None
|
||||||
removed, added, modified, renamed = {}, {}, {}, {}
|
removed, added, modified, renamed = {}, {}, {}, {}
|
||||||
ss = utils.popenReadLines(self.root, args, prefs, 'mtn_bash')
|
lines = utils.popenReadLines(self.root, args, prefs, 'mtn_bash')
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(ss):
|
while i < len(lines):
|
||||||
# process results
|
# process results
|
||||||
s = shlex.split(ss[i])
|
line_args = shlex.split(lines[i])
|
||||||
i += 1
|
i += 1
|
||||||
if len(s) < 2:
|
if len(line_args) < 2:
|
||||||
continue
|
continue
|
||||||
arg, arg1 = s[0], s[1]
|
arg, arg1 = line_args[0], line_args[1]
|
||||||
if arg == 'old_revision' and len(arg1) > 2:
|
if arg == 'old_revision' and len(arg1) > 2:
|
||||||
if prev is not None:
|
if prev is not None:
|
||||||
break
|
break
|
||||||
|
@ -82,26 +83,27 @@ class Mtn(VcsInterface):
|
||||||
if fs.contains(k):
|
if fs.contains(k):
|
||||||
modified[arg1] = k
|
modified[arg1] = k
|
||||||
elif arg == 'rename':
|
elif arg == 'rename':
|
||||||
s = shlex.split(ss[i])
|
line_args = shlex.split(lines[i])
|
||||||
i += 1
|
i += 1
|
||||||
if len(s) > 1 and s[0] == 'to':
|
if len(line_args) > 1 and line_args[0] == 'to':
|
||||||
# renamed file
|
# renamed file
|
||||||
k0 = os.path.join(self.root, prefs.convertToNativePath(arg1))
|
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):
|
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:
|
if removed or renamed:
|
||||||
# remove directories
|
# remove directories
|
||||||
removed_dirs = set()
|
removed_dirs = set()
|
||||||
for s in utils.popenReadLines(
|
lines = utils.popenReadLines(
|
||||||
self.root,
|
self.root,
|
||||||
[vcs_bin, 'automate', 'get_manifest_of', prev],
|
[vcs_bin, 'automate', 'get_manifest_of', prev],
|
||||||
prefs,
|
prefs,
|
||||||
'mtn_bash'
|
'mtn_bash'
|
||||||
):
|
)
|
||||||
s = shlex.split(s)
|
for line in lines:
|
||||||
if len(s) > 1 and s[0] == 'dir':
|
line_args = shlex.split(line)
|
||||||
removed_dirs.add(s[1])
|
if len(line_args) > 1 and line_args[0] == 'dir':
|
||||||
|
removed_dirs.add(line_args[1])
|
||||||
for k in removed_dirs:
|
for k in removed_dirs:
|
||||||
for m in removed, modified:
|
for m in removed, modified:
|
||||||
if k in m:
|
if k in m:
|
||||||
|
|
|
@ -22,12 +22,13 @@ import os
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from diffuse import utils
|
from diffuse import utils
|
||||||
|
from diffuse.preferences import Preferences
|
||||||
from diffuse.vcs.vcs_interface import VcsInterface
|
from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
|
|
||||||
# RCS support
|
# RCS support
|
||||||
class Rcs(VcsInterface):
|
class Rcs(VcsInterface):
|
||||||
def getFileTemplate(self, prefs, name):
|
def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList:
|
||||||
args = [
|
args = [
|
||||||
prefs.getString('rcs_bin_rlog'),
|
prefs.getString('rcs_bin_rlog'),
|
||||||
'-L',
|
'-L',
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from typing import Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
from diffuse import utils
|
from diffuse import utils
|
||||||
from diffuse.vcs.svn import Svn
|
from diffuse.vcs.svn import Svn
|
||||||
|
@ -41,7 +41,7 @@ class Svk(Svn):
|
||||||
return s[0], s[4:]
|
return s[0], s[4:]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _getPreviousRevision(rev: str) -> str:
|
def _getPreviousRevision(rev: Optional[str]) -> str:
|
||||||
if rev is None:
|
if rev is None:
|
||||||
return 'HEAD'
|
return 'HEAD'
|
||||||
if rev.endswith('@'):
|
if rev.endswith('@'):
|
||||||
|
|
|
@ -24,6 +24,7 @@ from gettext import gettext as _
|
||||||
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.folder_set import FolderSet
|
from diffuse.vcs.folder_set import FolderSet
|
||||||
from diffuse.vcs.vcs_interface import VcsInterface
|
from diffuse.vcs.vcs_interface import VcsInterface
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ class Svn(VcsInterface):
|
||||||
return s[0], s[k:]
|
return s[0], s[k:]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _getPreviousRevision(rev: str) -> str:
|
def _getPreviousRevision(rev: Optional[str]) -> str:
|
||||||
if rev is None:
|
if rev is None:
|
||||||
return 'BASE'
|
return 'BASE'
|
||||||
m = int(rev)
|
m = int(rev)
|
||||||
|
@ -71,7 +72,7 @@ class Svn(VcsInterface):
|
||||||
break
|
break
|
||||||
return self.url
|
return self.url
|
||||||
|
|
||||||
def getFileTemplate(self, prefs, name):
|
def getFileTemplate(self, prefs: Preferences, name: str) -> VcsInterface.PathRevisionList:
|
||||||
# FIXME: verify this
|
# FIXME: verify this
|
||||||
# merge conflict
|
# merge conflict
|
||||||
escaped_name = utils.globEscape(name)
|
escaped_name = utils.globEscape(name)
|
||||||
|
|
|
@ -17,14 +17,22 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
from typing import List, Optional, Tuple
|
||||||
|
|
||||||
|
from diffuse.preferences import Preferences
|
||||||
|
|
||||||
|
|
||||||
class VcsInterface:
|
class VcsInterface:
|
||||||
"""Interface for the VCSs."""
|
"""Interface for the VCSs."""
|
||||||
|
|
||||||
|
PathRevisionPair = Tuple[Optional[str], Optional[str]]
|
||||||
|
PathRevisionList = List[PathRevisionPair]
|
||||||
|
|
||||||
def __init__(self, root: str):
|
def __init__(self, root: str):
|
||||||
"""The object will initialized with the repository's root folder."""
|
"""The object will initialized with the repository's root folder."""
|
||||||
self.root = root
|
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
|
"""Indicates which revisions to display for a file when none were explicitly
|
||||||
requested."""
|
requested."""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue