comparison mercurial/commands.py @ 7230:261a9f47b44b

grep: avoid infinite loop when trailing newline is missing
author Matt Mackall <mpm@selenic.com>
date Thu, 23 Oct 2008 14:56:16 -0500
parents 9b72c732ed2f
children db6fbb785800
comparison
equal deleted inserted replaced
7229:7946503ec76e 7230:261a9f47b44b
1092 if not match: 1092 if not match:
1093 break 1093 break
1094 mstart, mend = match.span() 1094 mstart, mend = match.span()
1095 linenum += body.count('\n', begin, mstart) + 1 1095 linenum += body.count('\n', begin, mstart) + 1
1096 lstart = body.rfind('\n', begin, mstart) + 1 or begin 1096 lstart = body.rfind('\n', begin, mstart) + 1 or begin
1097 lend = body.find('\n', mend) 1097 begin = body.find('\n', mend) + 1 or len(body)
1098 lend = begin - 1
1098 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] 1099 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
1099 begin = lend + 1
1100 1100
1101 class linestate(object): 1101 class linestate(object):
1102 def __init__(self, line, linenum, colstart, colend): 1102 def __init__(self, line, linenum, colstart, colend):
1103 self.line = line 1103 self.line = line
1104 self.linenum = linenum 1104 self.linenum = linenum