Commit cb5442bf authored by msb@chromium.org's avatar msb@chromium.org

gclient_scm: add test for unsupported scm

gclient_scm: use a map for deciding whether or not the scm is supported

gclient_scm: add a checks for unsupported scm and unimplemented method

git_scm: pull out svn code into SVNWrapper

gclient_scm: create a create_scm factory method

Use a factory method to abstract SCMWrapper creation. This method
will eventually return the correct subclass of SCMWrapper. Initially,
there will only be SVNWrapper.

Review URL: http://codereview.chromium.org/215022

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@26823 0039d316-1c4b-4281-b951-d872f2087c98
parent 742eb52c
......@@ -555,7 +555,7 @@ class GClient(object):
raise Error(
"relative DEPS entry \"%s\" must begin with a slash" % d)
# Create a scm just to query the full url.
scm = gclient_scm.SCMWrapper(solution["url"], self._root_dir,
scm = gclient_scm.CreateSCM(solution["url"], self._root_dir,
None)
url = scm.FullUrlForRelativeUrl(url)
if d in deps and deps[d] != url:
......@@ -672,7 +672,7 @@ class GClient(object):
entries[name] = url
if run_scm:
self._options.revision = revision_overrides.get(name)
scm = gclient_scm.SCMWrapper(url, self._root_dir, name)
scm = gclient_scm.CreateSCM(url, self._root_dir, name)
scm.RunCommand(command, self._options, args, file_list)
file_list = [os.path.join(name, file.strip()) for file in file_list]
self._options.revision = None
......@@ -698,7 +698,7 @@ class GClient(object):
entries[d] = url
if run_scm:
self._options.revision = revision_overrides.get(d)
scm = gclient_scm.SCMWrapper(url, self._root_dir, d)
scm = gclient_scm.CreateSCM(url, self._root_dir, d)
scm.RunCommand(command, self._options, args, file_list)
self._options.revision = None
......@@ -715,7 +715,7 @@ class GClient(object):
entries[d] = url
if run_scm:
self._options.revision = revision_overrides.get(d)
scm = gclient_scm.SCMWrapper(url, self._root_dir, d)
scm = gclient_scm.CreateSCM(url, self._root_dir, d)
scm.RunCommand(command, self._options, args, file_list)
self._options.revision = None
......
......@@ -28,6 +28,20 @@ SVN_COMMAND = "svn"
### SCM abstraction layer
# Factory Method for SCM wrapper creation
def CreateSCM(url=None, root_dir=None, relpath=None, scm_name='svn'):
# TODO(maruel): Deduce the SCM from the url.
scm_map = {
'svn' : SVNWrapper,
}
if not scm_name in scm_map:
raise gclient_utils.Error('Unsupported scm %s' % scm_name)
return scm_map[scm_name](url, root_dir, relpath, scm_name)
# SCMWrapper base class
class SCMWrapper(object):
"""Add necessary glue between all the supported SCM.
......@@ -36,7 +50,6 @@ class SCMWrapper(object):
once another SCM is supported."""
def __init__(self, url=None, root_dir=None, relpath=None,
scm_name='svn'):
# TODO(maruel): Deduce the SCM from the url.
self.scm_name = scm_name
self.url = url
self._root_dir = root_dir
......@@ -55,21 +68,21 @@ class SCMWrapper(object):
if file_list is None:
file_list = []
commands = {
'cleanup': self.cleanup,
'export': self.export,
'update': self.update,
'revert': self.revert,
'status': self.status,
'diff': self.diff,
'pack': self.pack,
'runhooks': self.status,
}
commands = ['cleanup', 'export', 'update', 'revert',
'status', 'diff', 'pack', 'runhooks']
if not command in commands:
raise gclient_utils.Error('Unknown command %s' % command)
return commands[command](options, args, file_list)
if not command in dir(self):
raise gclient_utils.Error('Command %s not implemnted in %s wrapper' % (
command, self.scm_name))
return getattr(self, command)(options, args, file_list)
class SVNWrapper(SCMWrapper):
""" Wrapper for SVN """
def cleanup(self, options, args, file_list):
"""Cleanup working copy."""
......@@ -255,6 +268,9 @@ class SCMWrapper(object):
# "svn up --revision BASE" achieve the same effect.
RunSVNAndGetFileList(['update', '--revision', 'BASE'], path, file_list)
def runhooks(self, options, args, file_list):
self.status(options, args, file_list)
def status(self, options, args, file_list):
"""Display status information."""
path = os.path.join(self._root_dir, self.relpath)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment