Mercurial > hg
comparison mercurial/grep.py @ 45699:888e633f0c1c
grep: move readfile() to grepsearcher class
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 09 Sep 2020 16:04:39 +0900 |
parents | 41e0cbccb260 |
children | c694b1841a5e |
comparison
equal
deleted
inserted
replaced
45698:41e0cbccb260 | 45699:888e633f0c1c |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import difflib | 10 import difflib |
11 import errno | |
12 | |
13 from .i18n import _ | |
11 | 14 |
12 from . import ( | 15 from . import ( |
16 error, | |
13 pycompat, | 17 pycompat, |
14 scmutil, | 18 scmutil, |
15 util, | 19 util, |
16 ) | 20 ) |
17 | 21 |
98 return | 102 return |
99 | 103 |
100 for lnum, cstart, cend, line in matchlines(body, self._regexp): | 104 for lnum, cstart, cend, line in matchlines(body, self._regexp): |
101 s = linestate(line, lnum, cstart, cend) | 105 s = linestate(line, lnum, cstart, cend) |
102 m.append(s) | 106 m.append(s) |
107 | |
108 def _readfile(self, ctx, fn): | |
109 rev = ctx.rev() | |
110 if rev is None: | |
111 fctx = ctx[fn] | |
112 try: | |
113 return fctx.data() | |
114 except IOError as e: | |
115 if e.errno != errno.ENOENT: | |
116 raise | |
117 else: | |
118 flog = self._getfile(fn) | |
119 fnode = ctx.filenode(fn) | |
120 try: | |
121 return flog.read(fnode) | |
122 except error.CensoredNodeError: | |
123 self._ui.warn( | |
124 _( | |
125 b'cannot search in censored file: ' | |
126 b'%(filename)s:%(revnum)s\n' | |
127 ) | |
128 % {b'filename': fn, b'revnum': pycompat.bytestr(rev)} | |
129 ) |