Mercurial > hg
comparison hgext/mq.py @ 23443:3b653c2fd6ba
mq: drop updateheader - inserthgheader and insertplainheader is enough
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 28 Nov 2014 03:09:19 +0100 |
parents | a5c94ea3b8af |
children | 7cc77030c557 |
comparison
equal
deleted
inserted
replaced
23442:a5c94ea3b8af | 23443:3b653c2fd6ba |
---|---|
301 util.any(c.startswith('Date: ') or | 301 util.any(c.startswith('Date: ') or |
302 c.startswith('From: ') | 302 c.startswith('From: ') |
303 for c in self.comments)) | 303 for c in self.comments)) |
304 | 304 |
305 def setuser(self, user): | 305 def setuser(self, user): |
306 if not self.updateheader(['From: ', '# User '], user): | 306 try: |
307 try: | 307 inserthgheader(self.comments, '# User ', user) |
308 inserthgheader(self.comments, '# User ', user) | 308 except ValueError: |
309 except ValueError: | 309 if self.plainmode: |
310 if self.plainmode: | 310 insertplainheader(self.comments, 'From', user) |
311 insertplainheader(self.comments, 'From', user) | 311 else: |
312 else: | 312 tmp = ['# HG changeset patch', '# User ' + user] |
313 tmp = ['# HG changeset patch', '# User ' + user] | 313 self.comments = tmp + self.comments |
314 self.comments = tmp + self.comments | |
315 self.user = user | 314 self.user = user |
316 | 315 |
317 def setdate(self, date): | 316 def setdate(self, date): |
318 if not self.updateheader(['Date: ', '# Date '], date): | 317 try: |
319 try: | 318 inserthgheader(self.comments, '# Date ', date) |
320 inserthgheader(self.comments, '# Date ', date) | 319 except ValueError: |
321 except ValueError: | 320 if self.plainmode: |
322 if self.plainmode: | 321 insertplainheader(self.comments, 'Date', date) |
323 insertplainheader(self.comments, 'Date', date) | 322 else: |
324 else: | 323 tmp = ['# HG changeset patch', '# Date ' + date] |
325 tmp = ['# HG changeset patch', '# Date ' + date] | 324 self.comments = tmp + self.comments |
326 self.comments = tmp + self.comments | |
327 self.date = date | 325 self.date = date |
328 | 326 |
329 def setparent(self, parent): | 327 def setparent(self, parent): |
330 if not (self.updateheader(['# Parent '], parent) or | 328 try: |
331 self.updateheader(['# Parent '], parent)): | 329 inserthgheader(self.comments, '# Parent ', parent) |
332 try: | 330 except ValueError: |
333 inserthgheader(self.comments, '# Parent ', parent) | 331 if not self.plainmode: |
334 except ValueError: | 332 tmp = ['# HG changeset patch', '# Parent ' + parent] |
335 if not self.plainmode: | 333 self.comments = tmp + self.comments |
336 tmp = ['# HG changeset patch', '# Parent ' + parent] | |
337 self.comments = tmp + self.comments | |
338 self.parent = parent | 334 self.parent = parent |
339 | 335 |
340 def setmessage(self, message): | 336 def setmessage(self, message): |
341 if self.comments: | 337 if self.comments: |
342 self._delmsg() | 338 self._delmsg() |
343 self.message = [message] | 339 self.message = [message] |
344 if message: | 340 if message: |
345 if self.plainmode and self.comments and self.comments[-1]: | 341 if self.plainmode and self.comments and self.comments[-1]: |
346 self.comments.append('') | 342 self.comments.append('') |
347 self.comments.append(message) | 343 self.comments.append(message) |
348 | |
349 def updateheader(self, prefixes, new): | |
350 '''Update all references to a field in the patch header. | |
351 Return whether the field is present.''' | |
352 res = False | |
353 for prefix in prefixes: | |
354 for i in xrange(len(self.comments)): | |
355 if self.comments[i].startswith(prefix): | |
356 self.comments[i] = prefix + new | |
357 res = True | |
358 break | |
359 return res | |
360 | 344 |
361 def __str__(self): | 345 def __str__(self): |
362 s = '\n'.join(self.comments).rstrip() | 346 s = '\n'.join(self.comments).rstrip() |
363 if not s: | 347 if not s: |
364 return '' | 348 return '' |