From 8e13a094398c96a7012e04e280384b737e339bfe Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 2 Nov 2010 19:06:06 +0000 Subject: [PATCH] Change gcl presubmit to only run commit hooks by default. Upload hook are only run with the --upload flag. Most of the time the same hook is run in both case so gcl presubmit is simply 2x slower than it could be otherwise. TEST=none BUG=none Review URL: http://codereview.chromium.org/4277003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@64779 0039d316-1c4b-4281-b951-d872f2087c98 --- gcl.py | 26 ++++++++++++++++---------- tests/gcl_unittest.py | 6 +++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/gcl.py b/gcl.py index 058837a1e..39f3bec1d 100755 --- a/gcl.py +++ b/gcl.py @@ -9,6 +9,7 @@ of files. """ import getpass +import optparse import os import random import re @@ -865,22 +866,27 @@ def CMDupload(change_info, args): return 0 -@need_change -def CMDpresubmit(change_info): +@need_change_and_args +@attrs(usage='[--upload]') +def CMDpresubmit(change_info, args): """Runs presubmit checks on the change. The actual presubmit code is implemented in presubmit_support.py and looks for PRESUBMIT.py files.""" if not change_info.GetFiles(): - print "Nothing to presubmit check, changelist is empty." + print('Nothing to presubmit check, changelist is empty.') return 0 - - print "*** Presubmit checks for UPLOAD would report: ***" - result = DoPresubmitChecks(change_info, False, False) - - print "\n*** Presubmit checks for COMMIT would report: ***" - result &= DoPresubmitChecks(change_info, True, False) - return not result + parser = optparse.OptionParser() + parser.add_option('--upload', action='store_true') + options, args = parser.parse_args(args) + if args: + parser.error('Unrecognized args: %s' % args) + if options.upload: + print('*** Presubmit checks for UPLOAD would report: ***') + return not DoPresubmitChecks(change_info, False, False) + else: + print('*** Presubmit checks for COMMIT would report: ***') + return not DoPresubmitChecks(change_info, True, False) def TryChange(change_info, args, swallow_exception): diff --git a/tests/gcl_unittest.py b/tests/gcl_unittest.py index b0e8c5783..68534c3e6 100755 --- a/tests/gcl_unittest.py +++ b/tests/gcl_unittest.py @@ -57,9 +57,9 @@ class GclUnittest(GclTestsBase): 'RunShell', 'RunShellWithReturnCode', 'SVN', 'TryChange', 'UnknownFiles', 'Warn', 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass', - 'json', 'main', 'need_change', 'need_change_and_args', 'no_args', 'os', - 'random', 're', 'string', 'subprocess', 'sys', 'tempfile', - 'time', 'upload', 'urllib2', + 'json', 'main', 'need_change', 'need_change_and_args', 'no_args', + 'optparse', 'os', 'random', 're', 'string', 'subprocess', 'sys', + 'tempfile', 'time', 'upload', 'urllib2', ] # If this test fails, you should add the relevant test. self.compareMembers(gcl, members)