changeset 47148:a07d5cb03a85

revlog: rename `indexfile` to `_indexfile` We want to make the actual location of the indexfile and location more of an implementation details than what is is currently. In that process, we make the attribute private. Differential Revision: https://phab.mercurial-scm.org/D10574
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:22:16 +0200
parents 8a1a51d31e85
children 396442cd7e6a
files contrib/perf.py mercurial/bundlerepo.py mercurial/changegroup.py mercurial/changelog.py mercurial/filelog.py mercurial/repoview.py mercurial/revlog.py mercurial/revlogutils/nodemap.py mercurial/unionrepo.py mercurial/upgrade_utils/engine.py tests/test-contrib-perf.t tests/test-revlog-raw.py
diffstat 12 files changed, 88 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Mon May 03 12:22:06 2021 +0200
+++ b/contrib/perf.py	Mon May 03 12:22:16 2021 +0200
@@ -2609,7 +2609,11 @@
     rl = cmdutil.openrevlog(repo, b'perfrevlogindex', file_, opts)
 
     opener = getattr(rl, 'opener')  # trick linter
-    indexfile = rl.indexfile
+    # compat with hg <= 5.8
+    indexfile = getattr(rl, '_indexfile', None)
+    if indexfile is None:
+        # compatibility with <= hg-5.8
+        indexfile = getattr(rl, 'indexfile')
     data = opener.read(indexfile)
 
     header = struct.unpack(b'>I', data[0:4])[0]
@@ -3031,7 +3035,11 @@
     if util.safehasattr(orig, k):
         revlogkwargs[k] = getattr(orig, k)
 
-    origindexpath = orig.opener.join(orig.indexfile)
+    indexfile = getattr(orig, '_indexfile', None)
+    if indexfile is None:
+        # compatibility with <= hg-5.8
+        indexfile = getattr(orig, 'indexfile')
+    origindexpath = orig.opener.join(indexfile)
     origdatapath = orig.opener.join(orig.datafile)
     indexname = 'revlog.i'
     dataname = 'revlog.d'
@@ -3127,7 +3135,11 @@
 
     def rlfh(rl):
         if rl._inline:
-            return getsvfs(repo)(rl.indexfile)
+            indexfile = getattr(rl, '_indexfile', None)
+            if indexfile is None:
+                # compatibility with <= hg-5.8
+                indexfile = getattr(rl, 'indexfile')
+            return getsvfs(repo)(indexfile)
         else:
             return getsvfs(repo)(rl.datafile)
 
--- a/mercurial/bundlerepo.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/bundlerepo.py	Mon May 03 12:22:16 2021 +0200
@@ -84,12 +84,12 @@
             for p in (p1, p2):
                 if not self.index.has_node(p):
                     raise error.LookupError(
-                        p, self.indexfile, _(b"unknown parent")
+                        p, self._indexfile, _(b"unknown parent")
                     )
 
             if not self.index.has_node(deltabase):
                 raise LookupError(
-                    deltabase, self.indexfile, _(b'unknown delta base')
+                    deltabase, self._indexfile, _(b'unknown delta base')
                 )
 
             baserev = self.rev(deltabase)
@@ -180,7 +180,7 @@
             self,
             opener,
             (revlog_constants.KIND_CHANGELOG, None),
-            self.indexfile,
+            self._indexfile,
             cgunpacker,
             linkmapper,
         )
@@ -201,7 +201,7 @@
             self,
             opener,
             (revlog_constants.KIND_MANIFESTLOG, dir),
-            self._revlog.indexfile,
+            self._revlog._indexfile,
             cgunpacker,
             linkmapper,
         )
@@ -233,7 +233,7 @@
             opener,
             # XXX should use the unencoded path
             target=(revlog_constants.KIND_FILELOG, path),
-            indexfile=self._revlog.indexfile,
+            indexfile=self._revlog._indexfile,
             cgunpacker=cgunpacker,
             linkmapper=linkmapper,
         )
--- a/mercurial/changegroup.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/changegroup.py	Mon May 03 12:22:16 2021 +0200
@@ -804,10 +804,10 @@
                 # We failed to resolve a parent for this node, so
                 # we crash the changegroup construction.
                 if util.safehasattr(store, 'target'):
