equal
deleted
inserted
replaced
3438 copies = {} |
3438 copies = {} |
3439 |
3439 |
3440 def grepbody(fn, rev, body): |
3440 def grepbody(fn, rev, body): |
3441 matches[rev].setdefault(fn, []) |
3441 matches[rev].setdefault(fn, []) |
3442 m = matches[rev][fn] |
3442 m = matches[rev][fn] |
|
3443 if body is None: |
|
3444 return |
|
3445 |
3443 for lnum, cstart, cend, line in matchlines(body): |
3446 for lnum, cstart, cend, line in matchlines(body): |
3444 s = linestate(line, lnum, cstart, cend) |
3447 s = linestate(line, lnum, cstart, cend) |
3445 m.append(s) |
3448 m.append(s) |
3446 |
3449 |
3447 def difflinestates(a, b): |
3450 def difflinestates(a, b): |
3573 found = False |
3576 found = False |
3574 follow = opts.get(b'follow') |
3577 follow = opts.get(b'follow') |
3575 |
3578 |
3576 getrenamed = scmutil.getrenamedfn(repo) |
3579 getrenamed = scmutil.getrenamedfn(repo) |
3577 |
3580 |
|
3581 def get_file_content(filename, filelog, filenode, context, revision): |
|
3582 try: |
|
3583 content = filelog.read(filenode) |
|
3584 except error.WdirUnsupported: |
|
3585 content = context[filename].data() |
|
3586 except error.CensoredNodeError: |
|
3587 content = None |
|
3588 ui.warn( |
|
3589 _(b'cannot search in censored file: %(filename)s:%(revnum)s\n') |
|
3590 % {b'filename': filename, b'revnum': pycompat.bytestr(revision)} |
|
3591 ) |
|
3592 return content |
|
3593 |
3578 def prep(ctx, fns): |
3594 def prep(ctx, fns): |
3579 rev = ctx.rev() |
3595 rev = ctx.rev() |
3580 pctx = ctx.p1() |
3596 pctx = ctx.p1() |
3581 parent = pctx.rev() |
3597 parent = pctx.rev() |
3582 matches.setdefault(rev, {}) |
3598 matches.setdefault(rev, {}) |
3599 if fn in skip: |
3615 if fn in skip: |
3600 continue |
3616 continue |
3601 files.append(fn) |
3617 files.append(fn) |
3602 |
3618 |
3603 if fn not in matches[rev]: |
3619 if fn not in matches[rev]: |
3604 try: |
3620 content = get_file_content(fn, flog, fnode, ctx, rev) |
3605 content = flog.read(fnode) |
|
3606 except error.WdirUnsupported: |
|
3607 content = ctx[fn].data() |
|
3608 grepbody(fn, rev, content) |
3621 grepbody(fn, rev, content) |
3609 |
3622 |
3610 pfn = copy or fn |
3623 pfn = copy or fn |
3611 if pfn not in matches[parent]: |
3624 if pfn not in matches[parent]: |
3612 try: |
3625 try: |
3613 fnode = pctx.filenode(pfn) |
3626 pfnode = pctx.filenode(pfn) |
3614 grepbody(pfn, parent, flog.read(fnode)) |
3627 pcontent = get_file_content(pfn, flog, pfnode, pctx, parent) |
|
3628 grepbody(pfn, parent, pcontent) |
3615 except error.LookupError: |
3629 except error.LookupError: |
3616 pass |
3630 pass |
3617 |
3631 |
3618 ui.pager(b'grep') |
3632 ui.pager(b'grep') |
3619 fm = ui.formatter(b'grep', opts) |
3633 fm = ui.formatter(b'grep', opts) |