changeset 51381:1d488f7be492

crecord: add `content` properties to all nodes In order to have a unified API of what can be searched, let's provide a `content` property to each node type. This way we can search filenames, context headers (e.g. containing function names, if deducible from patch context) or changed lines themselves.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Wed, 14 Feb 2024 22:43:51 -0500
parents e68908edebba
children ed0b78b2a3aa
files mercurial/crecord.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/crecord.py	Wed Feb 14 22:42:08 2024 -0500
+++ b/mercurial/crecord.py	Wed Feb 14 22:43:51 2024 -0500
@@ -86,6 +86,10 @@
     (i.e. patchroot, header, hunk, hunkline)
     """
 
+    @property
+    def content(self):
+        return b''
+
     def firstchild(self):
         raise NotImplementedError(b"method must be implemented by subclass")
 
@@ -223,6 +227,10 @@
         self.neverunfolded = True
         self.hunks = [uihunk(h, self) for h in self.hunks]
 
+    @property
+    def content(self):
+        return self.filename()
+
     def prettystr(self):
         x = stringio()
         self.pretty(x)
@@ -289,6 +297,10 @@
         # in the previtem method.
         self.folded = False
 
+    @property
+    def content(self):
+        return self.linetext
+
     def prettystr(self):
         return self.linetext
 
@@ -347,6 +359,10 @@
         # children are partially applied (i.e. some applied, some not).
         self.partial = False
 
+    @property
+    def content(self):
+        return self.proc if self.proc else b''
+
     def nextsibling(self):
         numhunksinheader = len(self.header.hunks)
         indexofthishunk = self.header.hunks.index(self)