Patchwork D10630: revlog: move the `trypending` logic from the `changelog` to the `revlog`

login
register
mail settings
Submitter phabricator
Date May 3, 2021, 12:08 p.m.
Message ID <differential-rev-PHID-DREV-gchrbklum4iwrcct6cu3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48948/
State New
Headers show

Comments

phabricator - May 3, 2021, 12:08 p.m.
marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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).

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10630

AFFECTED FILES
  mercurial/changelog.py
  mercurial/revlog.py
  mercurial/revlogutils/nodemap.py

CHANGE DETAILS




To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -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
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -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:
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -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):