1 # Copyright (c) 2011 The Chromium OS Authors.
3 # See file CREDITS for list of people who contributed to this
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 # Series-xxx tags that we understand
28 valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name'];
31 """Holds information about a patch series, including all tags.
34 cc: List of aliases/emails to Cc all patches to
35 commits: List of Commit objects, one for each patch
36 cover: List of lines in the cover letter
37 notes: List of lines in the notes
38 changes: (dict) List of changes for each version, The key is
39 the integer version number
49 # These make us more like a dictionary
50 def __setattr__(self, name, value):
53 def __getattr__(self, name):
56 def AddTag(self, commit, line, name, value):
57 """Add a new Series-xxx tag along with its value.
60 line: Source line containing tag (useful for debug/error messages)
61 name: Tag name (part after 'Series-')
62 value: Tag value (part after 'Series-xxx: ')
64 # If we already have it, then add to our list
66 values = value.split(',')
67 values = [str.strip() for str in values]
68 if type(self[name]) != type([]):
69 raise ValueError("In %s: line '%s': Cannot add another value "
70 "'%s' to series '%s'" %
71 (commit.hash, line, values, self[name]))
74 # Otherwise just set the value
75 elif name in valid_series:
78 raise ValueError("In %s: line '%s': Unknown 'Series-%s': valid "
79 "options are %s" % (commit.hash, line, name,
80 ', '.join(valid_series)))
82 def AddCommit(self, commit):
83 """Add a commit into our list of commits
85 We create a list of tags in the commit subject also.
88 commit: Commit object to add
91 self.commits.append(commit)
93 def ShowActions(self, args, cmd, process_tags):
94 """Show what actions we will/would perform
97 args: List of patch files we created
98 cmd: The git command we would have run
99 process_tags: Process tags as if they were aliases
101 col = terminal.Color()
102 print 'Dry run, so not doing much. But I would do this:'
104 print 'Send a total of %d patch%s with %scover letter.' % (
105 len(args), '' if len(args) == 1 else 'es',
106 self.get('cover') and 'a ' or 'no ')
108 # TODO: Colour the patches according to whether they passed checks
109 for upto in range(len(args)):
110 commit = self.commits[upto]
111 print col.Color(col.GREEN, ' %s' % args[upto])
114 cc_list += gitutil.BuildEmailList(commit.tags)
115 cc_list += gitutil.BuildEmailList(commit.cc_list)
117 # Skip items in To list
120 map(cc_list.remove, gitutil.BuildEmailList(self.to))
124 for email in cc_list:
126 email = col.Color(col.YELLOW, "<alias '%s' not found>"
131 for item in gitutil.BuildEmailList(self.get('to', '<none>')):
133 for item in gitutil.BuildEmailList(self.cc):
135 print 'Version: ', self.get('version')
136 print 'Prefix:\t ', self.get('prefix')
138 print 'Cover: %d lines' % len(self.cover)
140 print 'Git command: %s' % cmd
142 def MakeChangeLog(self, commit):
143 """Create a list of changes for each version.
146 The change log as a list of strings, one per line
149 - Jog the dial back closer to the widget
160 for change in sorted(self.changes, reverse=True):
162 for this_commit, text in self.changes[change]:
163 if commit and this_commit != commit:
166 line = 'Changes in v%d:' % change
167 have_changes = len(out) > 0
171 out = [line + ' None']
175 need_blank = have_changes
181 """Check that each version has a change log
183 Print an error if something is wrong.
185 col = terminal.Color()
186 if self.get('version'):
187 changes_copy = dict(self.changes)
188 for version in range(1, int(self.version) + 1):
189 if self.changes.get(version):
190 del changes_copy[version]
193 str = 'Change log missing for v%d' % version
194 print col.Color(col.RED, str)
195 for version in changes_copy:
196 str = 'Change log for unknown version v%d' % version
197 print col.Color(col.RED, str)
199 str = 'Change log exists, but no version is set'
200 print col.Color(col.RED, str)
202 def MakeCcFile(self, process_tags):
203 """Make a cc file for us to use for per-commit Cc automation
206 process_tags: Process tags as if they were aliases
208 Filename of temp file created
210 # Look for commit tags (of the form 'xxx:' at the start of the subject)
211 fname = '/tmp/patman.%d' % os.getpid()
212 fd = open(fname, 'w')
213 for commit in self.commits:
216 list += gitutil.BuildEmailList(commit.tags)
217 list += gitutil.BuildEmailList(commit.cc_list)
218 print >>fd, commit.patch, ', '.join(list)
223 def AddChange(self, version, commit, info):
224 """Add a new change line to a version.
226 This will later appear in the change log.
229 version: version number to add change list to
230 info: change line for this version
232 if not self.changes.get(version):
233 self.changes[version] = []
234 self.changes[version].append([commit, info])
236 def GetPatchPrefix(self):
237 """Get the patch version string
240 Patch string, like 'RFC PATCH v5' or just 'PATCH'
243 if self.get('version'):
244 version = ' v%s' % self['version']
246 # Get patch name prefix
248 if self.get('prefix'):
249 prefix = '%s ' % self['prefix']
250 return '%sPATCH%s' % (prefix, version)