Commit edd27d17 authored by maruel@chromium.org's avatar maruel@chromium.org

- Add '!' and 'L' status support.

- Fix gclient revert/status when one of the dependency directory is deleted.
- Remove an unneeded svn update after svn checkout.
- Updated tests.
Review URL: http://codereview.chromium.org/100256

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@15068 0039d316-1c4b-4281-b951-d872f2087c98
parent 277003e2
......@@ -592,15 +592,16 @@ def CaptureSVNHeadRevision(options, url):
class FileStatus:
def __init__(self, path, text_status, props, history):
def __init__(self, path, text_status, props, lock, history):
self.path = path
self.text_status = text_status
self.props = props
self.lock = lock
self.history = history
def __str__(self):
# Emulate svn status 1.5 output.
return (self.text_status + self.props + ' ' + self.history + ' ' +
return (self.text_status + self.props + self.lock + self.history + ' ' +
self.path)
......@@ -635,6 +636,8 @@ def CaptureSVNStatus(options, path):
statuses[0] = 'A'
elif xml_item_status == 'conflicted':
statuses[0] = 'C'
elif xml_item_status in ('incomplete', 'missing'):
statuses[0] = '!'
elif not xml_item_status:
pass
else:
......@@ -652,10 +655,14 @@ def CaptureSVNStatus(options, path):
else:
raise Exception('Unknown props status "%s"; please implement me!' %
xml_props_status)
# Col 2
if wc_status[0].getAttribute('wc-locked') == 'true':
statuses[2] = 'L'
# Col 3
if wc_status[0].getAttribute('copied') == 'true':
statuses[3] = '+'
item = FileStatus(file, statuses[0], statuses[1], statuses[3])
item = FileStatus(file, statuses[0], statuses[1], statuses[2],
statuses[3])
results.append(item)
return results
......@@ -755,7 +762,10 @@ class SCMWrapper(object):
if not options.path_exists(os.path.join(self._root_dir, self.relpath)):
# We need to checkout.
command = ['checkout', url, os.path.join(self._root_dir, self.relpath)]
if revision:
command.extend(['--revision', str(revision)])
RunSVNAndGetFileList(options, command, self._root_dir, file_list)
return
# Get the existing scm url and the revision number of the current checkout.
from_info = CaptureSVNInfo(options,
......@@ -810,12 +820,12 @@ class SCMWrapper(object):
"""
path = os.path.join(self._root_dir, self.relpath)
if not os.path.isdir(path):
# We can't revert path that doesn't exist.
# TODO(maruel): Should we update instead?
if options.verbose:
print >>options.stdout, ("\n_____ %s is missing, can't revert" %
self.relpath)
return
# svn revert won't work if the directory doesn't exist. It needs to
# checkout instead.
print >>options.stdout, ("\n_____ %s is missing, synching instead" %
self.relpath)
# Don't reuse the args.
return self.update(options, [], file_list)
files = CaptureSVNStatus(options, path)
# Batch the command.
......@@ -859,10 +869,18 @@ class SCMWrapper(object):
def status(self, options, args, file_list):
"""Display status information."""
path = os.path.join(self._root_dir, self.relpath)
command = ['status']
command.extend(args)
RunSVNAndGetFileList(options, command,
os.path.join(self._root_dir, self.relpath), file_list)
if not os.path.isdir(path):
# svn status won't work if the directory doesn't exist.
print >> options.stdout, (
"\n________ couldn't run \'%s\' in \'%s\':\nThe directory "
"does not exist."
% (' '.join(command), path))
# There's no file list to retrieve.
else:
RunSVNAndGetFileList(options, command, path, file_list)
## GClient implementation.
......
......@@ -1121,16 +1121,22 @@ class SCMWrapperTestCase(BaseTestCase):
def testRevertMissing(self):
options = self.Options(verbose=True)
gclient.os.path.isdir = self.mox.CreateMockAnything()
gclient.os.path.isdir(os.path.join(self.root_dir, self.relpath)
).AndReturn(False)
print >>options.stdout, ("\n_____ %s is missing, can't revert" %
base_path = os.path.join(self.root_dir, self.relpath)
gclient.os.path.isdir(base_path).AndReturn(False)
# It'll to a checkout instead.
options.path_exists(os.path.join(base_path, '.git')).AndReturn(False)
print >>options.stdout, ("\n_____ %s is missing, synching instead" %
self.relpath)
# Checkout.
options.path_exists(base_path).AndReturn(False)
files_list = self.mox.CreateMockAnything()
gclient.RunSVNAndGetFileList(options, ['checkout', self.url, base_path],
self.root_dir, files_list)
self.mox.ReplayAll()
scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
file_list = []
scm.revert(options, self.args, file_list)
scm.revert(options, self.args, files_list)
self.mox.VerifyAll()
gclient.os.path.isdir = os.path.isdir
......@@ -1155,8 +1161,8 @@ class SCMWrapperTestCase(BaseTestCase):
gclient.os.path.isdir = self.mox.CreateMockAnything()
gclient.os.path.isdir(base_path).AndReturn(True)
items = [
gclient.FileStatus('a', 'M', ' ', ' '),
gclient.FileStatus('b', 'A', ' ', ' '),
gclient.FileStatus('a', 'M', ' ', ' ', ' '),
gclient.FileStatus('b', 'A', ' ', ' ', ' '),
]
gclient.CaptureSVNStatus(options, base_path).AndReturn(items)
......@@ -1175,6 +1181,8 @@ class SCMWrapperTestCase(BaseTestCase):
def testStatus(self):
options = self.Options(verbose=True)
base_path = os.path.join(self.root_dir, self.relpath)
gclient.os.path.isdir = self.mox.CreateMockAnything()
gclient.os.path.isdir(base_path).AndReturn(True)
gclient.RunSVNAndGetFileList(options, ['status'] + self.args, base_path,
[]).AndReturn(None)
......@@ -1197,23 +1205,14 @@ class SCMWrapperTestCase(BaseTestCase):
file_info.uuid = 'ABC'
file_info.revision = 42
options.path_exists(os.path.join(base_path, '.git')).AndReturn(False)
# Checkout or update.
# Checkout.
options.path_exists(base_path).AndReturn(False)
print >>options.stdout, "\n_____ asf at 42"
#print >>options.stdout, "\n________ running 'svn checkout %s %s' in '%s'" % (
# self.url, base_path, os.path.abspath(self.root_dir))
gclient.CaptureSVNInfo(options, os.path.join(base_path, "."), '.'
).AndReturn(file_info)
# Cheat a bit here.
gclient.CaptureSVNInfo(options, file_info.url, '.').AndReturn(file_info)
files_list = self.mox.CreateMockAnything()
gclient.RunSVNAndGetFileList(options, ['checkout', self.url, base_path],
self.root_dir, files_list)
self.mox.ReplayAll()
scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
#file_list = []
scm.update(options, (), files_list)
self.mox.VerifyAll()
......
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