[PATCH] grep: warn on censored revisions instead of erroring out

Yuya Nishihara yuya at tcha.org
Mon Oct 21 21:39:51 EDT 2019


On Mon, 21 Oct 2019 16:10:58 -0400, Jordi GutiƩrrez Hermoso wrote:
> # HG changeset patch
> # User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
> # Date 1571688404 14400
> #      Mon Oct 21 16:06:44 2019 -0400
> # Node ID 608193de8560218cc27032977bc380cb8dc0f3f8
> # Parent  d782cce137fd1d50cccfecf8ccb17a623fde8800
> grep: warn on censored revisions instead of erroring out

Can you add some tests?

> @@ -3575,6 +3578,22 @@ def grep(ui, repo, pattern, *pats, **opt
>  
>      getrenamed = scmutil.getrenamedfn(repo)
>  
> +    def get_file_content(filename, filelog, filenode, context, revision):
> +        try:
> +            content = filelog.read(filenode)
> +        except error.WdirUnsupported:
> +            content = context[filename].data()
> +        except error.Sensurround:
> +            content = None

Might be better to fail if censor.policy != ignore.

The doc says:

 "Censored nodes can interrupt mercurial's typical operation whenever the excised
  data needs to be materialized. Some commands, like ``hg cat``/``hg revert``,
  simply fail when asked to produce censored data. Others, like ``hg verify`` and
  ``hg update``, must be capable of tolerating censored data to continue to
  function in a meaningful way. Such commands only tolerate censored file
  revisions if they are allowed by the "censor.policy=ignore" config option.

I have no idea which command group "hg grep" should belong to.

> +            ui.warn(
> +                _(b'Cannot search in censored file: %(filename)s:%(revnum)s\n')

Nit: messages are all lowercase in general.

> +                % {
> +                    'filename': pycompat.bytestr(filename),

Nit: filename must be bytes. bytestr() shouldn't be needed.


More information about the Mercurial-devel mailing list