Commit 96b6b3bf authored by maruel@chromium.org's avatar maruel@chromium.org

Revert both r78355 and r78329

"Fix regression introduced in r78329."
"Modify gcl to use suggested_reviewer output from presubmit_support."

My quick fix was insufficient.

TBR=dpranke

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@78356 0039d316-1c4b-4281-b951-d872f2087c98
parent dbe4058f
...@@ -39,10 +39,7 @@ import breakpad # pylint: disable=W0611 ...@@ -39,10 +39,7 @@ import breakpad # pylint: disable=W0611
# gcl now depends on gclient. # gcl now depends on gclient.
from scm import SVN from scm import SVN
import gclient_utils import gclient_utils
import owners
import presubmit_support
__version__ = '1.2' __version__ = '1.2'
...@@ -73,7 +70,6 @@ FILES_CACHE = {} ...@@ -73,7 +70,6 @@ FILES_CACHE = {}
DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)"
DEFAULT_LINT_IGNORE_REGEX = r"$^" DEFAULT_LINT_IGNORE_REGEX = r"$^"
REVIEWERS_REGEX = r'\s*R=(.+)'
def CheckHomeForFile(filename): def CheckHomeForFile(filename):
"""Checks the users home dir for the existence of the given file. Returns """Checks the users home dir for the existence of the given file. Returns
...@@ -290,10 +286,7 @@ class ChangeInfo(object): ...@@ -290,10 +286,7 @@ class ChangeInfo(object):
self.name = name self.name = name
self.issue = int(issue) self.issue = int(issue)
self.patchset = int(patchset) self.patchset = int(patchset)
self._description = None self.description = description
self._subject = None
self._reviewers = None
self._set_description(description)
if files is None: if files is None:
files = [] files = []
self._files = files self._files = files
...@@ -305,44 +298,6 @@ class ChangeInfo(object): ...@@ -305,44 +298,6 @@ class ChangeInfo(object):
# Set the default value. # Set the default value.
self.rietveld = GetCodeReviewSetting('CODE_REVIEW_SERVER') self.rietveld = GetCodeReviewSetting('CODE_REVIEW_SERVER')
def _get_description(self):
return self._description
def _set_description(self, description):
# TODO(dpranke): Cloned from git_cl.py. These should be shared.
if not description:
self._description = description
return
parsed_lines = []
reviewers_re = re.compile(REVIEWERS_REGEX)
reviewers = ''
subject = ''
for l in description.splitlines():
if not subject:
subject = l
matched_reviewers = reviewers_re.match(l)
if matched_reviewers:
reviewers = matched_reviewers.group(1)
parsed_lines.append(l)
if len(subject) > 100:
subject = subject[:97] + '...'
self._subject = subject
self._reviewers = reviewers
self._description = '\n'.join(parsed_lines)
description = property(_get_description, _set_description)
@property
def reviewers(self):
return self._reviewers
@property
def subject(self):
return self._subject
def NeedsUpload(self): def NeedsUpload(self):
return self.needs_upload return self.needs_upload
...@@ -759,16 +714,10 @@ def GenerateDiff(files, root=None): ...@@ -759,16 +714,10 @@ def GenerateDiff(files, root=None):
def OptionallyDoPresubmitChecks(change_info, committing, args): def OptionallyDoPresubmitChecks(change_info, committing, args):
if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"): if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"):
return presubmit_support.PresubmitOutput() return True
return DoPresubmitChecks(change_info, committing, True) return DoPresubmitChecks(change_info, committing, True)
def suggest_reviewers(change_info, affected_files):
owners_db = owners.Database(change_info.GetLocalRoot(), fopen=file,
os_path=os.path)
return owners_db.reviewers_for(affected_files)
def defer_attributes(a, b): def defer_attributes(a, b):
"""Copy attributes from an object (like a function) to another.""" """Copy attributes from an object (like a function) to another."""
for x in dir(a): for x in dir(a):
...@@ -848,9 +797,7 @@ def CMDupload(change_info, args): ...@@ -848,9 +797,7 @@ def CMDupload(change_info, args):
if not change_info.GetFiles(): if not change_info.GetFiles():
print "Nothing to upload, changelist is empty." print "Nothing to upload, changelist is empty."
return 0 return 0
if not OptionallyDoPresubmitChecks(change_info, False, args):
output = OptionallyDoPresubmitChecks(change_info, False, args)
if not output.should_continue():
return 1 return 1
no_watchlists = (FilterFlag(args, "--no_watchlists") or no_watchlists = (FilterFlag(args, "--no_watchlists") or
FilterFlag(args, "--no-watchlists")) FilterFlag(args, "--no-watchlists"))
...@@ -861,13 +808,6 @@ def CMDupload(change_info, args): ...@@ -861,13 +808,6 @@ def CMDupload(change_info, args):
upload_arg = ["upload.py", "-y"] upload_arg = ["upload.py", "-y"]
upload_arg.append("--server=%s" % change_info.rietveld) upload_arg.append("--server=%s" % change_info.rietveld)
reviewers = change_info.reviewers or output.reviewers
if (reviewers and
not any(arg.startswith('-r') or arg.startswith('--reviewer') for
arg in args)):
upload_arg.append('--reviewers=%s' % ','.join(reviewers))
upload_arg.extend(args) upload_arg.extend(args)
desc_file = "" desc_file = ""
...@@ -901,8 +841,15 @@ def CMDupload(change_info, args): ...@@ -901,8 +841,15 @@ def CMDupload(change_info, args):
if cc_list: if cc_list:
upload_arg.append("--cc=" + cc_list) upload_arg.append("--cc=" + cc_list)
upload_arg.append("--description_file=" + desc_file + "") upload_arg.append("--description_file=" + desc_file + "")
if change_info.subject: if change_info.description:
upload_arg.append("--message=" + change_info.subject) subject = change_info.description[:77]
if subject.find("\r\n") != -1:
subject = subject[:subject.find("\r\n")]
if subject.find("\n") != -1:
subject = subject[:subject.find("\n")]
if len(change_info.description) > 77:
subject = subject + "..."
upload_arg.append("--message=" + subject)
if GetCodeReviewSetting("PRIVATE") == "True": if GetCodeReviewSetting("PRIVATE") == "True":
upload_arg.append("--private") upload_arg.append("--private")
...@@ -1034,7 +981,7 @@ def CMDcommit(change_info, args): ...@@ -1034,7 +981,7 @@ def CMDcommit(change_info, args):
revision = re.compile(".*?\nCommitted revision (\d+)", revision = re.compile(".*?\nCommitted revision (\d+)",
re.DOTALL).match(output).group(1) re.DOTALL).match(output).group(1)
viewvc_url = GetCodeReviewSetting("VIEW_VC") viewvc_url = GetCodeReviewSetting("VIEW_VC")
change_info.description += '\n' change_info.description = change_info.description + '\n'
if viewvc_url: if viewvc_url:
change_info.description += "\nCommitted: " + viewvc_url + revision change_info.description += "\nCommitted: " + viewvc_url + revision
change_info.CloseIssue() change_info.CloseIssue()
...@@ -1096,13 +1043,6 @@ def CMDchange(args): ...@@ -1096,13 +1043,6 @@ def CMDchange(args):
affected_files = [x for x in other_files if file_re.match(x[0])] affected_files = [x for x in other_files if file_re.match(x[0])]
unaffected_files = [x for x in other_files if not file_re.match(x[0])] unaffected_files = [x for x in other_files if not file_re.match(x[0])]
suggested_reviewers = suggest_reviewers(change_info, affected_files)
if suggested_reviewers:
reviewers_re = re.compile(REVIEWERS_REGEX)
if not any(
reviewers_re.match(l) for l in description.splitlines()):
description += '\nR=' + ','.join(suggested_reviewers) + '\n'
separator1 = ("\n---All lines above this line become the description.\n" separator1 = ("\n---All lines above this line become the description.\n"
"---Repository Root: " + change_info.GetLocalRoot() + "\n" "---Repository Root: " + change_info.GetLocalRoot() + "\n"
"---Paths in this changelist (" + change_info.name + "):\n") "---Paths in this changelist (" + change_info.name + "):\n")
...@@ -1224,6 +1164,8 @@ def CMDlint(change_info, args): ...@@ -1224,6 +1164,8 @@ def CMDlint(change_info, args):
def DoPresubmitChecks(change_info, committing, may_prompt): def DoPresubmitChecks(change_info, committing, may_prompt):
"""Imports presubmit, then calls presubmit.DoPresubmitChecks.""" """Imports presubmit, then calls presubmit.DoPresubmitChecks."""
# Need to import here to avoid circular dependency.
import presubmit_support
root_presubmit = GetCachedFile('PRESUBMIT.py', use_root=True) root_presubmit = GetCachedFile('PRESUBMIT.py', use_root=True)
change = presubmit_support.SvnChange(change_info.name, change = presubmit_support.SvnChange(change_info.name,
change_info.description, change_info.description,
...@@ -1237,14 +1179,13 @@ def DoPresubmitChecks(change_info, committing, may_prompt): ...@@ -1237,14 +1179,13 @@ def DoPresubmitChecks(change_info, committing, may_prompt):
output_stream=sys.stdout, output_stream=sys.stdout,
input_stream=sys.stdin, input_stream=sys.stdin,
default_presubmit=root_presubmit, default_presubmit=root_presubmit,
may_prompt=may_prompt, may_prompt=may_prompt)
tbr=False,
host_url=change_info.rietveld)
if not output.should_continue() and may_prompt: if not output.should_continue() and may_prompt:
# TODO(dpranke): move into DoPresubmitChecks(), unify cmd line args. # TODO(dpranke): move into DoPresubmitChecks(), unify cmd line args.
print "\nPresubmit errors, can't continue (use --no_presubmit to bypass)" print "\nPresubmit errors, can't continue (use --no_presubmit to bypass)"
return output # TODO(dpranke): Return the output object and make use of it.
return output.should_continue()
@no_args @no_args
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
from super_mox import mox, SuperMoxTestBase from super_mox import mox, SuperMoxTestBase
import gcl import gcl
import presubmit_support
class GclTestsBase(SuperMoxTestBase): class GclTestsBase(SuperMoxTestBase):
...@@ -57,14 +56,13 @@ class GclUnittest(GclTestsBase): ...@@ -57,14 +56,13 @@ class GclUnittest(GclTestsBase):
'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir',
'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles',
'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG',
'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX', 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT',
'RunShell', 'RunShellWithReturnCode', 'SVN', 'RunShell', 'RunShellWithReturnCode', 'SVN',
'TryChange', 'UnknownFiles', 'Warn', 'TryChange', 'UnknownFiles', 'Warn',
'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass', 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass',
'json', 'main', 'need_change', 'need_change_and_args', 'no_args', 'json', 'main', 'need_change', 'need_change_and_args', 'no_args',
'optparse', 'os', 'owners', 'presubmit_support', 'random', 're', 'optparse', 'os', 'random', 're', 'string', 'subprocess', 'sys',
'string', 'subprocess', 'suggest_reviewers', 'sys', 'tempfile', 'time', 'tempfile', 'time', 'upload', 'urllib2',
'upload', 'urllib2',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(gcl, members) self.compareMembers(gcl, members)
...@@ -151,8 +149,7 @@ class ChangeInfoUnittest(GclTestsBase): ...@@ -151,8 +149,7 @@ class ChangeInfoUnittest(GclTestsBase):
'NeedsUpload', 'PrimeLint', 'Save', 'SendToRietveld', 'NeedsUpload', 'PrimeLint', 'Save', 'SendToRietveld',
'UpdateRietveldDescription', 'UpdateRietveldDescription',
'description', 'issue', 'name', 'description', 'issue', 'name',
'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', 'needs_upload', 'patch', 'patchset', 'rietveld',
'subject'
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers( self.compareMembers(
...@@ -261,8 +258,7 @@ class CMDuploadUnittest(GclTestsBase): ...@@ -261,8 +258,7 @@ class CMDuploadUnittest(GclTestsBase):
change_info.patch = None change_info.patch = None
change_info.rietveld = 'my_server' change_info.rietveld = 'my_server'
files = [item[1] for item in change_info.files] files = [item[1] for item in change_info.files]
output = presubmit_support.PresubmitOutput() gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output)
#gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.os.getcwd().AndReturn('somewhere') gcl.os.getcwd().AndReturn('somewhere')
change_info.GetFiles().AndReturn(change_info.files) change_info.GetFiles().AndReturn(change_info.files)
...@@ -297,8 +293,7 @@ class CMDuploadUnittest(GclTestsBase): ...@@ -297,8 +293,7 @@ class CMDuploadUnittest(GclTestsBase):
self.fake_root_dir, 'my_server') self.fake_root_dir, 'my_server')
self.mox.StubOutWithMock(change_info, 'Save') self.mox.StubOutWithMock(change_info, 'Save')
change_info.Save() change_info.Save()
output = presubmit_support.PresubmitOutput() gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output)
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description) gcl.os.write(42, change_info.description)
gcl.os.close(42) gcl.os.close(42)
...@@ -332,8 +327,7 @@ class CMDuploadUnittest(GclTestsBase): ...@@ -332,8 +327,7 @@ class CMDuploadUnittest(GclTestsBase):
self.fake_root_dir, 'my_server') self.fake_root_dir, 'my_server')
self.mox.StubOutWithMock(change_info, 'Save') self.mox.StubOutWithMock(change_info, 'Save')
change_info.Save() change_info.Save()
output = presubmit_support.PresubmitOutput() gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
gcl.DoPresubmitChecks(change_info, False, True).AndReturn(output)
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description) gcl.os.write(42, change_info.description)
gcl.os.close(42) gcl.os.close(42)
......
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