-                    target = store.indexfile
+                    target = store._indexfile
                 else:
                     # some revlog not actually a revlog
-                    target = store._revlog.indexfile
+                    target = store._revlog._indexfile
 
                 raise error.Abort(
                     b"unable to resolve parent while packing '%s' %r"
--- a/mercurial/changelog.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/changelog.py	Mon May 03 12:22:16 2021 +0200
@@ -452,13 +452,13 @@
         if not self._delayed:
             if len(self) == 0:
                 self._divert = True
-                if self._realopener.exists(self.indexfile + b'.a'):
-                    self._realopener.unlink(self.indexfile + b'.a')
-                self.opener = _divertopener(self._realopener, self.indexfile)
+                if self._realopener.exists(self._indexfile + b'.a'):
+                    self._realopener.unlink(self._indexfile + b'.a')
+                self.opener = _divertopener(self._realopener, self._indexfile)
             else:
                 self._delaybuf = []
                 self.opener = _delayopener(
-                    self._realopener, self.indexfile, self._delaybuf
+                    self._realopener, self._indexfile, self._delaybuf
                 )
         self._delayed = True
         tr.addpending(b'cl-%i' % id(self), self._writepending)
@@ -471,12 +471,12 @@
         # move redirected index data back into place
         if self._divert:
             assert not self._delaybuf
-            tmpname = self.indexfile + b".a"
+            tmpname = self._indexfile + b".a"
             nfile = self.opener.open(tmpname)
             nfile.close()
-            self.opener.rename(tmpname, self.indexfile, checkambig=True)
+            self.opener.rename(tmpname, self._indexfile, checkambig=True)
         elif self._delaybuf:
-            fp = self.opener(self.indexfile, b'a', checkambig=True)
+            fp = self.opener(self._indexfile, b'a', checkambig=True)
             fp.write(b"".join(self._delaybuf))
             fp.close()
             self._delaybuf = None
@@ -489,8 +489,8 @@
         pretxnchangegroup"""
         if self._delaybuf:
             # make a temporary copy of the index
-            fp1 = self._realopener(self.indexfile)
-            pendingfilename = self.indexfile + b".a"
+            fp1 = self._realopener(self._indexfile)
+            pendingfilename = self._indexfile + b".a"
             # register as a temp file to ensure cleanup on failure
             tr.registertmp(pendingfilename)
             # write existing data
@@ -502,7 +502,7 @@
             # switch modes so finalize can simply rename
             self._delaybuf = None
             self._divert = True
-            self.opener = _divertopener(self._realopener, self.indexfile)
+            self.opener = _divertopener(self._realopener, self._indexfile)
 
         if self._divert:
             return True
--- a/mercurial/filelog.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/filelog.py	Mon May 03 12:22:16 2021 +0200
@@ -71,7 +71,7 @@
 
     def lookup(self, node):
         return storageutil.fileidlookup(
-            self._revlog, node, self._revlog.indexfile
+            self._revlog, node, self._revlog._indexfile
         )
 
     def linkrev(self, rev):
--- a/mercurial/repoview.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/repoview.py	Mon May 03 12:22:16 2021 +0200
@@ -333,7 +333,7 @@
         r = super(filteredchangelogmixin, self).rev(node)
         if r in self.filteredrevs:
             raise error.FilteredLookupError(
-                hex(node), self.indexfile, _(b'filtered node')
+                hex(node), self._indexfile, _(b'filtered node')
             )
         return r
 
--- a/mercurial/revlog.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/revlog.py	Mon May 03 12:22:16 2021 +0200
@@ -323,13 +323,13 @@
                 datafile = b'%s.%s' % (datafile, postfix)
         if postfix is not None:
             indexfile = b'%s.%s' % (indexfile, postfix)
-        self.indexfile = indexfile
+        self._indexfile = indexfile
         self.datafile = datafile
         self.nodemap_file = None
         self.postfix = postfix
         if persistentnodemap:
             self.nodemap_file = nodemaputil.get_nodemap_file(
-                opener, self.indexfile
+                opener, self._indexfile
             )
 
         self.opener = opener
@@ -490,7 +490,7 @@
             if flags:
                 raise error.RevlogError(
                     _(b'unknown flags (%#04x) in version %d revlog %s')
-                    % (flags >> 16, fmt, self.indexfile)
+                    % (flags >> 16, fmt, self._indexfile)
                 )
 
             self._inline = False
@@ -500,7 +500,7 @@
             if flags & ~REVLOGV1_FLAGS:
                 raise error.RevlogError(
                     _(b'unknown flags (%#04x) in version %d revlog %s')
-                    % (flags >> 16, fmt, self.indexfile)
+                    % (flags >> 16, fmt, self._indexfile)
                 )
 
             self._inline = versionflags & FLAG_INLINE_DATA
@@ -510,7 +510,7 @@
             if flags & ~REVLOGV2_FLAGS:
                 raise error.RevlogError(
                     _(b'unknown flags (%#04x) in version %d revlog %s')
-                    % (flags >> 16, fmt, self.indexfile)
+                    % (flags >> 16, fmt, self._indexfile)
                 )
 
             # There is a bug in the transaction handling when going from an
@@ -523,7 +523,7 @@
 
         else:
             raise error.RevlogError(
-                _(b'unknown version (%d) in revlog %s') % (fmt, self.indexfile)
+                _(b'unknown version (%d) in revlog %s') % (fmt, self._indexfile)
             )
 
         self.nodeconstants = sha1nodeconstants
@@ -578,7 +578,7 @@
                         index.update_nodemap_data(*nodemap_data)
         except (ValueError, IndexError):
             raise error.RevlogError(
-                _(b"index %s is corrupted") % self.indexfile
+                _(b"index %s is corrupted") % self._indexfile
             )
         self.index, self._chunkcache = d
         if not self._chunkcache:
@@ -604,7 +604,7 @@
             args['checkambig'] = self._checkambig
         if mode == b'w':
             args['atomictemp'] = True
-        return self.opener(self.indexfile, **args)
+        return self.opener(self._indexfile, **args)
 
     def _datafp(self, mode=b'r'):
         """file object for the revlog's data file"""
@@ -729,7 +729,7 @@
                 or node in self.nodeconstants.wdirfilenodeids
             ):
                 raise error.WdirUnsupported
