This instance will be upgraded to Heptapod 0.26.0rc1 on 2021-10-25 at 14:00 UTC+2 (a few minutes of down time)

Commit 973a19c5 authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

grep: move readfile() to grepsearcher class

parent 41e0cbccb260
......@@ -3519,28 +3519,6 @@ def grep(ui, repo, pattern, *pats, **opts):
getrenamed = searcher._getrenamed
def readfile(ctx, fn):
rev = ctx.rev()
if rev is None:
fctx = ctx[fn]
try:
return fctx.data()
except IOError as e:
if e.errno != errno.ENOENT:
raise
else:
flog = getfile(fn)
fnode = ctx.filenode(fn)
try:
return flog.read(fnode)
except error.CensoredNodeError:
ui.warn(
_(
b'cannot search in censored file: %(filename)s:%(revnum)s\n'
)
% {b'filename': fn, b'revnum': pycompat.bytestr(rev),}
)
def prep(ctx, fmatch):
rev = ctx.rev()
pctx = ctx.p1()
......@@ -3581,12 +3559,14 @@ def grep(ui, repo, pattern, *pats, **opts):
files.append(fn)
if fn not in matches[rev]:
searcher._grepbody(fn, rev, readfile(ctx, fn))
searcher._grepbody(fn, rev, searcher._readfile(ctx, fn))
if diff:
pfn = copy or fn
if pfn not in matches[parent] and pfn in pctx:
searcher._grepbody(pfn, parent, readfile(pctx, pfn))
searcher._grepbody(
pfn, parent, searcher._readfile(pctx, pfn)
)
wopts = logcmdutil.walkopts(
pats=pats,
......
......@@ -8,8 +8,12 @@
from __future__ import absolute_import
import difflib
import errno
from .i18n import _
from . import (
error,
pycompat,
scmutil,
util,
......@@ -100,3 +104,26 @@ class grepsearcher(object):
for lnum, cstart, cend, line in matchlines(body, self._regexp):
s = linestate(line, lnum, cstart, cend)
m.append(s)
def _readfile(self, ctx, fn):
rev = ctx.rev()
if rev is None:
fctx = ctx[fn]
try:
return fctx.data()
except IOError as e:
if e.errno != errno.ENOENT:
raise
else:
flog = self._getfile(fn)
fnode = ctx.filenode(fn)
try:
return flog.read(fnode)
except error.CensoredNodeError:
self._ui.warn(
_(
b'cannot search in censored file: '
b'%(filename)s:%(revnum)s\n'
)
% {b'filename': fn, b'revnum': pycompat.bytestr(rev)}
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment