This is an archive of the discontinued Mercurial Phabricator instance.

grep: enables passing wdir as a revision in grep
ClosedPublic

Authored by sangeet259 on May 30 2018, 9:31 AM.

Details

Summary

When you pass wdir() to the -r flag, it catches the
WdirUnsupported error and fall back to and alternate path

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

sangeet259 created this revision.May 30 2018, 9:31 AM
yuja added a subscriber: yuja.May 31 2018, 8:44 AM
  • 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() ?

sangeet259 updated this revision to Diff 8951.Jun 2 2018, 2:30 AM
yuja added a comment.Jun 2 2018, 11:04 PM

+ if ctx.rev() is None :
+ rev = scmutil.intrev(ctx)

Moved this to top and queued, thanks.

This revision was automatically updated to reflect the committed changes.