changeset 47240:4f38ada3fc26

revlog: move the `trypending` logic from the `changelog` to the `revlog` We move the -reading- logic for the pending's '.a' suffixed index within the revlog class. This is motivated by the fact the logic could be simpler and cleaner if directly handled by the revlog docket. Before we can do so, we need to teach the revlog code about reading "pending" changes. To be honest, we already needed some special casing of the `.a` postfix, so this does not adds much complexity. The logic around -writing- the special '00changelog.i.a' remains in the `changelog` class. Note that the revlog-v2 logic no longer use this logic. The only remaining user of the `postfix` argument is the `censor` logic. We could probably also make the revlog full aware of it (most of the code is already implemented in revlog anyway) and get rid of the `postfix` argument and logic. However this is an adventure for another time. Since we have more information, we add more, paranoid, Programming error in case we detect such "pending reader" trying to do a read (which does not happens anyways). Differential Revision: https://phab.mercurial-scm.org/D10630
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:35:14 +0200
parents 682f09857d69
children 2219853a1503
files mercurial/changelog.py mercurial/revlog.py mercurial/revlogutils/nodemap.py
diffstat 3 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changelog.py	Mon May 03 12:35:02 2021 +0200
+++ b/mercurial/changelog.py	Mon May 03 12:35:14 2021 +0200
@@ -396,21 +396,16 @@
         the documentation there.
         """
 
-        if trypending and opener.exists(b'00changelog.i.a'):
-            postfix = b'a'
-        else:
-            postfix = None
-
         revlog.revlog.__init__(
             self,
             opener,
             target=(revlog_constants.KIND_CHANGELOG, None),
             radix=b'00changelog',
-            postfix=postfix,
             checkambig=True,
             mmaplargeindex=True,
             persistentnodemap=opener.options.get(b'persistent-nodemap', False),
             concurrencychecker=concurrencychecker,
+            trypending=trypending,
         )
 
         if self._initempty and (self._format_version == revlog.REVLOGV1):
--- a/mercurial/revlog.py	Mon May 03 12:35:02 2021 +0200
+++ b/mercurial/revlog.py	Mon May 03 12:35:14 2021 +0200
@@ -293,13 +293,14 @@
         opener,
         target,
         radix,
-        postfix=None,
+        postfix=None,  # only exist for `tmpcensored` now
         checkambig=False,
         mmaplargeindex=False,
         censorable=False,
         upperboundcomp=None,
         persistentnodemap=False,
         concurrencychecker=None,
+        trypending=False,
     ):
         """
         create a revlog object
@@ -323,6 +324,7 @@
         self._datafile = None
         self._nodemap_file = None
         self.postfix = postfix
+        self._trypending = trypending
         self.opener = opener
         if persistentnodemap:
             self._nodemap_file = nodemaputil.get_nodemap_file(self)
@@ -484,10 +486,12 @@
 
         new_header, mmapindexthreshold, force_nodemap = self._init_opts()
 
-        if self.postfix is None:
+        if self.postfix is not None:
+            entry_point = b'%s.i.%s' % (self.radix, self.postfix)
+        elif self._trypending and self.opener.exists(b'%s.i.a' % self.radix):
+            entry_point = b'%s.i.a' % self.radix
+        else:
             entry_point = b'%s.i' % self.radix
-        else:
-            entry_point = b'%s.i.%s' % (self.radix, self.postfix)
 
         entry_data = b''
         self._initempty = True
@@ -545,7 +549,7 @@
             # main docket, so disable it for now.
             self._nodemap_file = None
 
-        if self.postfix is None or self.postfix == b'a':
+        if self.postfix is None:
             self._datafile = b'%s.d' % self.radix
         else:
             self._datafile = b'%s.d.%s' % (self.radix, self.postfix)
@@ -2067,6 +2071,10 @@
 
     @contextlib.contextmanager
     def _writing(self, transaction):
+        if self._trypending:
+            msg = b'try to write in a `trypending` revlog: %s'
+            msg %= self.display_id
+            raise error.ProgrammingError(msg)
         if self._writinghandles is not None:
             yield
         else:
--- a/mercurial/revlogutils/nodemap.py	Mon May 03 12:35:02 2021 +0200
+++ b/mercurial/revlogutils/nodemap.py	Mon May 03 12:35:14 2021 +0200
@@ -649,7 +649,7 @@
 
 
 def get_nodemap_file(revlog):
-    if revlog.postfix == b'a':
+    if revlog._trypending:
         pending_path = revlog.radix + b".n.a"
         if revlog.opener.exists(pending_path):
             return pending_path