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 and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, | 1290 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, |
1291 default_presubmit=None, may_prompt=may_prompt, | 1291 default_presubmit=None, may_prompt=may_prompt, |
1292 rietveld_obj=self._codereview_impl.GetRieveldObjForPresubmit()) | 1292 rietveld_obj=self._codereview_impl.GetRieveldObjForPresubmit()) |
1293 except presubmit_support.PresubmitFailure, e: | 1293 except presubmit_support.PresubmitFailure, e: |
1294 DieWithError( | 1294 DieWithError( |
1295 ('%s\nMaybe your depot_tools is out of date?\n' | 1295 ('%s\nMaybe your depot_tools is out of date?\n' |
1296 'If all fails, contact maruel@') % e) | 1296 'If all fails, contact maruel@') % e) |
1297 | 1297 |
1298 def CMDPatchIssue(self, issue_arg, reject, nocommit, directory): | 1298 def CMDPatchIssue(self, issue_arg, reject, nocommit, directory): |
1299 """Fetches and applies the issue patch from codereview to local branch.""" | 1299 """Fetches and applies the issue patch from codereview to local branch.""" |
1300 if issue_arg.isdigit(): | 1300 if isinstance(issue_arg, (int, long)) or issue_arg.isdigit(): |
1301 parsed_issue_arg = _RietveldParsedIssueNumberArgument(int(issue_arg)) | 1301 parsed_issue_arg = _ParsedIssueNumberArgument(int(issue_arg)) |
1302 else: | 1302 else: |
1303 # Assume url. | 1303 # Assume url. |
1304 parsed_issue_arg = self._codereview_impl.ParseIssueURL( | 1304 parsed_issue_arg = self._codereview_impl.ParseIssueURL( |
1305 urlparse.urlparse(issue_arg)) | 1305 urlparse.urlparse(issue_arg)) |
1306 if not parsed_issue_arg or not parsed_issue_arg.valid: | 1306 if not parsed_issue_arg or not parsed_issue_arg.valid: |
1307 DieWithError('Failed to parse issue argument "%s". ' | 1307 DieWithError('Failed to parse issue argument "%s". ' |
1308 'Must be an issue number or a valid URL.' % issue_arg) | 1308 'Must be an issue number or a valid URL.' % issue_arg) |
1309 return self._codereview_impl.CMDPatchWithParsedIssue( | 1309 return self._codereview_impl.CMDPatchWithParsedIssue( |
1310 parsed_issue_arg, reject, nocommit, directory) | 1310 parsed_issue_arg, reject, nocommit, directory) |
1311 | 1311 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1596 | 1596 |
1597 # PatchIssue should never be called with a dirty tree. It is up to the | 1597 # PatchIssue should never be called with a dirty tree. It is up to the |
1598 # caller to check this, but just in case we assert here since the | 1598 # caller to check this, but just in case we assert here since the |
1599 # consequences of the caller not checking this could be dire. | 1599 # consequences of the caller not checking this could be dire. |
1600 assert(not git_common.is_dirty_git_tree('apply')) | 1600 assert(not git_common.is_dirty_git_tree('apply')) |
1601 assert(parsed_issue_arg.valid) | 1601 assert(parsed_issue_arg.valid) |
1602 self._changelist.issue = parsed_issue_arg.issue | 1602 self._changelist.issue = parsed_issue_arg.issue |
1603 if parsed_issue_arg.hostname: | 1603 if parsed_issue_arg.hostname: |
1604 self._rietveld_server = 'https://%s' % parsed_issue_arg.hostname | 1604 self._rietveld_server = 'https://%s' % parsed_issue_arg.hostname |
1605 | 1605 |
1606 if parsed_issue_arg.patch_url: | 1606 if (isinstance(parsed_issue_arg, _RietveldParsedIssueNumberArgument) and |
1607 parsed_issue_arg.patch_url): | |
1607 assert parsed_issue_arg.patchset | 1608 assert parsed_issue_arg.patchset |
1608 patchset = parsed_issue_arg.patchset | 1609 patchset = parsed_issue_arg.patchset |
1609 patch_data = urllib2.urlopen(parsed_issue_arg.patch_url).read() | 1610 patch_data = urllib2.urlopen(parsed_issue_arg.patch_url).read() |
1610 else: | 1611 else: |
1611 patchset = parsed_issue_arg.patchset or self.GetMostRecentPatchset() | 1612 patchset = parsed_issue_arg.patchset or self.GetMostRecentPatchset() |
1612 patch_data = self.GetPatchSetDiff(self.GetIssue(), patchset) | 1613 patch_data = self.GetPatchSetDiff(self.GetIssue(), patchset) |
1613 | 1614 |
1614 # Switch up to the top-level directory, if necessary, in preparation for | 1615 # Switch up to the top-level directory, if necessary, in preparation for |
1615 # applying the patch. | 1616 # applying the patch. |
1616 top = settings.GetRelativeRoot() | 1617 top = settings.GetRelativeRoot() |
(...skipping 2692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4309 cl = Changelist(auth_config=auth_config) | 4310 cl = Changelist(auth_config=auth_config) |
4310 issue = cl.GetIssue() | 4311 issue = cl.GetIssue() |
4311 branch = cl.GetBranch() | 4312 branch = cl.GetBranch() |
4312 if not issue: | 4313 if not issue: |
4313 DieWithError('No issue found for current branch (%s)' % branch) | 4314 DieWithError('No issue found for current branch (%s)' % branch) |
4314 TMP_BRANCH = 'git-cl-diff' | 4315 TMP_BRANCH = 'git-cl-diff' |
4315 base_branch = cl.GetCommonAncestorWithUpstream() | 4316 base_branch = cl.GetCommonAncestorWithUpstream() |
4316 | 4317 |
4317 # Create a new branch based on the merge-base | 4318 # Create a new branch based on the merge-base |
4318 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) | 4319 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) |
4320 # Update the cached branch in cl instance, to avoid overwriting original | |
Michael Achenbach
2016/04/07 09:35:53
This could do some more information hiding.
| |
4321 # branch properties. | |
4322 cl.branch = cl.branchref = None | |
4319 try: | 4323 try: |
4320 rtn = cl.CMDPatchIssue(issue, reject=False, nocommit=False, directory=None) | 4324 rtn = cl.CMDPatchIssue(issue, reject=False, nocommit=False, directory=None) |
4321 if rtn != 0: | 4325 if rtn != 0: |
4322 RunGit(['reset', '--hard']) | 4326 RunGit(['reset', '--hard']) |
4323 return rtn | 4327 return rtn |
4324 | 4328 |
4325 # Switch back to starting branch and diff against the temporary | 4329 # Switch back to starting branch and diff against the temporary |
4326 # branch containing the latest rietveld patch. | 4330 # branch containing the latest rietveld patch. |
4327 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--']) | 4331 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--']) |
4328 finally: | 4332 finally: |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4620 if __name__ == '__main__': | 4624 if __name__ == '__main__': |
4621 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4625 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4622 # unit testing. | 4626 # unit testing. |
4623 fix_encoding.fix_encoding() | 4627 fix_encoding.fix_encoding() |
4624 setup_color.init() | 4628 setup_color.init() |
4625 try: | 4629 try: |
4626 sys.exit(main(sys.argv[1:])) | 4630 sys.exit(main(sys.argv[1:])) |
4627 except KeyboardInterrupt: | 4631 except KeyboardInterrupt: |
4628 sys.stderr.write('interrupted\n') | 4632 sys.stderr.write('interrupted\n') |
4629 sys.exit(1) | 4633 sys.exit(1) |
OLD | NEW |