Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
| 7 | 7 |
| 8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
| 9 | 9 |
| 10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 content) | 311 content) |
| 312 break | 312 break |
| 313 if response.status < 500 or try_count >= 2: | 313 if response.status < 500 or try_count >= 2: |
| 314 raise httplib2.HttpLib2Error(content) | 314 raise httplib2.HttpLib2Error(content) |
| 315 | 315 |
| 316 # status >= 500 means transient failures. | 316 # status >= 500 means transient failures. |
| 317 logging.debug('Transient errors when triggering tryjobs. Will retry.') | 317 logging.debug('Transient errors when triggering tryjobs. Will retry.') |
| 318 time.sleep(0.5 + 1.5*try_count) | 318 time.sleep(0.5 + 1.5*try_count) |
| 319 | 319 |
| 320 print '\n'.join(print_text) | 320 print '\n'.join(print_text) |
| 321 | 321 |
| 322 | 322 |
| 323 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): | 323 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): |
| 324 """Return the corresponding git ref if |base_url| together with |glob_spec| | 324 """Return the corresponding git ref if |base_url| together with |glob_spec| |
| 325 matches the full |url|. | 325 matches the full |url|. |
| 326 | 326 |
| 327 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). | 327 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). |
| 328 """ | 328 """ |
| 329 fetch_suburl, as_ref = glob_spec.split(':') | 329 fetch_suburl, as_ref = glob_spec.split(':') |
| 330 if allow_wildcards: | 330 if allow_wildcards: |
| 331 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl) | 331 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl) |
| (...skipping 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2704 return PatchIssue(issue_arg, options.reject, options.nocommit, | 2704 return PatchIssue(issue_arg, options.reject, options.nocommit, |
| 2705 options.directory, auth_config) | 2705 options.directory, auth_config) |
| 2706 | 2706 |
| 2707 | 2707 |
| 2708 def PatchIssue(issue_arg, reject, nocommit, directory, auth_config): | 2708 def PatchIssue(issue_arg, reject, nocommit, directory, auth_config): |
| 2709 # PatchIssue should never be called with a dirty tree. It is up to the | 2709 # PatchIssue should never be called with a dirty tree. It is up to the |
| 2710 # caller to check this, but just in case we assert here since the | 2710 # caller to check this, but just in case we assert here since the |
| 2711 # consequences of the caller not checking this could be dire. | 2711 # consequences of the caller not checking this could be dire. |
| 2712 assert(not git_common.is_dirty_git_tree('apply')) | 2712 assert(not git_common.is_dirty_git_tree('apply')) |
| 2713 | 2713 |
| 2714 if type(issue_arg) is int or issue_arg.isdigit(): | 2714 arg_is_issue_id = type(issue_arg) is int or issue_arg.isdigit() |
| 2715 if arg_is_issue_id: | |
| 2715 # Input is an issue id. Figure out the URL. | 2716 # Input is an issue id. Figure out the URL. |
| 2716 issue = int(issue_arg) | 2717 issue = int(issue_arg) |
| 2717 cl = Changelist(issue=issue, auth_config=auth_config) | 2718 cl = Changelist(issue=issue, auth_config=auth_config) |
| 2718 patchset = cl.GetMostRecentPatchset() | 2719 patchset = cl.GetMostRecentPatchset() |
| 2719 patch_data = cl.GetPatchSetDiff(issue, patchset) | 2720 patch_data = cl.GetPatchSetDiff(issue, patchset) |
| 2720 else: | 2721 else: |
| 2721 # Assume it's a URL to the patch. Default to https. | 2722 # Assume it's a URL to the patch. Default to https. |
| 2722 issue_url = gclient_utils.UpgradeToHttps(issue_arg) | 2723 issue_url = gclient_utils.UpgradeToHttps(issue_arg) |
| 2723 match = re.match(r'.*?/issue(\d+)_(\d+).diff', issue_url) | 2724 match = re.match(r'.*?/issue(\d+)_(\d+).diff', issue_url) |
| 2724 if not match: | 2725 if not match: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2757 cmd.append('--3way') | 2758 cmd.append('--3way') |
| 2758 try: | 2759 try: |
| 2759 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(), | 2760 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(), |
| 2760 stdin=patch_data, stdout=subprocess2.VOID) | 2761 stdin=patch_data, stdout=subprocess2.VOID) |
| 2761 except subprocess2.CalledProcessError: | 2762 except subprocess2.CalledProcessError: |
| 2762 print 'Failed to apply the patch' | 2763 print 'Failed to apply the patch' |
| 2763 return 1 | 2764 return 1 |
| 2764 | 2765 |
| 2765 # If we had an issue, commit the current state and register the issue. | 2766 # If we had an issue, commit the current state and register the issue. |
| 2766 if not nocommit: | 2767 if not nocommit: |
| 2767 RunGit(['commit', '-m', (cl.GetDescription() + '\n\n' + | 2768 commit_message = cl.GetDescription() + '\n\n' if arg_is_issue_id else '' |
|
agable
2015/06/01 21:22:53
Rather than removing functionality (replacing the
kjellander_chromium
2015/06/02 07:47:09
Good idea. That was pretty simple to do by just up
| |
| 2769 RunGit(['commit', '-m', (commit_message + | |
| 2768 'patch from issue %(i)s at patchset ' | 2770 'patch from issue %(i)s at patchset ' |
| 2769 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)' | 2771 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)' |
| 2770 % {'i': issue, 'p': patchset})]) | 2772 % {'i': issue, 'p': patchset})]) |
| 2771 cl = Changelist(auth_config=auth_config) | 2773 cl = Changelist(auth_config=auth_config) |
| 2772 cl.SetIssue(issue) | 2774 cl.SetIssue(issue) |
| 2773 cl.SetPatchset(patchset) | 2775 cl.SetPatchset(patchset) |
| 2774 print "Committed patch locally." | 2776 print "Committed patch locally." |
| 2775 else: | 2777 else: |
| 2776 print "Patch applied to index." | 2778 print "Patch applied to index." |
| 2777 return 0 | 2779 return 0 |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3343 if __name__ == '__main__': | 3345 if __name__ == '__main__': |
| 3344 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3346 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 3345 # unit testing. | 3347 # unit testing. |
| 3346 fix_encoding.fix_encoding() | 3348 fix_encoding.fix_encoding() |
| 3347 colorama.init() | 3349 colorama.init() |
| 3348 try: | 3350 try: |
| 3349 sys.exit(main(sys.argv[1:])) | 3351 sys.exit(main(sys.argv[1:])) |
| 3350 except KeyboardInterrupt: | 3352 except KeyboardInterrupt: |
| 3351 sys.stderr.write('interrupted\n') | 3353 sys.stderr.write('interrupted\n') |
| 3352 sys.exit(1) | 3354 sys.exit(1) |
| OLD | NEW |