-            raise error.LookupError(node, self.indexfile, _(b'no node'))
+            raise error.LookupError(node, self._indexfile, _(b'no node'))
 
     # Accessors for index entries.
 
@@ -1393,7 +1393,7 @@
             # fast path: for unfiltered changelog, radix tree is accurate
             if not getattr(self, 'filteredrevs', None):
                 raise error.AmbiguousPrefixLookupError(
-                    id, self.indexfile, _(b'ambiguous identifier')
+                    id, self._indexfile, _(b'ambiguous identifier')
                 )
             # fall through to slow path that filters hidden revisions
         except (AttributeError, ValueError):
@@ -1419,7 +1419,7 @@
                         self._pcache[id] = nl[0]
                         return nl[0]
                     raise error.AmbiguousPrefixLookupError(
-                        id, self.indexfile, _(b'ambiguous identifier')
+                        id, self._indexfile, _(b'ambiguous identifier')
                     )
                 if maybewdir:
                     raise error.WdirUnsupported
@@ -1439,7 +1439,7 @@
         if n:
             return n
 
-        raise error.LookupError(id, self.indexfile, _(b'no match found'))
+        raise error.LookupError(id, self._indexfile, _(b'no match found'))
 
     def shortest(self, node, minlength=1):
         """Find the shortest unambiguous prefix that matches node."""
@@ -1453,7 +1453,7 @@
                 # single 'ff...' match
                 return True
             if matchednode is None:
-                raise error.LookupError(node, self.indexfile, _(b'no node'))
+                raise error.LookupError(node, self._indexfile, _(b'no node'))
             return True
 
         def maybewdir(prefix):
@@ -1474,7 +1474,9 @@
                 return disambiguate(hexnode, length)
             except error.RevlogError:
                 if node != self.nodeconstants.wdirid:
-                    raise error.LookupError(node, self.indexfile, _(b'no node'))
+                    raise error.LookupError(
+                        node, self._indexfile, _(b'no node')
+                    )
             except AttributeError:
                 # Fall through to pure code
                 pass
@@ -1545,7 +1547,7 @@
                         b'offset %d, got %d'
                     )
                     % (
-                        self.indexfile if self._inline else self.datafile,
+                        self._indexfile if self._inline else self.datafile,
                         length,
                         realoffset,
                         len(d) - startoffset,
@@ -1561,7 +1563,7 @@
                     b'%d, got %d'
                 )
                 % (
-                    self.indexfile if self._inline else self.datafile,
+                    self._indexfile if self._inline else self.datafile,
                     length,
                     offset,
                     len(d),
@@ -1932,11 +1934,11 @@
                     revornode = templatefilters.short(hex(node))
                 raise error.RevlogError(
                     _(b"integrity check failed on %s:%s")
-                    % (self.indexfile, pycompat.bytestr(revornode))
+                    % (self._indexfile, pycompat.bytestr(revornode))
                 )
         except error.RevlogError:
             if self._censorable and storageutil.iscensoredtext(text):
-                raise error.CensoredNodeError(self.indexfile, node, text)
+                raise error.CensoredNodeError(self._indexfile, node, text)
             raise
 
     def _enforceinlinesize(self, tr, fp=None):
@@ -1953,10 +1955,10 @@
         ):
             return
 
-        troffset = tr.findoffset(self.indexfile)
+        troffset = tr.findoffset(self._indexfile)
         if troffset is None:
             raise error.RevlogError(
-                _(b"%s not found in the transaction") % self.indexfile
+                _(b"%s not found in the transaction") % self._indexfile
             )
         trindex = 0
         tr.add(self.datafile, 0)
@@ -1988,7 +1990,7 @@
             # the temp file replace the real index when we exit the context
             # manager
 
-        tr.replace(self.indexfile, trindex * self.index.entry_size)
+        tr.replace(self._indexfile, trindex * self.index.entry_size)
         nodemaputil.setup_persistent_nodemap(tr, self)
         self._chunkclear()
 
@@ -2024,7 +2026,7 @@
         """
         if link == nullrev:
             raise error.RevlogError(
-                _(b"attempted to add linkrev -1 to %s") % self.indexfile
+                _(b"attempted to add linkrev -1 to %s") % self._indexfile
             )
 
         if sidedata is None:
@@ -2049,7 +2051,7 @@
                 _(
                     b"%s: size of %d bytes exceeds maximum revlog storage of 2GiB"
                 )
-                % (self.indexfile, len(rawtext))
+                % (self._indexfile, len(rawtext))
             )
 
         node = node or self.hash(rawtext, p1, p2)
@@ -2220,14 +2222,14 @@
         """
         if node == self.nullid:
             raise error.RevlogError(
-                _(b"%s: attempt to add null revision") % self.indexfile
+                _(b"%s: attempt to add null revision") % self._indexfile
             )
         if (
             node == self.nodeconstants.wdirid
             or node in self.nodeconstants.wdirfilenodeids
         ):
             raise error.RevlogError(
-                _(b"%s: attempt to add wdir revision") % self.indexfile
+                _(b"%s: attempt to add wdir revision") % self._indexfile
             )
 
         if self._inline:
@@ -2247,12 +2249,12 @@
                 # offset is "as if" it were in the .d file, so we need to add on
                 # the size of the entry metadata.
                 self._concurrencychecker(
-                    ifh, self.indexfile, offset + curr * self.index.entry_size
+                    ifh, self._indexfile, offset + curr * self.index.entry_size
                 )
             else:
                 # Entries in the .i are a consistent size.
                 self._concurrencychecker(
-                    ifh, self.indexfile, curr * self.index.entry_size
+                    ifh, self._indexfile, curr * self.index.entry_size
                 )
                 self._concurrencychecker(dfh, self.datafile, offset)
 
@@ -2369,7 +2371,7 @@
         curr = len(self) - 1
         if not self._inline:
             transaction.add(self.datafile, offset)
