comparison hgext/histedit.py @ 49022:e160f073c37b

histedit: use new function for getting first line of a string This fixes a crash you can run into if you enter a commit message that's just a "newline-like" byte, like a form feed byte (`hg ci -m \x0f` in Fish). That bug is the motivation for this series. Differential Revision: https://phab.mercurial-scm.org/D12405
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 24 Mar 2022 16:51:20 -0700
parents 642e31cb55f0
children 7bdf19f892c6
comparison
equal deleted inserted replaced
49021:51aed118f9dc 49022:e160f073c37b
550 {(b'templatealias', b'label(l,x)'): b"x"}, b'histedit' 550 {(b'templatealias', b'label(l,x)'): b"x"}, b'histedit'
551 ): 551 ):
552 summary = cmdutil.rendertemplate( 552 summary = cmdutil.rendertemplate(
553 ctx, ui.config(b'histedit', b'summary-template') 553 ctx, ui.config(b'histedit', b'summary-template')
554 ) 554 )
555 # Handle the fact that `''.splitlines() => []` 555 line = b'%s %s %s' % (self.verb, ctx, stringutil.firstline(summary))
556 summary = summary.splitlines()[0] if summary else b''
557 line = b'%s %s %s' % (self.verb, ctx, summary)
558 # trim to 75 columns by default so it's not stupidly wide in my editor 556 # trim to 75 columns by default so it's not stupidly wide in my editor
559 # (the 5 more are left for verb) 557 # (the 5 more are left for verb)
560 maxlen = self.repo.ui.configint(b'histedit', b'linelen') 558 maxlen = self.repo.ui.configint(b'histedit', b'linelen')
561 maxlen = max(maxlen, 22) # avoid truncating hash 559 maxlen = max(maxlen, 22) # avoid truncating hash
562 return stringutil.ellipsis(line, maxlen) 560 return stringutil.ellipsis(line, maxlen)
1190 if summary: 1188 if summary:
1191 return summary 1189 return summary
1192 # This is split off from the prefix property so that we can 1190 # This is split off from the prefix property so that we can
1193 # separately make the description for 'roll' red (since it 1191 # separately make the description for 'roll' red (since it
1194 # will get discarded). 1192 # will get discarded).
1195 return self.ctx.description().splitlines()[0].strip() 1193 return stringutil.firstline(self.ctx.description())
1196 1194
1197 def checkconflicts(self, other): 1195 def checkconflicts(self, other):
1198 if other.pos > self.pos and other.origpos <= self.origpos: 1196 if other.pos > self.pos and other.origpos <= self.origpos:
1199 if set(other.ctx.files()) & set(self.ctx.files()) != set(): 1197 if set(other.ctx.files()) & set(self.ctx.files()) != set():
1200 self.conflicts.append(other) 1198 self.conflicts.append(other)
1289 1287
1290 bms = self.repo.nodebookmarks(ctx.node()) 1288 bms = self.repo.nodebookmarks(ctx.node())
1291 line = b"bookmark: %s" % b' '.join(bms) 1289 line = b"bookmark: %s" % b' '.join(bms)
1292 win.addstr(3, 1, line[:length]) 1290 win.addstr(3, 1, line[:length])
1293 1291
1294 line = b"summary: %s" % (ctx.description().splitlines()[0]) 1292 line = b"summary: %s" % stringutil.firstline(ctx.description())
1295 win.addstr(4, 1, line[:length]) 1293 win.addstr(4, 1, line[:length])
1296 1294
1297 line = b"files: " 1295 line = b"files: "
1298 win.addstr(5, 1, line) 1296 win.addstr(5, 1, line)
1299 fnx = 1 + len(line) 1297 fnx = 1 + len(line)
2322 2320
2323 def _getsummary(ctx): 2321 def _getsummary(ctx):
2324 # a common pattern is to extract the summary but default to the empty 2322 # a common pattern is to extract the summary but default to the empty
2325 # string 2323 # string
2326 summary = ctx.description() or b'' 2324 summary = ctx.description() or b''
2327 if summary: 2325 return stringutil.firstline(summary)
2328 summary = summary.splitlines()[0]
2329 return summary
2330 2326
2331 2327
2332 def bootstrapcontinue(ui, state, opts): 2328 def bootstrapcontinue(ui, state, opts):
2333 repo = state.repo 2329 repo = state.repo
2334 2330