D3673: grep: enables passing wdir as a revision in grep

Yuya Nishihara yuya at tcha.org
Thu May 31 08:43:46 EDT 2018


> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -2513,19 +2513,27 @@
>          @util.cachefunc
>          def binary():
>              flog = getfile(fn)
> -            return stringutil.binary(flog.read(ctx.filenode(fn)))
> +            try:
> +                content = flog.read(ctx.filenode(fn))
> +            except error.WdirUnsupported:
> +                content = ctx[fn].data()

`ctx[fn].isbinary()` is preferred.

> -            fm.data(node=fm.hexfunc(ctx.node()))
> +            fm.data(node=fm.hexfunc(scmutil.binnode(ctx)))
> +            if ctx._rev is None :

`ctx.rev()`

> +                showrev = False
> +            else :
> +                showrev = True
>              cols = [
>                  ('filename', fn, True),
> -                ('rev', rev, True),
> +                ('rev', rev, showrev),

It's probably better to not disable the revision output since we'll need
a revision number in machine-readable output such as JSON.

We can use `scmutil.intrev(ctx)` instead. The output is a bit ugly for
humans, but it's valid and we can fix it to be prettier later.

> -            copied = flog.renamed(fnode)
> +            try:
> +                copied = flog.renamed(fnode)
> +            except error.WdirUnsupported :
> +                copied = False

`ctx[fn].renamed()` ?


More information about the Mercurial-devel mailing list