From edd27d17704d2b4ac32909c41ad619644b75dc67 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Fri, 1 May 2009 17:46:56 +0000 Subject: [PATCH] - 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 --- gclient.py | 40 +++++++++++++++++++++++++++++----------- tests/gclient_test.py | 33 ++++++++++++++++----------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/gclient.py b/gclient.py index 54e94889b..769c3061c 100755 --- a/gclient.py +++ b/gclient.py @@ -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. diff --git a/tests/gclient_test.py b/tests/gclient_test.py index bacd2b9bf..3c0f60b59 100644 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -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()