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 |
| 13 from git_cl_repo import upload |
| 14 |
12 import presubmit_support | 15 import presubmit_support |
13 import scm | 16 import scm |
14 import watchlists | 17 import watchlists |
15 | 18 |
| 19 # Really ugly hack to quiet upload.py |
| 20 upload.verbosity = 0 |
| 21 |
16 def Backquote(cmd, cwd=None): | 22 def Backquote(cmd, cwd=None): |
17 """Like running `cmd` in a shell script.""" | 23 """Like running `cmd` in a shell script.""" |
18 return subprocess.Popen(cmd, | 24 return subprocess.Popen(cmd, |
19 cwd=cwd, | 25 cwd=cwd, |
20 stdout=subprocess.PIPE).communicate()[0].strip() | 26 stdout=subprocess.PIPE).communicate()[0].strip() |
21 | 27 |
22 def BackquoteAsInteger(cmd, cwd=None): | 28 def ConvertToInteger(input): |
23 """Like Backquote, but returns either an int or None.""" | 29 """Convert a string to integer, but returns either an int or None.""" |
24 try: | 30 try: |
25 return int(Backquote(cmd, cwd)) | 31 return int(input) |
26 except ValueError: | 32 except TypeError, ValueError: |
27 return None | 33 return None |
28 | 34 |
29 | 35 |
30 class ChangeOptions: | 36 class ChangeOptions: |
31 def __init__(self, commit=None, upstream_branch=None): | 37 def __init__(self, commit=None, upstream_branch=None): |
32 self.commit = commit | 38 self.commit = commit |
33 self.verbose = None | 39 self.verbose = None |
34 self.default_presubmit = None | 40 self.default_presubmit = None |
35 self.may_prompt = None | 41 self.may_prompt = None |
36 | 42 |
37 root = Backquote(['git', 'rev-parse', '--show-cdup']) | 43 root = Backquote(['git', 'rev-parse', '--show-cdup']) |
38 if not root: | 44 if not root: |
39 root = "." | 45 root = "." |
40 absroot = os.path.abspath(root) | 46 absroot = os.path.abspath(root) |
41 if not root: | 47 if not root: |
42 raise Exception("Could not get root directory.") | 48 raise Exception("Could not get root directory.") |
43 # 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. |
44 name = Backquote(['git', 'rev-parse', 'HEAD']) | 50 name = Backquote(['git', 'rev-parse', 'HEAD']) |
45 files = scm.GIT.CaptureStatus([root], upstream_branch) | 51 files = scm.GIT.CaptureStatus([root], upstream_branch) |
46 issue = BackquoteAsInteger(['git', 'cl', 'status', '--field=id']) | 52 cl = git_cl.Changelist() |
47 patchset = BackquoteAsInteger(['git', 'cl', 'status', '--field=patch']) | 53 issue = ConvertToInteger(cl.GetIssue()) |
| 54 patchset = ConvertToInteger(cl.GetPatchset()) |
48 if issue: | 55 if issue: |
49 description = Backquote(['git', 'cl', 'status', '--field=desc']) | 56 description = cl.GetDescription() |
50 else: | 57 else: |
51 # 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 |
52 # 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 |
53 # with these log messages. | 60 # with these log messages. |
54 description = Backquote(['git', 'log', '--pretty=format:%s%n%n%b', | 61 description = Backquote(['git', 'log', '--pretty=format:%s%n%n%b', |
55 '%s...' % (upstream_branch)]) | 62 '%s...' % (upstream_branch)]) |
56 self.change = presubmit_support.GitChange(name, description, absroot, files, | 63 self.change = presubmit_support.GitChange(name, description, absroot, files, |
57 issue, patchset) | 64 issue, patchset) |
58 | 65 |
59 | 66 |
(...skipping 15 matching lines...) Expand all Loading... |
75 if presubmit_support.DoPresubmitChecks(options.change, | 82 if presubmit_support.DoPresubmitChecks(options.change, |
76 options.commit, | 83 options.commit, |
77 options.verbose, | 84 options.verbose, |
78 sys.stdout, | 85 sys.stdout, |
79 sys.stdin, | 86 sys.stdin, |
80 options.default_presubmit, | 87 options.default_presubmit, |
81 options.may_prompt): | 88 options.may_prompt): |
82 sys.exit(0) | 89 sys.exit(0) |
83 else: | 90 else: |
84 sys.exit(1) | 91 sys.exit(1) |
OLD | NEW |