comparison hgext/histedit.py @ 45908:f4065c3f09b8

histedit: don't crash if commit message is empty If the commit message is empty, histedit will crash before this patch because it assumes that `summary.splitlines()` is non-empty. One of our users at work ran into this crash for a commit that was created by an internal system. I don't think we have a good way of testing this because it's hard to create a commit with an empty commit message. I've added a comment to help prevent regressions. Differential Revision: https://phab.mercurial-scm.org/D9325
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 16 Nov 2020 10:56:54 -0800
parents 62983988bbf5
children 89a2afe31e82
comparison
equal deleted inserted replaced
45907:06b64fabf91c 45908:f4065c3f09b8
531 {(b'templatealias', b'label(l,x)'): b"x"}, b'histedit' 531 {(b'templatealias', b'label(l,x)'): b"x"}, b'histedit'
532 ): 532 ):
533 summary = cmdutil.rendertemplate( 533 summary = cmdutil.rendertemplate(
534 ctx, ui.config(b'histedit', b'summary-template') 534 ctx, ui.config(b'histedit', b'summary-template')
535 ) 535 )
536 summary = summary.splitlines()[0] 536 # Handle the fact that `''.splitlines() => []`
537 summary = summary.splitlines()[0] if summary else b''
537 line = b'%s %s %s' % (self.verb, ctx, summary) 538 line = b'%s %s %s' % (self.verb, ctx, summary)
538 # trim to 75 columns by default so it's not stupidly wide in my editor 539 # trim to 75 columns by default so it's not stupidly wide in my editor
539 # (the 5 more are left for verb) 540 # (the 5 more are left for verb)
540 maxlen = self.repo.ui.configint(b'histedit', b'linelen') 541 maxlen = self.repo.ui.configint(b'histedit', b'linelen')
541 maxlen = max(maxlen, 22) # avoid truncating hash 542 maxlen = max(maxlen, 22) # avoid truncating hash