Commit 669600d3 authored by maruel@chromium.org's avatar maruel@chromium.org

Remove scm.SVN.Run() and all stdout argument to more calls.

BUG=54084
TEST=unit tests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@58214 0039d316-1c4b-4281-b951-d872f2087c98
parent 17d01795
......@@ -670,15 +670,14 @@ class SVNWrapper(SCMWrapper):
def cleanup(self, options, args, file_list):
"""Cleanup working copy."""
scm.SVN.Run(['cleanup'] + args,
cwd=os.path.join(self._root_dir, self.relpath))
self._Run(['cleanup'] + args, options)
def diff(self, options, args, 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)
scm.SVN.Run(['diff'] + args, cwd=path)
self._Run(['diff'] + args, options)
def export(self, options, args, file_list):
"""Export a clean directory tree into the given path."""
......@@ -689,8 +688,7 @@ class SVNWrapper(SCMWrapper):
except OSError:
pass
assert os.path.exists(export_path)
scm.SVN.Run(['export', '--force', '.', export_path],
cwd=os.path.join(self._root_dir, self.relpath))
self._Run(['export', '--force', '.', export_path], options)
def pack(self, options, args, file_list):
"""Generates a patch file which can be applied to the root of the
......@@ -745,8 +743,7 @@ class SVNWrapper(SCMWrapper):
# We need to checkout.
command = ['checkout', url, checkout_path]
command = self._AddAdditionalUpdateFlags(command, options, revision)
scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir,
file_list)
self._RunAndGetFileList(command, options, file_list, self._root_dir)
return
# Get the existing scm url and the revision number of the current checkout.
......@@ -761,7 +758,7 @@ class SVNWrapper(SCMWrapper):
dir_info = scm.SVN.CaptureStatus(os.path.join(checkout_path, '.'))
if [True for d in dir_info if d[0][2] == 'L' and d[1] == checkout_path]:
# The current directory is locked, clean it up.
scm.SVN.Run(['cleanup'], cwd=checkout_path)
self._Run(['cleanup'], options)
# Retrieve the current HEAD version because svn is slow at null updates.
if options.manually_grab_svn_rev and not revision:
......@@ -793,7 +790,7 @@ class SVNWrapper(SCMWrapper):
from_info['Repository Root'],
to_info['Repository Root'],
self.relpath]
scm.SVN.Run(command, cwd=self._root_dir)
self._Run(command, options, cwd=self._root_dir)
from_info['URL'] = from_info['URL'].replace(
from_info['Repository Root'],
to_info['Repository Root'])
......@@ -812,8 +809,7 @@ class SVNWrapper(SCMWrapper):
# We need to checkout.
command = ['checkout', url, checkout_path]
command = self._AddAdditionalUpdateFlags(command, options, revision)
scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir,
file_list)
self._RunAndGetFileList(command, options, file_list, self._root_dir)
return
# If the provided url has a revision number that matches the revision
......@@ -825,8 +821,7 @@ class SVNWrapper(SCMWrapper):
command = ['update', checkout_path]
command = self._AddAdditionalUpdateFlags(command, options, revision)
scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir,
file_list)
self._RunAndGetFileList(command, options, file_list, self._root_dir)
def updatesingle(self, options, args, file_list):
checkout_path = os.path.join(self._root_dir, self.relpath)
......@@ -836,12 +831,11 @@ class SVNWrapper(SCMWrapper):
# Create an empty checkout and then update the one file we want. Future
# operations will only apply to the one file we checked out.
command = ["checkout", "--depth", "empty", self.url, checkout_path]
scm.SVN.Run(command, cwd=self._root_dir)
self._Run(command, options, cwd=self._root_dir)
if os.path.exists(os.path.join(checkout_path, filename)):
os.remove(os.path.join(checkout_path, filename))
command = ["update", filename]
scm.SVN.RunAndGetFileList(options.verbose, command, checkout_path,
file_list)
self._RunAndGetFileList(command, options, file_list)
# After the initial checkout, we can use update as if it were any other
# dep.
self.update(options, args, file_list)
......@@ -856,7 +850,7 @@ class SVNWrapper(SCMWrapper):
os.path.join(checkout_path, filename)]
command = self._AddAdditionalUpdateFlags(command, options,
options.revision)
scm.SVN.Run(command, cwd=self._root_dir)
self._Run(command, options, cwd=self._root_dir)
def revert(self, options, args, file_list):
"""Reverts local modifications. Subversion specific.
......@@ -919,9 +913,8 @@ class SVNWrapper(SCMWrapper):
try:
# svn revert is so broken we don't even use it. Using
# "svn up --revision BASE" achieve the same effect.
scm.SVN.RunAndGetFileList(options.verbose,
['update', '--revision', 'BASE'], path,
file_list)
self._RunAndGetFileList(['update', '--revision', 'BASE'], options,
file_list)
except OSError, e:
# Maybe the directory disapeared meanwhile. We don't want it to throw an
# exception.
......@@ -937,8 +930,7 @@ class SVNWrapper(SCMWrapper):
def status(self, options, args, file_list):
"""Display status information."""
path = os.path.join(self._root_dir, self.relpath)
command = ['status']
command.extend(args)
command = ['status'] + args
if not os.path.isdir(path):
# svn status won't work if the directory doesn't exist.
print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory "
......@@ -946,12 +938,24 @@ class SVNWrapper(SCMWrapper):
% (' '.join(command), path))
# There's no file list to retrieve.
else:
scm.SVN.RunAndGetFileList(options.verbose, command, path, file_list)
self._RunAndGetFileList(command, options, file_list)
def FullUrlForRelativeUrl(self, url):
# Find the forth '/' and strip from there. A bit hackish.
return '/'.join(self.url.split('/')[:4]) + url
def _Run(self, args, options, **kwargs):
"""Runs a commands that goes to stdout."""
kwargs.setdefault('cwd', os.path.join(self._root_dir, self.relpath))
gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args,
always=options.verbose, stdout=options.stdout, **kwargs)
def _RunAndGetFileList(self, args, options, file_list, cwd=None):
"""Runs a commands that goes to stdout and grabs the file listed."""
cwd = cwd or os.path.join(self._root_dir, self.relpath)
scm.SVN.RunAndGetFileList(options.verbose, args, cwd=cwd,
file_list=file_list, stdout=options.stdout)
@staticmethod
def _AddAdditionalUpdateFlags(command, options, revision):
"""Add additional flags to command depending on what options are set.
......
......@@ -305,12 +305,6 @@ class GIT(object):
class SVN(object):
current_version = None
@staticmethod
def Run(args, **kwargs):
"""Wrappers to gclient_utils.CheckCallAndFilterAndHeader()."""
return gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args,
always=True, **kwargs)
@staticmethod
def Capture(args, in_directory=None, print_error=True):
"""Runs svn, capturing output sent to stdout as a string.
......
......@@ -33,6 +33,8 @@ class BaseTestCase(GCBaseTestCase):
def setUp(self):
GCBaseTestCase.setUp(self)
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter')
self.mox.StubOutWithMock(gclient_scm.gclient_utils,
'CheckCallAndFilterAndHeader')
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory')
......@@ -40,10 +42,10 @@ class BaseTestCase(GCBaseTestCase):
self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo')
self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Run')
self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList')
self._scm_wrapper = gclient_scm.CreateSCM
gclient_scm.sys.stdout.flush = lambda: None
gclient_scm.scm.SVN.current_version = None
class SVNWrapperTestCase(BaseTestCase):
......@@ -56,6 +58,7 @@ class SVNWrapperTestCase(BaseTestCase):
self.force = False
self.reset = False
self.nohooks = False
self.stdout = gclient_scm.sys.stdout
def Options(self, *args, **kwargs):
return self.OptionsObject(self, *args, **kwargs)
......@@ -131,7 +134,9 @@ class SVNWrapperTestCase(BaseTestCase):
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
['checkout', self.url, base_path,
'--force'],
self.root_dir, files_list)
cwd=self.root_dir,
file_list=files_list,
stdout=options.stdout)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
......@@ -145,7 +150,9 @@ class SVNWrapperTestCase(BaseTestCase):
gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([])
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
['update', '--revision', 'BASE'],
base_path, mox.IgnoreArg())
cwd=base_path,
file_list=mox.IgnoreArg(),
stdout=options.stdout)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
......@@ -172,7 +179,9 @@ class SVNWrapperTestCase(BaseTestCase):
gclient_scm.os.remove(file_path2)
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
['update', '--revision', 'BASE'],
base_path, mox.IgnoreArg())
cwd=base_path,
file_list=mox.IgnoreArg(),
stdout=options.stdout)
print(gclient_scm.os.path.join(base_path, 'a'))
print(gclient_scm.os.path.join(base_path, 'b'))
......@@ -200,7 +209,9 @@ class SVNWrapperTestCase(BaseTestCase):
file_list1 = []
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
['update', '--revision', 'BASE'],
base_path, mox.IgnoreArg())
cwd=base_path,
file_list=mox.IgnoreArg(),
stdout=options.stdout)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
......@@ -214,7 +225,8 @@ class SVNWrapperTestCase(BaseTestCase):
gclient_scm.os.path.isdir(base_path).AndReturn(True)
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
['status'] + self.args,
base_path, []).AndReturn(None)
cwd=base_path, file_list=[],
stdout=options.stdout).AndReturn(None)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
......@@ -238,10 +250,14 @@ class SVNWrapperTestCase(BaseTestCase):
# Checkout.
gclient_scm.os.path.exists(base_path).AndReturn(False)
files_list = self.mox.CreateMockAnything()
gclient_scm.scm.SVN.Capture(['--version']
).AndReturn('svn, version 1.5.1 (r32289)')
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
['checkout', self.url, base_path,
'--force'],
self.root_dir, files_list)
cwd=self.root_dir,
file_list=files_list,
stdout=options.stdout)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
......@@ -275,13 +291,14 @@ class SVNWrapperTestCase(BaseTestCase):
additional_args = []
if options.manually_grab_svn_rev:
additional_args = ['--revision', str(file_info['Revision'])]
if options.force and gclient_scm.scm.SVN.AssertVersion("1.5")[0]:
additional_args.append('--force')
gclient_scm.scm.SVN.Capture(['--version']
).AndReturn('svn, version 1.5.1 (r32289)')
additional_args.append('--force')
files_list = []
gclient_scm.scm.SVN.RunAndGetFileList(
options.verbose,
['update', base_path] + additional_args,
self.root_dir, files_list)
cwd=self.root_dir, file_list=files_list, stdout=options.stdout)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
......@@ -311,11 +328,11 @@ class SVNWrapperTestCase(BaseTestCase):
# When checking out a single file, we issue an svn checkout and svn update.
files_list = self.mox.CreateMockAnything()
gclient_scm.scm.SVN.Run(
['checkout', '--depth', 'empty', self.url, base_path],
cwd=self.root_dir)
gclient_scm.gclient_utils.CheckCallAndFilterAndHeader(
['svn', 'checkout', '--depth', 'empty', self.url, base_path],
always=True, cwd=self.root_dir, stdout=options.stdout)
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'],
gclient_scm.os.path.join(self.root_dir, self.relpath), files_list)
cwd=base_path, file_list=files_list, stdout=options.stdout)
# Now we fall back on scm.update().
gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
......@@ -325,7 +342,8 @@ class SVNWrapperTestCase(BaseTestCase):
gclient_scm.os.path.join(base_path, "."), '.'
).AndReturn(file_info)
gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info)
print("\n_____ %s at 42" % self.relpath)
options.stdout.write("\n_____ %s at 42" % self.relpath)
options.stdout.write('\n')
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
......@@ -349,10 +367,10 @@ class SVNWrapperTestCase(BaseTestCase):
# When checking out a single file with svn 1.4, we use svn export
files_list = self.mox.CreateMockAnything()
gclient_scm.scm.SVN.Run(
['export', gclient_scm.os.path.join(self.url, 'DEPS'),
gclient_scm.gclient_utils.CheckCallAndFilterAndHeader(
['svn', 'export', gclient_scm.os.path.join(self.url, 'DEPS'),
gclient_scm.os.path.join(base_path, 'DEPS')],
cwd=self.root_dir)
always=True, cwd=self.root_dir, stdout=options.stdout)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
......@@ -385,11 +403,11 @@ class SVNWrapperTestCase(BaseTestCase):
# When checking out a single file, we issue an svn checkout and svn update.
files_list = self.mox.CreateMockAnything()
gclient_scm.scm.SVN.Run(
['checkout', '--depth', 'empty', self.url, base_path],
cwd=self.root_dir)
gclient_scm.gclient_utils.CheckCallAndFilterAndHeader(
['svn', 'checkout', '--depth', 'empty', self.url, base_path],
always=True, cwd=self.root_dir, stdout=options.stdout)
gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'],
gclient_scm.os.path.join(self.root_dir, self.relpath), files_list)
cwd=base_path, file_list=files_list, stdout=options.stdout)
# Now we fall back on scm.update().
gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
......
......@@ -870,9 +870,9 @@ class GClientSmokeFromCheckout(GClientSmokeBase):
def testRest(self):
self.gclient(['sync'])
# TODO(maruel): This is incorrect, it should run on ./ too.
out = self.parseGclient(['cleanup', '--deps', 'mac'],
out = self.parseGclient(['cleanup', '--deps', 'mac', '--verbose'],
[('running', join(self.root_dir, 'foo', 'bar'))])
out = self.parseGclient(['diff', '--deps', 'mac'],
out = self.parseGclient(['diff', '--deps', 'mac', '--verbose'],
[('running', join(self.root_dir, 'foo', 'bar'))])
......
......@@ -161,7 +161,7 @@ class SVNTestCase(BaseSCMTestCase):
'CaptureHeadRevision', 'CaptureInfo', 'CaptureStatus',
'current_version', 'DiffItem', 'GenerateDiff',
'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved',
'IsMovedInfo', 'ReadSimpleAuth', 'Run', 'RunAndGetFileList',
'IsMovedInfo', 'ReadSimpleAuth', 'RunAndGetFileList',
]
# If this test fails, you should add the relevant test.
self.compareMembers(scm.SVN, members)
......@@ -311,14 +311,6 @@ class SVNTestCase(BaseSCMTestCase):
]
self.assertEquals(sorted(info), sorted(expected))
def testRun(self):
param2 = 'bleh'
scm.gclient_utils.CheckCallAndFilterAndHeader(
['svn', 'foo', 'bar'], cwd=param2,
always=True).AndReturn(None)
self.mox.ReplayAll()
scm.SVN.Run(['foo', 'bar'], cwd=param2)
def testCaptureStatusEmpty(self):
text = r"""<?xml version="1.0"?>
<status>
......
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