Incremental changes towards more efficient refactoring of gclient.py

Fix gclient diff & pack to not throw uncatched exceptions when a directory is missing.

Reorder things in gclient.py for easier diff later
Update revinfo help
Add GetScmName(), it will be needed later.

TEST=unit tests
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@49565 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 15 years ago
parent f0fc991611
commit 9eda411072

@ -157,6 +157,7 @@ class GClientKeywords(object):
class GClient(GClientKeywords): class GClient(GClientKeywords):
"""Object that represent a gclient checkout.""" """Object that represent a gclient checkout."""
DEPS_FILE = 'DEPS'
SUPPORTED_COMMANDS = [ SUPPORTED_COMMANDS = [
'cleanup', 'diff', 'export', 'pack', 'revert', 'status', 'update', 'cleanup', 'diff', 'export', 'pack', 'revert', 'status', 'update',
@ -174,8 +175,6 @@ class GClient(GClientKeywords):
"linux2": "unix", "linux2": "unix",
} }
DEPS_FILE = 'DEPS'
DEFAULT_CLIENT_FILE_TEXT = ("""\ DEFAULT_CLIENT_FILE_TEXT = ("""\
solutions = [ solutions = [
{ "name" : "%(solution_name)s", { "name" : "%(solution_name)s",
@ -1040,14 +1039,22 @@ def CMDrunhooks(parser, args):
def CMDrevinfo(parser, args): def CMDrevinfo(parser, args):
"""Outputs details for every dependencies.""" """Output revision info mapping for the client and its dependencies.
parser.add_option("--deps", dest="deps_os", metavar="OS_LIST",
help="override deps for the specified (comma-separated) " This allows the capture of an overall "revision" for the source tree that
"platform(s); 'all' will process all deps_os " can be used to reproduce the same tree in the future. It is only useful for
"references") "unpinned dependencies", i.e. DEPS/deps references without a svn revision
parser.add_option("-s", "--snapshot", action="store_true", number or a git hash. A git branch name isn't "pinned" since the actual
help="create a snapshot file of the current " commit can change.
"version of all repositories") """
parser.add_option('--deps', dest='deps_os', metavar='OS_LIST',
help='override deps for the specified (comma-separated) '
'platform(s); \'all\' will process all deps_os '
'references')
parser.add_option('-s', '--snapshot', action='store_true',
help='creates a snapshot .gclient file of the current '
'version of all repositories to reproduce the tree, '
'implies -a')
(options, args) = parser.parse_args(args) (options, args) = parser.parse_args(args)
client = GClient.LoadCurrentConfig(options) client = GClient.LoadCurrentConfig(options)
if not client: if not client:

@ -55,22 +55,28 @@ class DiffFilterer(object):
# Factory Method for SCM wrapper creation # Factory Method for SCM wrapper creation
def CreateSCM(url=None, root_dir=None, relpath=None, scm_name='svn'): def GetScmName(url):
scm_map = { if url:
url, _ = gclient_utils.SplitUrlRevision(url)
if (url.startswith('git://') or url.startswith('ssh://') or
url.endswith('.git')):
return 'git'
elif (url.startswith('http://') or url.startswith('svn://') or
url.startswith('ssh+svn://')):
return 'svn'
return None
def CreateSCM(url, root_dir=None, relpath=None):
SCM_MAP = {
'svn' : SVNWrapper, 'svn' : SVNWrapper,
'git' : GitWrapper, 'git' : GitWrapper,
} }
orig_url = url scm_name = GetScmName(url)
if not scm_name in SCM_MAP:
if url: raise gclient_utils.Error('No SCM found for url %s' % url)
url, _ = gclient_utils.SplitUrlRevision(url) return SCM_MAP[scm_name](url, root_dir, relpath)
if url.startswith('git:') or url.startswith('ssh:') or url.endswith('.git'):
scm_name = 'git'
if not scm_name in scm_map:
raise gclient_utils.Error('Unsupported scm %s' % scm_name)
return scm_map[scm_name](orig_url, root_dir, relpath, scm_name)
# SCMWrapper base class # SCMWrapper base class
@ -80,9 +86,7 @@ class SCMWrapper(object):
This is the abstraction layer to bind to different SCM. This is the abstraction layer to bind to different SCM.
""" """
def __init__(self, url=None, root_dir=None, relpath=None, def __init__(self, url=None, root_dir=None, relpath=None):
scm_name='svn'):
self.scm_name = scm_name
self.url = url self.url = url
self._root_dir = root_dir self._root_dir = root_dir
if self._root_dir: if self._root_dir:
@ -106,7 +110,7 @@ class SCMWrapper(object):
if not command in dir(self): if not command in dir(self):
raise gclient_utils.Error('Command %s not implemented in %s wrapper' % ( raise gclient_utils.Error('Command %s not implemented in %s wrapper' % (
command, self.scm_name)) command, self.__class__.__name__))
return getattr(self, command)(options, args, file_list) return getattr(self, command)(options, args, file_list)
@ -671,9 +675,12 @@ class SVNWrapper(SCMWrapper):
def diff(self, options, args, file_list): def diff(self, options, args, file_list):
# NOTE: This function does not currently modify file_list. # NOTE: This function does not currently modify file_list.
path = os.path.join(self._root_dir, self.relpath)
if not os.path.isdir(path):
raise gclient_utils.Error('Directory %s is not present.' % path)
command = ['diff'] command = ['diff']
command.extend(args) command.extend(args)
scm.SVN.Run(command, os.path.join(self._root_dir, self.relpath)) scm.SVN.Run(command, path)
def export(self, options, args, file_list): def export(self, options, args, file_list):
"""Export a clean directory tree into the given path.""" """Export a clean directory tree into the given path."""
@ -692,6 +699,8 @@ class SVNWrapper(SCMWrapper):
"""Generates a patch file which can be applied to the root of the """Generates a patch file which can be applied to the root of the
repository.""" repository."""
path = os.path.join(self._root_dir, self.relpath) path = os.path.join(self._root_dir, self.relpath)
if not os.path.isdir(path):
raise gclient_utils.Error('Directory %s is not present.' % path)
command = ['diff'] command = ['diff']
command.extend(args) command.extend(args)

@ -301,10 +301,10 @@ def IsUsingGit(root, paths):
return True return True
return False return False
def FindGclientRoot(from_dir): def FindGclientRoot(from_dir, filename='.gclient'):
"""Tries to find the gclient root.""" """Tries to find the gclient root."""
path = os.path.realpath(from_dir) path = os.path.realpath(from_dir)
while not os.path.exists(os.path.join(path, '.gclient')): while not os.path.exists(os.path.join(path, filename)):
next = os.path.split(path) next = os.path.split(path)
if not next[1]: if not next[1]:
return None return None
@ -312,6 +312,7 @@ def FindGclientRoot(from_dir):
logging.info('Found gclient root at ' + path) logging.info('Found gclient root at ' + path)
return path return path
def PathDifference(root, subpath): def PathDifference(root, subpath):
"""Returns the difference subpath minus root.""" """Returns the difference subpath minus root."""
root = os.path.realpath(root) root = os.path.realpath(root)

@ -70,18 +70,17 @@ class SVNWrapperTestCase(BaseTestCase):
members = [ members = [
'AddAdditionalFlags', 'FullUrlForRelativeUrl', 'RunCommand', 'AddAdditionalFlags', 'FullUrlForRelativeUrl', 'RunCommand',
'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'revinfo', 'runhooks', 'status', 'update',
'updatesingle', 'url', 'updatesingle', 'url',
] ]
# If you add a member, be sure to add the relevant test! # If you add a member, be sure to add the relevant test!
self.compareMembers(self._scm_wrapper(), members) self.compareMembers(self._scm_wrapper('svn://a'), members)
def testUnsupportedSCM(self): def testUnsupportedSCM(self):
args = [self.url, self.root_dir, self.relpath] args = ['gopher://foo', self.root_dir, self.relpath]
kwargs = {'scm_name' : 'foo'} exception_msg = 'No SCM found for url gopher://foo'
exception_msg = 'Unsupported scm %(scm_name)s' % kwargs self.assertRaisesError(exception_msg, self._scm_wrapper, *args)
self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs)
def testSVNFullUrlForRelativeUrl(self): def testSVNFullUrlForRelativeUrl(self):
self.url = 'svn://a/b/c/d' self.url = 'svn://a/b/c/d'
@ -528,7 +527,7 @@ from :3
members = [ members = [
'FullUrlForRelativeUrl', 'RunCommand', 'FullUrlForRelativeUrl', 'RunCommand',
'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', 'revinfo', 'runhooks', 'status', 'update', 'url',
] ]
# If you add a member, be sure to add the relevant test! # If you add a member, be sure to add the relevant test!

Loading…
Cancel
Save