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 2674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2685 DieWithError('Running editor failed') | 2685 DieWithError('Running editor failed') |
2686 lines = content.splitlines() | 2686 lines = content.splitlines() |
2687 | 2687 |
2688 # Strip off comments. | 2688 # Strip off comments. |
2689 clean_lines = [line.rstrip() for line in lines if not line.startswith('#')] | 2689 clean_lines = [line.rstrip() for line in lines if not line.startswith('#')] |
2690 if not clean_lines: | 2690 if not clean_lines: |
2691 DieWithError('No CL description, aborting') | 2691 DieWithError('No CL description, aborting') |
2692 self.set_description(clean_lines) | 2692 self.set_description(clean_lines) |
2693 | 2693 |
2694 def append_footer(self, line): | 2694 def append_footer(self, line): |
2695 if self._description_lines: | 2695 """Adds a footer line to the description. |
2696 # Add an empty line if either the last line or the new line isn't a tag. | 2696 |
2697 last_line = self._description_lines[-1] | 2697 Differentiates legacy "KEY=xxx" footers (used to be called tags) and |
2698 if (not presubmit_support.Change.TAG_LINE_RE.match(last_line) or | 2698 Gerrit's footers in the form of "Footer-Key: footer any value" and ensures |
2699 not presubmit_support.Change.TAG_LINE_RE.match(line)): | 2699 that Gerrit footers are always at the end. |
2700 self._description_lines.append('') | 2700 """ |
2701 self._description_lines.append(line) | 2701 parsed_footer_line = git_footers.parse_footer(line) |
| 2702 if parsed_footer_line: |
| 2703 # Line is a gerrit footer in the form: Footer-Key: any value. |
| 2704 # Thus, must be appended observing Gerrit footer rules. |
| 2705 self.set_description( |
| 2706 git_footers.add_footer(self.description, |
| 2707 key=parsed_footer_line[0], |
| 2708 value=parsed_footer_line[1])) |
| 2709 return |
| 2710 |
| 2711 if not self._description_lines: |
| 2712 self._description_lines.append(line) |
| 2713 return |
| 2714 |
| 2715 top_lines, gerrit_footers, _ = git_footers.split_footers(self.description) |
| 2716 if gerrit_footers: |
| 2717 # git_footers.split_footers ensures that there is an empty line before |
| 2718 # actual (gerrit) footers, if any. We have to keep it that way. |
| 2719 assert top_lines and top_lines[-1] == '' |
| 2720 top_lines, separator = top_lines[:-1], top_lines[-1:] |
| 2721 else: |
| 2722 separator = [] # No need for separator if there are no gerrit_footers. |
| 2723 |
| 2724 prev_line = top_lines[-1] if top_lines else '' |
| 2725 if (not presubmit_support.Change.TAG_LINE_RE.match(prev_line) or |
| 2726 not presubmit_support.Change.TAG_LINE_RE.match(line)): |
| 2727 top_lines.append('') |
| 2728 top_lines.append(line) |
| 2729 self._description_lines = top_lines + separator + gerrit_footers |
2702 | 2730 |
2703 def get_reviewers(self): | 2731 def get_reviewers(self): |
2704 """Retrieves the list of reviewers.""" | 2732 """Retrieves the list of reviewers.""" |
2705 matches = [re.match(self.R_LINE, line) for line in self._description_lines] | 2733 matches = [re.match(self.R_LINE, line) for line in self._description_lines] |
2706 reviewers = [match.group(2).strip() for match in matches if match] | 2734 reviewers = [match.group(2).strip() for match in matches if match] |
2707 return cleanup_list(reviewers) | 2735 return cleanup_list(reviewers) |
2708 | 2736 |
2709 | 2737 |
2710 def get_approving_reviewers(props): | 2738 def get_approving_reviewers(props): |
2711 """Retrieves the reviewers that approved a CL from the issue properties with | 2739 """Retrieves the reviewers that approved a CL from the issue properties with |
(...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4907 if __name__ == '__main__': | 4935 if __name__ == '__main__': |
4908 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4936 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4909 # unit testing. | 4937 # unit testing. |
4910 fix_encoding.fix_encoding() | 4938 fix_encoding.fix_encoding() |
4911 setup_color.init() | 4939 setup_color.init() |
4912 try: | 4940 try: |
4913 sys.exit(main(sys.argv[1:])) | 4941 sys.exit(main(sys.argv[1:])) |
4914 except KeyboardInterrupt: | 4942 except KeyboardInterrupt: |
4915 sys.stderr.write('interrupted\n') | 4943 sys.stderr.write('interrupted\n') |
4916 sys.exit(1) | 4944 sys.exit(1) |
OLD | NEW |