Patchwork [2,of,7] changelog: add a `changes` property on `changelogrevision`

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 23, 2020, 9:51 p.m.
Message ID <4ca4cc404afd6ec3dc4a.1600897911@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/47264/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 23, 2020, 9:51 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1600177052 -7200
#      Tue Sep 15 15:37:32 2020 +0200
# Node ID 4ca4cc404afd6ec3dc4a61b2d68b33e1aa7f1cf6
# Parent  383317c8b1438d445d8d16f3fe769492d3d994b1
# EXP-Topic new-metadata-pre
# Available At https://foss.heptapod.net/octobus/mercurial-devel/
#              hg pull https://foss.heptapod.net/octobus/mercurial-devel/ -r 4ca4cc404afd
changelog: add a `changes` property on `changelogrevision`

For the sidedata storage we are moving toward "all in one" block containing the
equivalent of a "ChangingFiles" instance. We do various refactoring beforehand
to prepare the usage of theses new data in the code.

Since the object use slots, the "property cache" tricks cannot be used, and we
cache the value manually.

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -216,6 +216,7 @@  class changelogrevision(object):
         '_text',
         '_sidedata',
         '_cpsd',
+        '_changes',
     )
 
     def __new__(cls, text, sidedata, cpsd):
@@ -252,6 +253,7 @@  class changelogrevision(object):
         self._text = text
         self._sidedata = sidedata
         self._cpsd = cpsd
+        self._changes = None
 
         return self
 
@@ -301,6 +303,20 @@  class changelogrevision(object):
         return decodeextra(raw)
 
     @property
+    def changes(self):
+        if self._changes is not None:
+            return self._changes
+        changes = metadata.ChangingFiles(
+            touched=self.files or (),
+            added=self.filesadded or (),
+            removed=self.filesremoved or (),
+            p1_copies=self.p1copies or {},
+            p2_copies=self.p2copies or {},
+        )
+        self._changes = changes
+        return changes
+
+    @property
     def files(self):
         off = self._offsets
         if off[2] == off[3]: