| OLD | NEW |
| 1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import subprocess | 7 import subprocess |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 import breakpad | 10 import breakpad |
| 11 | 11 |
| 12 from git_cl_repo import git_cl | 12 from git_cl_repo import git_cl |
| 13 from git_cl_repo import upload | 13 from git_cl_repo import upload |
| 14 | 14 |
| 15 import presubmit_support | 15 import presubmit_support |
| 16 import scm | 16 import scm |
| 17 import watchlists | 17 import watchlists |
| 18 | 18 |
| 19 # Really ugly hack to quiet upload.py | 19 # Really ugly hack to quiet upload.py |
| 20 upload.verbosity = 0 | 20 upload.verbosity = 0 |
| 21 | 21 |
| 22 def Backquote(cmd, cwd=None): | 22 def Backquote(cmd, cwd=None): |
| 23 """Like running `cmd` in a shell script.""" | 23 """Like running `cmd` in a shell script.""" |
| 24 return subprocess.Popen(cmd, | 24 return subprocess.Popen(cmd, |
| 25 cwd=cwd, | 25 cwd=cwd, |
| 26 stdout=subprocess.PIPE).communicate()[0].strip() | 26 stdout=subprocess.PIPE).communicate()[0].strip() |
| 27 | 27 |
| 28 def BackquoteAsInteger(cmd, cwd=None): | 28 def ConvertToInteger(input): |
| 29 """Like Backquote, but returns either an int or None.""" | 29 """Convert a string to integer, but returns either an int or None.""" |
| 30 try: | 30 try: |
| 31 return int(Backquote(cmd, cwd)) | 31 return int(input) |
| 32 except ValueError: | 32 except TypeError, ValueError: |
| 33 return None | 33 return None |
| 34 | 34 |
| 35 | 35 |
| 36 class ChangeOptions: | 36 class ChangeOptions: |
| 37 def __init__(self, commit=None, upstream_branch=None): | 37 def __init__(self, commit=None, upstream_branch=None): |
| 38 self.commit = commit | 38 self.commit = commit |
| 39 self.verbose = None | 39 self.verbose = None |
| 40 self.default_presubmit = None | 40 self.default_presubmit = None |
| 41 self.may_prompt = None | 41 self.may_prompt = None |
| 42 | 42 |
| 43 root = Backquote(['git', 'rev-parse', '--show-cdup']) | 43 root = Backquote(['git', 'rev-parse', '--show-cdup']) |
| 44 if not root: | 44 if not root: |
| 45 root = "." | 45 root = "." |
| 46 absroot = os.path.abspath(root) | 46 absroot = os.path.abspath(root) |
| 47 if not root: | 47 if not root: |
| 48 raise Exception("Could not get root directory.") | 48 raise Exception("Could not get root directory.") |
| 49 # We use the sha1 of HEAD as a name of this change. | 49 # We use the sha1 of HEAD as a name of this change. |
| 50 name = Backquote(['git', 'rev-parse', 'HEAD']) | 50 name = Backquote(['git', 'rev-parse', 'HEAD']) |
| 51 files = scm.GIT.CaptureStatus([root], upstream_branch) | 51 files = scm.GIT.CaptureStatus([root], upstream_branch) |
| 52 cl = git_cl.Changelist() | 52 cl = git_cl.Changelist() |
| 53 issue = cl.GetIssue() | 53 issue = ConvertToInteger(cl.GetIssue()) |
| 54 patchset = cl.GetPatchset() | 54 patchset = ConvertToInteger(cl.GetPatchset()) |
| 55 if issue: | 55 if issue: |
| 56 description = cl.GetDescription() | 56 description = cl.GetDescription() |
| 57 else: | 57 else: |
| 58 # If the change was never uploaded, use the log messages of all commits | 58 # If the change was never uploaded, use the log messages of all commits |
| 59 # up to the branch point, as git cl upload will prefill the description | 59 # up to the branch point, as git cl upload will prefill the description |
| 60 # with these log messages. | 60 # with these log messages. |
| 61 description = Backquote(['git', 'log', '--pretty=format:%s%n%n%b', | 61 description = Backquote(['git', 'log', '--pretty=format:%s%n%n%b', |
| 62 '%s...' % (upstream_branch)]) | 62 '%s...' % (upstream_branch)]) |
| 63 self.change = presubmit_support.GitChange(name, description, absroot, files, | 63 self.change = presubmit_support.GitChange(name, description, absroot, files, |
| 64 issue, patchset) | 64 issue, patchset) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 82 if presubmit_support.DoPresubmitChecks(options.change, | 82 if presubmit_support.DoPresubmitChecks(options.change, |
| 83 options.commit, | 83 options.commit, |
| 84 options.verbose, | 84 options.verbose, |
| 85 sys.stdout, | 85 sys.stdout, |
| 86 sys.stdin, | 86 sys.stdin, |
| 87 options.default_presubmit, | 87 options.default_presubmit, |
| 88 options.may_prompt): | 88 options.may_prompt): |
| 89 sys.exit(0) | 89 sys.exit(0) |
| 90 else: | 90 else: |
| 91 sys.exit(1) | 91 sys.exit(1) |
| OLD | NEW |