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

login
register
mail settings
Submitter phabricator
Date June 2, 2018, 6:30 a.m.
Message ID <34ce20652ae32e5010fbe59d02331120@localhost.localdomain>
Download mbox | patch
Permalink /patch/31932/
State Not Applicable
Headers show

Comments

phabricator - June 2, 2018, 6:30 a.m.
sangeet259 updated this revision to Diff 8951.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3673?vs=8930&id=8951

REVISION DETAIL
  https://phab.mercurial-scm.org/D3673

AFFECTED FILES
  mercurial/commands.py
  tests/test-grep.t

CHANGE DETAILS




To: sangeet259, #hg-reviewers
Cc: yuja, mercurial-devel
Yuya Nishihara - June 3, 2018, 3:04 a.m.
> +            if ctx.rev() is None :
> +                rev = scmutil.intrev(ctx)

Moved this to top and queued, thanks.
phabricator - June 3, 2018, 3:04 a.m.
yuja added a comment.


  > +            if ctx.rev() is None :
  >  +                rev = scmutil.intrev(ctx)
  
  Moved this to top and queued, thanks.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3673

To: sangeet259, #hg-reviewers
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -250,8 +250,11 @@ 
   $ hg stat
   M port2
   $ hg grep -r 'wdir()' port
-  abort: working directory revision cannot be specified
-  [255]
+  port2:2147483647:export
+  port2:2147483647:vaportight
+  port2:2147483647:import/export
+  port2:2147483647:deport
+  port2:2147483647:wport
 
   $ cd ..
   $ hg init t2
@@ -368,3 +371,14 @@ 
   binfile.bin:0:+: Binary file matches
 
   $ cd ..
+
+Fix_Wdir(): test that passing wdir() t -r flag does greps on the
+files modified in the working directory
+
+  $ cd a
+  $ echo "abracadara" >> a
+  $ hg add a
+  $ hg grep -r "wdir()" "abra"
+  a:2147483647:abracadara
+
+  $ cd ..
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2513,16 +2513,22 @@ 
         @util.cachefunc
         def binary():
             flog = getfile(fn)
-            return stringutil.binary(flog.read(ctx.filenode(fn)))
+            try:
+                return stringutil.binary(flog.read(ctx.filenode(fn)))
+            except error.WdirUnsupported:
+                return ctx[fn].isbinary()
 
         fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'}
         if opts.get('all'):
             iter = difflinestates(pstates, states)
         else:
             iter = [('', l) for l in states]
         for change, l in iter:
             fm.startitem()
-            fm.data(node=fm.hexfunc(ctx.node()))
+            fm.data(node=fm.hexfunc(scmutil.binnode(ctx)))
+            if ctx.rev() is None :
+                rev = scmutil.intrev(ctx)
+
             cols = [
                 ('filename', fn, True),
                 ('rev', rev, True),
@@ -2588,8 +2594,10 @@ 
                 fnode = ctx.filenode(fn)
             except error.LookupError:
                 continue
-
-            copied = flog.renamed(fnode)
+            try:
+                copied = flog.renamed(fnode)
+            except error.WdirUnsupported :
+                copied = ctx[fn].renamed()
             copy = follow and copied and copied[0]
             if copy:
                 copies.setdefault(rev, {})[fn] = copy
@@ -2600,7 +2608,11 @@ 
             files.append(fn)
 
             if fn not in matches[rev]:
-                grepbody(fn, rev, flog.read(fnode))
+                try:
+                    content = flog.read(fnode)
+                except error.WdirUnsupported:
+                    content = ctx[fn].data()
+                grepbody(fn, rev, content)
 
             pfn = copy or fn
             if pfn not in matches[parent]: