Show More
@@ -3440,6 +3440,9 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
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) | |
@@ -3575,6 +3578,19 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
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() | |
@@ -3601,17 +3617,15 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
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 |
@@ -442,6 +442,33 b' Censored nodes can be bundled up and unb' | |||||
442 | checking files |
|
442 | checking files | |
443 | checked 14 changesets with 15 changes to 2 files |
|
443 | checked 14 changesets with 15 changes to 2 files | |
444 |
|
444 | |||
|
445 | Grepping only warns, doesn't error out | |||
|
446 | ||||
|
447 | $ cd ../rpull | |||
|
448 | $ hg grep 'Normal file' | |||
|
449 | bystander:Normal file v2 | |||
|
450 | $ hg grep nothing | |||
|
451 | target:Re-sanitized; nothing to see here | |||
|
452 | $ hg grep --diff 'Normal file' | |||
|
453 | cannot search in censored file: target:7 | |||
|
454 | cannot search in censored file: target:10 | |||
|
455 | cannot search in censored file: target:12 | |||
|
456 | bystander:6:-:Normal file v2 | |||
|
457 | cannot search in censored file: target:1 | |||
|
458 | cannot search in censored file: target:2 | |||
|
459 | cannot search in censored file: target:3 | |||
|
460 | bystander:2:-:Normal file here | |||
|
461 | bystander:2:+:Normal file v2 | |||
|
462 | bystander:0:+:Normal file here | |||
|
463 | $ hg grep --diff nothing | |||
|
464 | cannot search in censored file: target:7 | |||
|
465 | cannot search in censored file: target:10 | |||
|
466 | cannot search in censored file: target:12 | |||
|
467 | target:13:+:Re-sanitized; nothing to see here | |||
|
468 | cannot search in censored file: target:1 | |||
|
469 | cannot search in censored file: target:2 | |||
|
470 | cannot search in censored file: target:3 | |||
|
471 | ||||
445 | Censored nodes can be imported on top of censored nodes, consecutively |
|
472 | Censored nodes can be imported on top of censored nodes, consecutively | |
446 |
|
473 | |||
447 | $ hg init ../rimport |
|
474 | $ hg init ../rimport |
General Comments 0
You need to be logged in to leave comments.
Login now