-            transaction.add(self.indexfile, curr * len(entry))
+            transaction.add(self._indexfile, curr * len(entry))
             if data[0]:
                 dfh.write(data[0])
             dfh.write(data[1])
@@ -2378,7 +2380,7 @@
             ifh.write(entry)
         else:
             offset += curr * self.index.entry_size
-            transaction.add(self.indexfile, offset)
+            transaction.add(self._indexfile, offset)
             ifh.write(entry)
             ifh.write(data[0])
             ifh.write(data[1])
@@ -2417,10 +2419,10 @@
         ifh = self._indexfp(b"a+")
         isize = r * self.index.entry_size
         if self._inline:
-            transaction.add(self.indexfile, end + isize)
+            transaction.add(self._indexfile, end + isize)
             dfh = None
         else:
-            transaction.add(self.indexfile, isize)
+            transaction.add(self._indexfile, isize)
             transaction.add(self.datafile, end)
             dfh = self._datafp(b"a+")
 
@@ -2452,12 +2454,12 @@
                 for p in (p1, p2):
                     if not self.index.has_node(p):
                         raise error.LookupError(
-                            p, self.indexfile, _(b'unknown parent')
+                            p, self._indexfile, _(b'unknown parent')
                         )
 
                 if not self.index.has_node(deltabase):
                     raise error.LookupError(
-                        deltabase, self.indexfile, _(b'unknown delta base')
+                        deltabase, self._indexfile, _(b'unknown delta base')
                     )
 
                 baserev = self.rev(deltabase)
@@ -2470,7 +2472,7 @@
                     newlen = len(delta) - hlen
                     if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen):
                         raise error.CensoredBaseError(
-                            self.indexfile, self.node(baserev)
+                            self._indexfile, self.node(baserev)
                         )
 
                 if not flags and self._peek_iscensored(baserev, delta, flush):
@@ -2575,7 +2577,7 @@
         else:
             end += rev * self.index.entry_size
 
-        transaction.add(self.indexfile, end)
+        transaction.add(self._indexfile, end)
 
         # then reset internal state in memory to forget those revisions
         self._revisioncache = None
@@ -2608,7 +2610,7 @@
             dd = 0
 
         try:
-            f = self.opener(self.indexfile)
+            f = self.opener(self._indexfile)
             f.seek(0, io.SEEK_END)
             actual = f.tell()
             f.close()
@@ -2629,7 +2631,7 @@
         return (dd, di)
 
     def files(self):
-        res = [self.indexfile]
+        res = [self._indexfile]
         if not self._inline:
             res.append(self.datafile)
         return res
@@ -2847,7 +2849,7 @@
                     flags = flags | new_flags[0] & ~new_flags[1]
 
                 ifh = destrevlog.opener(
-                    destrevlog.indexfile, b'a+', checkambig=False
+                    destrevlog._indexfile, b'a+', checkambig=False
                 )
                 dfh = None
                 if not destrevlog._inline:
@@ -2899,7 +2901,7 @@
             self.opener,
             target=self.target,
             postfix=b'tmpcensored',
-            indexfile=self.indexfile,
+            indexfile=self._indexfile,
             censorable=True,
         )
         newrl._format_version = self._format_version
@@ -2952,11 +2954,11 @@
                 rawtext, tr, self.linkrev(rev), p1, p2, node, self.flags(rev)
             )
 
-        tr.addbackup(self.indexfile, location=b'store')
+        tr.addbackup(self._indexfile, location=b'store')
         if not self._inline:
             tr.addbackup(self.datafile, location=b'store')
 
-        self.opener.rename(newrl.indexfile, self.indexfile)
+        self.opener.rename(newrl._indexfile, self._indexfile)
         if not self._inline:
             self.opener.rename(newrl.datafile, self.datafile)
 
@@ -2981,7 +2983,7 @@
         if version != state[b'expectedversion']:
             yield revlogproblem(
                 warning=_(b"warning: '%s' uses revlog format %d; expected %d")
-                % (self.indexfile, version, state[b'expectedversion'])
+                % (self._indexfile, version, state[b'expectedversion'])
             )
 
         state[b'skipread'] = set()
