workingctx: build _manifest on filenode() or flags() request
authorYuya Nishihara <yuya@tcha.org>
Sun, 25 Mar 2018 18:27:43 +0900
changeset 37447 067e8d1178a2
parent 37446 d46d4f14300a
child 37448 d7114f883505
workingctx: build _manifest on filenode() or flags() request I'm not sure if this is the best workaround, but this fixes the following exception: AttributeError: 'workingctx' object has no attribute '_manifestdelta' The short hash '303030303030' seen in the test is node.modifiednodeid. Differential Revision: https://phab.mercurial-scm.org/D2940
mercurial/context.py
tests/test-grep.t
--- a/mercurial/context.py	Fri Apr 06 13:11:40 2018 -0700
+++ b/mercurial/context.py	Sun Mar 25 18:27:43 2018 +0900
@@ -1330,6 +1330,11 @@
             p = p[:-1]
         return [changectx(self._repo, x) for x in p]
 
+    def _fileinfo(self, path):
+        # populate __dict__['_manifest'] as workingctx has no _manifestdelta
+        self._manifest
+        return super(workingctx, self)._fileinfo(path)
+
     def filectx(self, path, filelog=None):
         """get a file context from the working directory"""
         return workingfilectx(self._repo, path, workingctx=self,
--- a/tests/test-grep.t	Fri Apr 06 13:11:40 2018 -0700
+++ b/tests/test-grep.t	Sun Mar 25 18:27:43 2018 +0900
@@ -237,6 +237,17 @@
   $ hg grep -f port
   [1]
 
+Test wdir
+(at least, this shouldn't crash)
+
+  $ hg up -q
+  $ echo wport >> port2
+  $ hg stat
+  M port2
+  $ hg grep -r 'wdir()' port
+  abort: data/port2.i@303030303030: no node!
+  [255]
+
   $ cd ..
   $ hg init t2
   $ cd t2