Mercurial > hg
comparison hgext/mq.py @ 22522:382c2be610dc
mq: simplify patchheader handling of the empty line before the diff
Don't try to append empty lines to HG patch headers - instead, add them in str
method.
This minor change removes some apparently redundant code and makes the code
more robust.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 24 Sep 2014 01:39:25 +0200 |
parents | 3f948469bac0 |
children | 0d75ce895adc |
comparison
equal
deleted
inserted
replaced
22521:3f948469bac0 | 22522:382c2be610dc |
---|---|
189 eatempty(message) | 189 eatempty(message) |
190 eatempty(comments) | 190 eatempty(comments) |
191 | 191 |
192 # make sure message isn't empty | 192 # make sure message isn't empty |
193 if format and format.startswith("tag") and subject: | 193 if format and format.startswith("tag") and subject: |
194 message.insert(0, "") | |
195 message.insert(0, subject) | 194 message.insert(0, subject) |
196 | 195 |
197 self.message = message | 196 self.message = message |
198 self.comments = comments | 197 self.comments = comments |
199 self.user = user | 198 self.user = user |
212 self.comments.insert(patchheaderat + 1, '# User ' + user) | 211 self.comments.insert(patchheaderat + 1, '# User ' + user) |
213 except ValueError: | 212 except ValueError: |
214 if self.plainmode or self._hasheader(['Date: ']): | 213 if self.plainmode or self._hasheader(['Date: ']): |
215 self.comments = ['From: ' + user] + self.comments | 214 self.comments = ['From: ' + user] + self.comments |
216 else: | 215 else: |
217 tmp = ['# HG changeset patch', '# User ' + user, ''] | 216 tmp = ['# HG changeset patch', '# User ' + user] |
218 self.comments = tmp + self.comments | 217 self.comments = tmp + self.comments |
219 self.user = user | 218 self.user = user |
220 | 219 |
221 def setdate(self, date): | 220 def setdate(self, date): |
222 if not self.updateheader(['Date: ', '# Date '], date): | 221 if not self.updateheader(['Date: ', '# Date '], date): |
225 self.comments.insert(patchheaderat + 1, '# Date ' + date) | 224 self.comments.insert(patchheaderat + 1, '# Date ' + date) |
226 except ValueError: | 225 except ValueError: |
227 if self.plainmode or self._hasheader(['From: ']): | 226 if self.plainmode or self._hasheader(['From: ']): |
228 self.comments = ['Date: ' + date] + self.comments | 227 self.comments = ['Date: ' + date] + self.comments |
229 else: | 228 else: |
230 tmp = ['# HG changeset patch', '# Date ' + date, ''] | 229 tmp = ['# HG changeset patch', '# Date ' + date] |
231 self.comments = tmp + self.comments | 230 self.comments = tmp + self.comments |
232 self.date = date | 231 self.date = date |
233 | 232 |
234 def setparent(self, parent): | 233 def setparent(self, parent): |
235 if not (self.updateheader(['# Parent '], parent) or | 234 if not (self.updateheader(['# Parent '], parent) or |
266 if comment.startswith(prefix): | 265 if comment.startswith(prefix): |
267 return True | 266 return True |
268 return False | 267 return False |
269 | 268 |
270 def __str__(self): | 269 def __str__(self): |
271 if not self.comments: | 270 s = '\n'.join(self.comments).rstrip() |
271 if not s: | |
272 return '' | 272 return '' |
273 return '\n'.join(self.comments) + '\n\n' | 273 return s + '\n\n' |
274 | 274 |
275 def _delmsg(self): | 275 def _delmsg(self): |
276 '''Remove existing message, keeping the rest of the comments fields. | 276 '''Remove existing message, keeping the rest of the comments fields. |
277 If comments contains 'subject: ', message will prepend | 277 If comments contains 'subject: ', message will prepend |
278 the field and a blank line.''' | 278 the field and a blank line.''' |