@@ -3079,7 +3081,7 @@
         d = {}
 
         if exclusivefiles:
-            d[b'exclusivefiles'] = [(self.opener, self.indexfile)]
+            d[b'exclusivefiles'] = [(self.opener, self._indexfile)]
             if not self._inline:
                 d[b'exclusivefiles'].append((self.opener, self.datafile))
 
--- a/mercurial/revlogutils/nodemap.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/revlogutils/nodemap.py	Mon May 03 12:22:16 2021 +0200
@@ -149,7 +149,7 @@
     if revlog.nodemap_file is None:
         if force:
             revlog.nodemap_file = get_nodemap_file(
-                revlog.opener, revlog.indexfile
+                revlog.opener, revlog._indexfile
             )
         else:
             msg = "calling persist nodemap on a revlog without the feature enabled"
--- a/mercurial/unionrepo.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/unionrepo.py	Mon May 03 12:22:16 2021 +0200
@@ -165,7 +165,7 @@
         linkmapper = None
         changelog2 = changelog.changelog(opener2)
         unionrevlog.__init__(
-            self, opener, self.indexfile, changelog2, linkmapper
+            self, opener, self._indexfile, changelog2, linkmapper
         )
 
 
@@ -174,7 +174,7 @@
         manifest.manifestrevlog.__init__(self, nodeconstants, opener)
         manifest2 = manifest.manifestrevlog(nodeconstants, opener2)
         unionrevlog.__init__(
-            self, opener, self._revlog.indexfile, manifest2, linkmapper
+            self, opener, self._revlog._indexfile, manifest2, linkmapper
         )
 
 
@@ -183,7 +183,7 @@
         filelog.filelog.__init__(self, opener, path)
         filelog2 = filelog.filelog(opener2, path)
         self._revlog = unionrevlog(
-            opener, self._revlog.indexfile, filelog2._revlog, linkmapper
+            opener, self._revlog._indexfile, filelog2._revlog, linkmapper
         )
         self._repo = repo
         self.repotiprev = self._revlog.repotiprev
--- a/mercurial/upgrade_utils/engine.py	Mon May 03 12:22:06 2021 +0200
+++ b/mercurial/upgrade_utils/engine.py	Mon May 03 12:22:16 2021 +0200
@@ -80,12 +80,12 @@
 
     oldvfs = oldrl.opener
     newvfs = newrl.opener
-    oldindex = oldvfs.join(oldrl.indexfile)
-    newindex = newvfs.join(newrl.indexfile)
+    oldindex = oldvfs.join(oldrl._indexfile)
+    newindex = newvfs.join(newrl._indexfile)
     olddata = oldvfs.join(oldrl.datafile)
     newdata = newvfs.join(newrl.datafile)
 
-    with newvfs(newrl.indexfile, b'w'):
+    with newvfs(newrl._indexfile, b'w'):
         pass  # create all the directories
 
     util.copyfile(oldindex, newindex)
--- a/tests/test-contrib-perf.t	Mon May 03 12:22:06 2021 +0200
+++ b/tests/test-contrib-perf.t	Mon May 03 12:22:16 2021 +0200
@@ -411,7 +411,7 @@
    >     from mercurial import (
    import newer module separately in try clause for early Mercurial
   contrib/perf.py:\d+: (re)
-   >     origindexpath = orig.opener.join(orig.indexfile)
+   >     origindexpath = orig.opener.join(indexfile)
    use getvfs()/getsvfs() for early Mercurial
   contrib/perf.py:\d+: (re)
    >     origdatapath = orig.opener.join(orig.datafile)
--- a/tests/test-revlog-raw.py	Mon May 03 12:22:06 2021 +0200
+++ b/tests/test-revlog-raw.py	Mon May 03 12:22:16 2021 +0200
@@ -204,7 +204,7 @@
         flags = rlog.flags(r)
         ifh = dfh = None
         try:
-            ifh = dlog.opener(dlog.indexfile, b'a+')
+            ifh = dlog.opener(dlog._indexfile, b'a+')
             if not dlog._inline:
                 dfh = dlog.opener(dlog.datafile, b'a+')
             dlog._addrevision(