Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: git_cl.py

Issue 2038673002: git cl description: avoid appending BUG= after Change-Id. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@bug-footer-fix
Patch Set: 80chars Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | tests/git_cl_test.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 elif options.rietveld: 2590 elif options.rietveld:
2591 options.forced_codereview = 'rietveld' 2591 options.forced_codereview = 'rietveld'
2592 2592
2593 2593
2594 class ChangeDescription(object): 2594 class ChangeDescription(object):
2595 """Contains a parsed form of the change description.""" 2595 """Contains a parsed form of the change description."""
2596 R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$' 2596 R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$'
2597 BUG_LINE = r'^[ \t]*(BUG)[ \t]*=[ \t]*(.*?)[ \t]*$' 2597 BUG_LINE = r'^[ \t]*(BUG)[ \t]*=[ \t]*(.*?)[ \t]*$'
2598 2598
2599 def __init__(self, description): 2599 def __init__(self, description):
2600 self._description_lines = (description or '').strip().splitlines() 2600 self._description_lines = (description or '').strip().splitlines()
tandrii(chromium) 2016/06/03 09:34:59 see this?
Sergiy Byelozyorov 2016/06/03 12:35:16 Acknowledged.
2601 2601
2602 @property # www.logilab.org/ticket/89786 2602 @property # www.logilab.org/ticket/89786
2603 def description(self): # pylint: disable=E0202 2603 def description(self): # pylint: disable=E0202
2604 return '\n'.join(self._description_lines) 2604 return '\n'.join(self._description_lines)
2605 2605
2606 def set_description(self, desc): 2606 def set_description(self, desc):
2607 if isinstance(desc, basestring): 2607 if isinstance(desc, basestring):
2608 lines = desc.splitlines() 2608 lines = desc.splitlines()
2609 else: 2609 else:
2610 lines = [line.rstrip() for line in desc] 2610 lines = [line.rstrip() for line in desc]
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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:
Sergiy Byelozyorov 2016/06/02 22:59:53 Why are you accessing self._description_lines here
tandrii(chromium) 2016/06/03 09:34:59 because _description_lines is actual primary stora
Sergiy Byelozyorov 2016/06/03 12:35:16 I was confused that you use both self._description
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 assert top_lines[-1] == '' and len(top_lines) >= 2
Sergiy Byelozyorov 2016/06/02 22:59:53 Please mention that this is also guaranteed in the
tandrii(chromium) 2016/06/03 09:34:59 Added comment.
Sergiy Byelozyorov 2016/06/03 12:35:16 Acknowledged.
2718 insert_index = len(top_lines) - 1
2719 else:
2720 insert_index = len(top_lines)
Sergiy Byelozyorov 2016/06/02 22:59:53 Shouldn't you also check and if necessary add an e
tandrii(chromium) 2016/06/03 09:34:59 OK, fair. Rewrote it. WDYT?
Sergiy Byelozyorov 2016/06/03 12:35:16 Excellent. Much easier to understand now.
2721 prev_line = top_lines[insert_index-1] if top_lines else None
2722 if (not presubmit_support.Change.TAG_LINE_RE.match(prev_line) or
2723 not presubmit_support.Change.TAG_LINE_RE.match(line)):
2724 top_lines.insert(insert_index, '')
2725 insert_index += 1
2726 top_lines.insert(insert_index, line)
2727 self._description_lines = top_lines + gerrit_footers
2702 2728
2703 def get_reviewers(self): 2729 def get_reviewers(self):
2704 """Retrieves the list of reviewers.""" 2730 """Retrieves the list of reviewers."""
2705 matches = [re.match(self.R_LINE, line) for line in self._description_lines] 2731 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] 2732 reviewers = [match.group(2).strip() for match in matches if match]
2707 return cleanup_list(reviewers) 2733 return cleanup_list(reviewers)
2708 2734
2709 2735
2710 def get_approving_reviewers(props): 2736 def get_approving_reviewers(props):
2711 """Retrieves the reviewers that approved a CL from the issue properties with 2737 """Retrieves the reviewers that approved a CL from the issue properties with
(...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after
4907 if __name__ == '__main__': 4933 if __name__ == '__main__':
4908 # These affect sys.stdout so do it outside of main() to simplify mocks in 4934 # These affect sys.stdout so do it outside of main() to simplify mocks in
4909 # unit testing. 4935 # unit testing.
4910 fix_encoding.fix_encoding() 4936 fix_encoding.fix_encoding()
4911 setup_color.init() 4937 setup_color.init()
4912 try: 4938 try:
4913 sys.exit(main(sys.argv[1:])) 4939 sys.exit(main(sys.argv[1:]))
4914 except KeyboardInterrupt: 4940 except KeyboardInterrupt:
4915 sys.stderr.write('interrupted\n') 4941 sys.stderr.write('interrupted\n')
4916 sys.exit(1) 4942 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | tests/git_cl_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698