Commit ed8b178c authored by msb@chromium.org's avatar msb@chromium.org

git_cl_hooks: get cl fields vi git_cl accessors instead of using backquote

This is part 2 of a 2-part change which fixes a bug where git-cl
hangs if ~/.codereview_upload_cookies does not exist. It is
actually waiting on user input for email/password (but you don't see the
prompt because it's happening in a subprocess).

This is a do-over of http://codereview.chromium.org/3622002.

Much thanks to Lei Zhang for fixing the bugs in the original CL. His
fixup CL was http://codereview.chromium.org/3541019.

BUG=none
TEST=Verified that the hang is fixed.

Wrote a quick pre-submit to test that issue and patchset are ints:
    http://codereview.chromium.org/3533020

Output:

** Presubmit Warnings **
Patchset is 1

Issue is 3533020

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@61957 0039d316-1c4b-4281-b951-d872f2087c98
parent b718983d
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -9,21 +9,27 @@ import sys
import breakpad
from git_cl_repo import git_cl
from git_cl_repo import upload
import presubmit_support
import scm
import watchlists
# Really ugly hack to quiet upload.py
upload.verbosity = 0
def Backquote(cmd, cwd=None):
"""Like running `cmd` in a shell script."""
return subprocess.Popen(cmd,
cwd=cwd,
stdout=subprocess.PIPE).communicate()[0].strip()
def BackquoteAsInteger(cmd, cwd=None):
"""Like Backquote, but returns either an int or None."""
def ConvertToInteger(input):
"""Convert a string to integer, but returns either an int or None."""
try:
return int(Backquote(cmd, cwd))
except ValueError:
return int(input)
except TypeError, ValueError:
return None
......@@ -43,10 +49,11 @@ class ChangeOptions:
# We use the sha1 of HEAD as a name of this change.
name = Backquote(['git', 'rev-parse', 'HEAD'])
files = scm.GIT.CaptureStatus([root], upstream_branch)
issue = BackquoteAsInteger(['git', 'cl', 'status', '--field=id'])
patchset = BackquoteAsInteger(['git', 'cl', 'status', '--field=patch'])
cl = git_cl.Changelist()
issue = ConvertToInteger(cl.GetIssue())
patchset = ConvertToInteger(cl.GetPatchset())
if issue:
description = Backquote(['git', 'cl', 'status', '--field=desc'])
description = cl.GetDescription()
else:
# If the change was never uploaded, use the log messages of all commits
# up to the branch point, as git cl upload will prefill the description
......
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