From 42c7f667334ac06da96645011005a5d215446ba6 Mon Sep 17 00:00:00 2001 From: "joi@chromium.org" Date: Wed, 6 Oct 2010 23:52:46 +0000 Subject: [PATCH] Reuse gcl.py's code review settings when running [gcl try], as gcl is smarter about finding the most appropriate settings file. Before this change, I inadvertently did a [gcl try] on a chrome-internal change (it was a trivial change and not really secret, so no harm done). After this change, that won't be possible. Also, change breakpad to not upload the exception that is thrown when the user fails to provide correct log-on credentials. TEST=none BUG=none Review URL: http://codereview.chromium.org/3390013 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@61738 0039d316-1c4b-4281-b951-d872f2087c98 --- gcl.py | 3 +++ git-try | 19 ++++++++++++------- tests/trychange_unittest.py | 12 ++++++------ trychange.py | 31 ++++++++++++++++++++----------- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/gcl.py b/gcl.py index 8aab876b0..e759970a8 100755 --- a/gcl.py +++ b/gcl.py @@ -1329,6 +1329,9 @@ def main(argv): print >> sys.stderr, 'Got an exception' print >> sys.stderr, str(e) return 1 + except upload.ClientLoginError, e: + print >> sys.stderr, 'Got an exception logging in to Rietveld' + print >> sys.stderr, str(e) except urllib2.HTTPError, e: if e.code != 500: raise diff --git a/git-try b/git-try index a4c9fbbbf..34ff5981b 100755 --- a/git-try +++ b/git-try @@ -11,6 +11,7 @@ import breakpad import gclient_utils from scm import GIT +import third_party.upload import trychange @@ -51,10 +52,14 @@ if __name__ == '__main__': args.extend(['--rietveld_url', GetRietveldServerUrl()]) # Hack around a limitation in logging. logging.getLogger().handlers = [] - sys.exit(trychange.TryChange( - args, file_list=[], swallow_exception=False, - prog='git-try', - extra_epilog='\n' - 'git-try will diff against your tracked branch and will ' - 'detect your rietveld\n' - 'code review if you are using git-cl\n')) + try: + sys.exit(trychange.TryChange( + args, file_list=[], swallow_exception=False, + prog='git-try', + extra_epilog='\n' + 'git-try will diff against your tracked branch and will ' + 'detect your rietveld\n' + 'code review if you are using git-cl\n')) + except third_party.upload.ClientLoginError, e: + print('Got an exception while trying to log in to Rietveld.') + print(str(e)) diff --git a/tests/trychange_unittest.py b/tests/trychange_unittest.py index e496ec6ae..2ebfd9240 100755 --- a/tests/trychange_unittest.py +++ b/tests/trychange_unittest.py @@ -40,12 +40,12 @@ class TryChangeUnittest(TryChangeTestsBase): """General trychange.py tests.""" def testMembersChanged(self): members = [ - 'EPILOG', 'EscapeDot', 'GIT', 'GuessVCS', 'GetMungedDiff', - 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess', - 'SCM', 'SVN', 'TryChange', 'USAGE', - 'breakpad', 'datetime', 'errno', 'gclient_utils', 'getpass', 'json', - 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil', 'sys', - 'tempfile', 'urllib', + 'EPILOG', 'EscapeDot', 'GIT', 'GuessVCS', 'GetMungedDiff', 'HELP_STRING', + 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess', 'SCM', 'SVN', + 'TryChange', 'USAGE', + 'breakpad', 'datetime', 'errno', 'gcl', 'gclient_utils', 'getpass', + 'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil', + 'sys', 'tempfile', 'urllib', ] # If this test fails, you should add the relevant test. self.compareMembers(trychange, members) diff --git a/trychange.py b/trychange.py index 289b0fe4e..c381b1058 100755 --- a/trychange.py +++ b/trychange.py @@ -33,6 +33,11 @@ try: except ImportError: pass +try: + import gcl +except ImportError: + gcl = None + import gclient_utils import scm @@ -106,17 +111,21 @@ class SCM(object): def GetCodeReviewSetting(self, key): """Returns a value for the given key for this repository. - Uses gcl-style settings from the repository.""" - if self.codereview_settings is None: - self.codereview_settings = {} - settings_file = self.ReadRootFile(self.codereview_settings_file) - if settings_file: - for line in settings_file.splitlines(): - if not line or line.lstrip().startswith('#'): - continue - k, v = line.split(":", 1) - self.codereview_settings[k.strip()] = v.strip() - return self.codereview_settings.get(key, '') + Uses gcl-style settings from the repository. + """ + if gcl: + return gcl.GetCodeReviewSetting(key) + else: + if self.codereview_settings is None: + self.codereview_settings = {} + settings_file = self.ReadRootFile(self.codereview_settings_file) + if settings_file: + for line in settings_file.splitlines(): + if not line or line.lstrip().startswith('#'): + continue + k, v = line.split(":", 1) + self.codereview_settings[k.strip()] = v.strip() + return self.codereview_settings.get(key, '') def _GclStyleSettings(self): """Set default settings based on the gcl-style settings from the