# HG changeset patch # User Pierre-Yves David # Date 2021-05-03 10:22:16 # Node ID a07d5cb03a85dd27c971740cda1c3af84958345b # Parent 8a1a51d31e8561e447f4fa9f540870311208f4b1 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 diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -2609,7 +2609,11 @@ def perfrevlogindex(ui, repo, file_=None 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 @@ def _temprevlog(ui, orig, truncaterev): 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 perfrevlogchunks(ui, repo, file_=Non 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) diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -84,12 +84,12 @@ class bundlerevlog(revlog.revlog): 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 @@ class bundlechangelog(bundlerevlog, chan self, opener, (revlog_constants.KIND_CHANGELOG, None), - self.indexfile, + self._indexfile, cgunpacker, linkmapper, ) @@ -201,7 +201,7 @@ class bundlemanifest(bundlerevlog, manif self, opener, (revlog_constants.KIND_MANIFESTLOG, dir), - self._revlog.indexfile, + self._revlog._indexfile, cgunpacker, linkmapper, ) @@ -233,7 +233,7 @@ class bundlefilelog(filelog.filelog): 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, ) diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -804,10 +804,10 @@ def _resolvenarrowrevisioninfo( # 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" diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -452,13 +452,13 @@ class changelog(revlog.revlog): 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 @@ class changelog(revlog.revlog): # 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 @@ class changelog(revlog.revlog): 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 @@ class changelog(revlog.revlog): # 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 diff --git a/mercurial/filelog.py b/mercurial/filelog.py --- a/mercurial/filelog.py +++ b/mercurial/filelog.py @@ -71,7 +71,7 @@ class filelog(object): def lookup(self, node): return storageutil.fileidlookup( - self._revlog, node, self._revlog.indexfile + self._revlog, node, self._revlog._indexfile ) def linkrev(self, rev): diff --git a/mercurial/repoview.py b/mercurial/repoview.py --- a/mercurial/repoview.py +++ b/mercurial/repoview.py @@ -333,7 +333,7 @@ class filteredchangelogmixin(object): 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 diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -323,13 +323,13 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): # 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): # 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): ): 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 @@ class revlog(object): # 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 @@ class revlog(object): """ 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 @@ class revlog(object): _( 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 @@ class revlog(object): """ 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 @@ class revlog(object): # 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): 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)) diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py --- a/mercurial/revlogutils/nodemap.py +++ b/mercurial/revlogutils/nodemap.py @@ -149,7 +149,7 @@ def persist_nodemap(tr, revlog, pending= 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" diff --git a/mercurial/unionrepo.py b/mercurial/unionrepo.py --- a/mercurial/unionrepo.py +++ b/mercurial/unionrepo.py @@ -165,7 +165,7 @@ class unionchangelog(unionrevlog, change linkmapper = None changelog2 = changelog.changelog(opener2) unionrevlog.__init__( - self, opener, self.indexfile, changelog2, linkmapper + self, opener, self._indexfile, changelog2, linkmapper ) @@ -174,7 +174,7 @@ class unionmanifest(unionrevlog, manifes 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 @@ class unionfilelog(filelog.filelog): 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 diff --git a/mercurial/upgrade_utils/engine.py b/mercurial/upgrade_utils/engine.py --- a/mercurial/upgrade_utils/engine.py +++ b/mercurial/upgrade_utils/engine.py @@ -80,12 +80,12 @@ def _copyrevlog(tr, destrepo, oldrl, rl_ 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) diff --git a/tests/test-contrib-perf.t b/tests/test-contrib-perf.t --- a/tests/test-contrib-perf.t +++ b/tests/test-contrib-perf.t @@ -411,7 +411,7 @@ Check perf.py for historical portability > 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) diff --git a/tests/test-revlog-raw.py b/tests/test-revlog-raw.py --- a/tests/test-revlog-raw.py +++ b/tests/test-revlog-raw.py @@ -204,7 +204,7 @@ def lowlevelcopy(rlog, tr, destname=b'_d 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(