comparison mercurial/commands.py @ 29861:fac24eab65a4

grep: factor out function that prints matched line with labels Prepares for formatter support.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 18 Aug 2016 14:09:49 +0900
parents b842b1adfea2
children 37d838e8eb0b
comparison
equal deleted inserted replaced
29860:b842b1adfea2 29861:fac24eab65a4
4354 if not m: 4354 if not m:
4355 break 4355 break
4356 yield m.span() 4356 yield m.span()
4357 p = m.end() 4357 p = m.end()
4358 4358
4359 def __iter__(self):
4360 p = 0
4361 for s, e in self.findpos():
4362 yield self.line[p:s], ''
4363 yield self.line[s:e], 'grep.match'
4364 p = e
4365 yield self.line[p:], ''
4366
4367 matches = {} 4359 matches = {}
4368 copies = {} 4360 copies = {}
4369 def grepbody(fn, rev, body): 4361 def grepbody(fn, rev, body):
4370 matches[rev].setdefault(fn, []) 4362 matches[rev].setdefault(fn, [])
4371 m = matches[rev][fn] 4363 m = matches[rev][fn]
4422 if not opts.get('files_with_matches'): 4414 if not opts.get('files_with_matches'):
4423 ui.write(sep, label='grep.sep') 4415 ui.write(sep, label='grep.sep')
4424 if not opts.get('text') and binary(): 4416 if not opts.get('text') and binary():
4425 ui.write(_(" Binary file matches")) 4417 ui.write(_(" Binary file matches"))
4426 else: 4418 else:
4427 for s, label in l: 4419 displaymatches(l)
4428 ui.write(s, label=label)
4429 ui.write(eol) 4420 ui.write(eol)
4430 found = True 4421 found = True
4431 if opts.get('files_with_matches'): 4422 if opts.get('files_with_matches'):
4432 break 4423 break
4433 return found 4424 return found
4425
4426 def displaymatches(l):
4427 p = 0
4428 for s, e in l.findpos():
4429 ui.write(l.line[p:s])
4430 ui.write(l.line[s:e], label='grep.match')
4431 p = e
4432 ui.write(l.line[p:])
4434 4433
4435 skip = {} 4434 skip = {}
4436 revfiles = {} 4435 revfiles = {}
4437 matchfn = scmutil.match(repo[None], pats, opts) 4436 matchfn = scmutil.match(repo[None], pats, opts)
4438 found = False 4437 found = False