# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 2024-02-15 03:43:51 # Node ID 1d488f7be492f17ad91b8bed577f7f758dfd396d # Parent e68908edebbad6549a6ef5ec012eb08b1fca7eb2 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. diff --git a/mercurial/crecord.py b/mercurial/crecord.py --- a/mercurial/crecord.py +++ b/mercurial/crecord.py @@ -86,6 +86,10 @@ class patchnode: (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 @@ class uiheader(patchnode): 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 @@ class uihunkline(patchnode): # in the previtem method. self.folded = False + @property + def content(self): + return self.linetext + def prettystr(self): return self.linetext @@ -347,6 +359,10 @@ class uihunk(patchnode): # 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)