Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 45695:760bb4d74aad
grep: explicitly pass regexp to closure functions
These functions will be extracted to new module.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 09 Sep 2020 15:17:26 +0900 |
parents | 0356b41fe01d |
children | de6f2afc0247 |
comparison
equal
deleted
inserted
replaced
45694:d1c10d33a85c | 45695:760bb4d74aad |
---|---|
3398 if opts.get(b'print0'): | 3398 if opts.get(b'print0'): |
3399 sep = eol = b'\0' | 3399 sep = eol = b'\0' |
3400 | 3400 |
3401 getfile = util.lrucachefunc(repo.file) | 3401 getfile = util.lrucachefunc(repo.file) |
3402 | 3402 |
3403 def matchlines(body): | 3403 def matchlines(body, regexp): |
3404 begin = 0 | 3404 begin = 0 |
3405 linenum = 0 | 3405 linenum = 0 |
3406 while begin < len(body): | 3406 while begin < len(body): |
3407 match = regexp.search(body, begin) | 3407 match = regexp.search(body, begin) |
3408 if not match: | 3408 if not match: |
3425 return hash(self.line) | 3425 return hash(self.line) |
3426 | 3426 |
3427 def __eq__(self, other): | 3427 def __eq__(self, other): |
3428 return self.line == other.line | 3428 return self.line == other.line |
3429 | 3429 |
3430 def findpos(self): | 3430 def findpos(self, regexp): |
3431 """Iterate all (start, end) indices of matches""" | 3431 """Iterate all (start, end) indices of matches""" |
3432 yield self.colstart, self.colend | 3432 yield self.colstart, self.colend |
3433 p = self.colend | 3433 p = self.colend |
3434 while p < len(self.line): | 3434 while p < len(self.line): |
3435 m = regexp.search(self.line, p) | 3435 m = regexp.search(self.line, p) |
3448 matches[rev].setdefault(fn, []) | 3448 matches[rev].setdefault(fn, []) |
3449 m = matches[rev][fn] | 3449 m = matches[rev][fn] |
3450 if body is None: | 3450 if body is None: |
3451 return | 3451 return |
3452 | 3452 |
3453 for lnum, cstart, cend, line in matchlines(body): | 3453 for lnum, cstart, cend, line in matchlines(body, regexp): |
3454 s = linestate(line, lnum, cstart, cend) | 3454 s = linestate(line, lnum, cstart, cend) |
3455 m.append(s) | 3455 m.append(s) |
3456 | 3456 |
3457 def difflinestates(a, b): | 3457 def difflinestates(a, b): |
3458 sm = difflib.SequenceMatcher(None, a, b) | 3458 sm = difflib.SequenceMatcher(None, a, b) |
3560 break | 3560 break |
3561 return found | 3561 return found |
3562 | 3562 |
3563 def displaymatches(fm, l): | 3563 def displaymatches(fm, l): |
3564 p = 0 | 3564 p = 0 |
3565 for s, e in l.findpos(): | 3565 for s, e in l.findpos(regexp): |
3566 if p < s: | 3566 if p < s: |
3567 fm.startitem() | 3567 fm.startitem() |
3568 fm.write(b'text', b'%s', l.line[p:s]) | 3568 fm.write(b'text', b'%s', l.line[p:s]) |
3569 fm.data(matched=False) | 3569 fm.data(matched=False) |
3570 fm.startitem() | 3570 fm.startitem() |