| 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 import json | 10 import json |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 | 1685 |
| 1686 | 1686 |
| 1687 @usage('<patch url or issue id>') | 1687 @usage('<patch url or issue id>') |
| 1688 def CMDpatch(parser, args): | 1688 def CMDpatch(parser, args): |
| 1689 """patch in a code review""" | 1689 """patch in a code review""" |
| 1690 parser.add_option('-b', dest='newbranch', | 1690 parser.add_option('-b', dest='newbranch', |
| 1691 help='create a new branch off trunk for the patch') | 1691 help='create a new branch off trunk for the patch') |
| 1692 parser.add_option('-f', action='store_true', dest='force', | 1692 parser.add_option('-f', action='store_true', dest='force', |
| 1693 help='with -b, clobber any existing branch') | 1693 help='with -b, clobber any existing branch') |
| 1694 parser.add_option('--reject', action='store_true', dest='reject', | 1694 parser.add_option('--reject', action='store_true', dest='reject', |
| 1695 help='failed patches spew .rej files rather than ' | 1695 help='allow failed patches and spew .rej files') |
| 1696 'attempting a 3-way merge') | |
| 1697 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 1696 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', |
| 1698 help="don't commit after patch applies") | 1697 help="don't commit after patch applies") |
| 1699 (options, args) = parser.parse_args(args) | 1698 (options, args) = parser.parse_args(args) |
| 1700 if len(args) != 1: | 1699 if len(args) != 1: |
| 1701 parser.print_help() | 1700 parser.print_help() |
| 1702 return 1 | 1701 return 1 |
| 1703 issue_arg = args[0] | 1702 issue_arg = args[0] |
| 1704 | 1703 |
| 1705 # TODO(maruel): Use apply_issue.py | 1704 # TODO(maruel): Use apply_issue.py |
| 1706 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 1705 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 ['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'], stdin=patch_data) | 1743 ['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'], stdin=patch_data) |
| 1745 except subprocess2.CalledProcessError: | 1744 except subprocess2.CalledProcessError: |
| 1746 DieWithError('Git patch mungling failed.') | 1745 DieWithError('Git patch mungling failed.') |
| 1747 logging.info(patch_data) | 1746 logging.info(patch_data) |
| 1748 # We use "git apply" to apply the patch instead of "patch" so that we can | 1747 # We use "git apply" to apply the patch instead of "patch" so that we can |
| 1749 # pick up file adds. | 1748 # pick up file adds. |
| 1750 # The --index flag means: also insert into the index (so we catch adds). | 1749 # The --index flag means: also insert into the index (so we catch adds). |
| 1751 cmd = ['git', '--no-pager', 'apply', '--index', '-p0'] | 1750 cmd = ['git', '--no-pager', 'apply', '--index', '-p0'] |
| 1752 if options.reject: | 1751 if options.reject: |
| 1753 cmd.append('--reject') | 1752 cmd.append('--reject') |
| 1754 else: | |
| 1755 cmd.append('--3way') | |
| 1756 try: | 1753 try: |
| 1757 subprocess2.check_call(cmd, stdin=patch_data, stdout=subprocess2.VOID) | 1754 subprocess2.check_call(cmd, stdin=patch_data, stdout=subprocess2.VOID) |
| 1758 except subprocess2.CalledProcessError: | 1755 except subprocess2.CalledProcessError: |
| 1759 DieWithError('Failed to apply the patch') | 1756 DieWithError('Failed to apply the patch') |
| 1760 | 1757 |
| 1761 # If we had an issue, commit the current state and register the issue. | 1758 # If we had an issue, commit the current state and register the issue. |
| 1762 if not options.nocommit: | 1759 if not options.nocommit: |
| 1763 RunGit(['commit', '-m', 'patch from issue %s' % issue]) | 1760 RunGit(['commit', '-m', 'patch from issue %s' % issue]) |
| 1764 cl = Changelist() | 1761 cl = Changelist() |
| 1765 cl.SetIssue(issue) | 1762 cl.SetIssue(issue) |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2096 GenUsage(parser, 'help') | 2093 GenUsage(parser, 'help') |
| 2097 return CMDhelp(parser, argv) | 2094 return CMDhelp(parser, argv) |
| 2098 | 2095 |
| 2099 | 2096 |
| 2100 if __name__ == '__main__': | 2097 if __name__ == '__main__': |
| 2101 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2098 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2102 # unit testing. | 2099 # unit testing. |
| 2103 fix_encoding.fix_encoding() | 2100 fix_encoding.fix_encoding() |
| 2104 colorama.init() | 2101 colorama.init() |
| 2105 sys.exit(main(sys.argv[1:])) | 2102 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |