Patchwork D10571: revlog: deal with special "postfix" explicitely

login
register
mail settings
Submitter phabricator
Date May 3, 2021, 11:55 a.m.
Message ID <differential-rev-PHID-DREV-c24y5kmmteypc25crgjs-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48888/
State New
Headers show

Comments

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

REVISION SUMMARY
  revlog usually use a straight forward '.i' and '.d' naming except for two cases
  "in-transaction" changelog, and censoring. Our goal is to let the revlog code
  deal with the internal of the file naming itself. To do so, we need to start
  dealing with these postfix explicitly.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




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

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -289,6 +289,7 @@ 
         self,
         opener,
         target,
+        postfix=None,
         indexfile=None,
         datafile=None,
         checkambig=False,
@@ -312,9 +313,20 @@ 
         accurate value.
         """
         self.upperboundcomp = upperboundcomp
+        if not indexfile.endswith(b'.i'):
+            raise error.ProgrammingError(
+                b"revlog's indexfile should end with `.i`"
+            )
+        if datafile is None:
+            datafile = indexfile[:-2] + b".d"
+            if postfix is not None:
+                datafile = b'%s.%s' % (datafile, postfix)
+        if postfix is not None:
+            indexfile = b'%s.%s' % (indexfile, postfix)
         self.indexfile = indexfile
-        self.datafile = datafile or (indexfile[:-2] + b".d")
+        self.datafile = datafile
         self.nodemap_file = None
+        self.postfix = postfix
         if persistentnodemap:
             self.nodemap_file = nodemaputil.get_nodemap_file(
                 opener, self.indexfile
@@ -2881,16 +2893,13 @@ 
         # Rewriting the revlog in place is hard. Our strategy for censoring is
         # to create a new revlog, copy all revisions to it, then replace the
         # revlogs on transaction close.
-
-        newindexfile = self.indexfile + b'.tmpcensored'
-        newdatafile = self.datafile + b'.tmpcensored'
-
+        #
         # This is a bit dangerous. We could easily have a mismatch of state.
         newrl = revlog(
             self.opener,
             target=self.target,
-            indexfile=newindexfile,
-            datafile=newdatafile,
+            postfix=b'tmpcensored',
+            indexfile=self.indexfile,
             censorable=True,
         )
         newrl._format_version = self._format_version
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -395,16 +395,19 @@ 
         ``concurrencychecker`` will be passed to the revlog init function, see
         the documentation there.
         """
+
+        indexfile = b'00changelog.i'
         if trypending and opener.exists(b'00changelog.i.a'):
-            indexfile = b'00changelog.i.a'
+            postfix = b'a'
         else:
-            indexfile = b'00changelog.i'
+            postfix = None
 
         datafile = b'00changelog.d'
         revlog.revlog.__init__(
             self,
             opener,
             target=(revlog_constants.KIND_CHANGELOG, None),
+            postfix=postfix,
             indexfile=indexfile,
             datafile=datafile,
             checkambig=True,