# HG changeset patch # User Matt Mackall # Date 2007-03-23 00:52:38 # Node ID b11a2fb59cf5c8a396f76caab3291d692ae11d47 # Parent 1b5c38e9d7aa5dfd7981b9b5eefce1e895a62507 revlog: simplify revlog version handling - pass the default version as an attribute on the opener - eliminate config option mess diff --git a/mercurial/appendfile.py b/mercurial/appendfile.py --- a/mercurial/appendfile.py +++ b/mercurial/appendfile.py @@ -147,15 +147,15 @@ class appendopener(object): # not mixed up together. class appendchangelog(changelog.changelog, appendopener): - def __init__(self, opener, version): + def __init__(self, opener): appendopener.__init__(self, opener) - changelog.changelog.__init__(self, self, version) + changelog.changelog.__init__(self, self) def checkinlinesize(self, fp, tr): return class appendmanifest(manifest.manifest, appendopener): - def __init__(self, opener, version): + def __init__(self, opener): appendopener.__init__(self, opener) - manifest.manifest.__init__(self, self, version) + manifest.manifest.__init__(self, self) def checkinlinesize(self, fp, tr): return diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -27,8 +27,8 @@ def _string_unescape(text): return text.decode('string_escape') class changelog(revlog): - def __init__(self, opener, defversion=REVLOGV0): - revlog.__init__(self, opener, "00changelog.i", defversion) + def __init__(self, opener): + revlog.__init__(self, opener, "00changelog.i") def decode_extra(self, text): extra = {} diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -666,7 +666,7 @@ def copy(ui, repo, *pats, **opts): def debugancestor(ui, index, rev1, rev2): """find the ancestor revision of two revisions in a given index""" - r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, 0) + r = revlog.revlog(util.opener(os.getcwd(), audit=False), index) a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) ui.write("%d:%s\n" % (r.rev(a), hex(a))) @@ -794,9 +794,8 @@ def debugstate(ui, repo): ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) def debugdata(ui, file_, rev): - """dump the contents of an data file revision""" - r = revlog.revlog(util.opener(os.getcwd(), audit=False), - file_[:-2] + ".i", 0) + """dump the contents of a data file revision""" + r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i") try: ui.write(r.revision(r.lookup(rev))) except KeyError: @@ -816,7 +815,7 @@ def debugdate(ui, date, range=None, **op def debugindex(ui, file_): """dump the contents of an index file""" - r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, 0) + r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) ui.write(" rev offset length base linkrev" + " nodeid p1 p2\n") for i in xrange(r.count()): @@ -828,7 +827,7 @@ def debugindex(ui, file_): def debugindexdot(ui, file_): """dump an index DAG as a .dot file""" - r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, 0) + r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) ui.write("digraph G {\n") for i in xrange(r.count()): node = r.node(i) diff --git a/mercurial/filelog.py b/mercurial/filelog.py --- a/mercurial/filelog.py +++ b/mercurial/filelog.py @@ -9,10 +9,9 @@ from revlog import * import os class filelog(revlog): - def __init__(self, opener, path, defversion=REVLOG_DEFAULT_VERSION): + def __init__(self, opener, path): revlog.__init__(self, opener, - "/".join(("data", self.encodedir(path + ".i"))), - defversion) + "/".join(("data", self.encodedir(path + ".i")))) # This avoids a collision between a file named foo and a dir named # foo.i or foo.d diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -1018,7 +1018,7 @@ class hgweb(object): def do_capabilities(self, req): caps = ['lookup', 'changegroupsubset'] if self.configbool('server', 'uncompressed'): - caps.append('stream=%d' % self.repo.revlogversion) + caps.append('stream=%d' % self.repo.changelog.version) # XXX: make configurable and/or share code with do_unbundle: unbundleversions = ['HG10GZ', 'HG10BZ', 'HG10UN'] if unbundleversions: diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -88,34 +88,14 @@ class localrepository(repo.repository): except IOError: pass - v = self.ui.configrevlog() - self.revlogversion = int(v.get('format', revlog.REVLOG_DEFAULT_FORMAT)) - self.revlogv1 = self.revlogversion != revlog.REVLOGV0 - fl = v.get('flags', None) - flags = 0 - if fl != None: - for x in fl.split(): - flags |= revlog.flagstr(x) - elif self.revlogv1: - flags = revlog.REVLOG_DEFAULT_FLAGS - - v = self.revlogversion | flags - self.manifest = manifest.manifest(self.sopener, v) - self.changelog = changelog.changelog(self.sopener, v) + self.changelog = changelog.changelog(self.sopener) + self.sopener.defversion = self.changelog.version + self.manifest = manifest.manifest(self.sopener) fallback = self.ui.config('ui', 'fallbackencoding') if fallback: util._fallbackencoding = fallback - # the changelog might not have the inline index flag - # on. If the format of the changelog is the same as found in - # .hgrc, apply any flags found in the .hgrc as well. - # Otherwise, just version from the changelog - v = self.changelog.version - if v == self.revlogversion: - v |= flags - self.revlogversion = v - self.tagscache = None self.branchcache = None self.nodetagscache = None @@ -493,7 +473,7 @@ class localrepository(repo.repository): def file(self, f): if f[0] == '/': f = f[1:] - return filelog.filelog(self.sopener, f, self.revlogversion) + return filelog.filelog(self.sopener, f) def changectx(self, changeid=None): return context.changectx(self, changeid) @@ -1804,9 +1784,7 @@ class localrepository(repo.repository): # inconsistent view cl = None try: - cl = appendfile.appendchangelog(self.sopener, - self.changelog.version) - + cl = appendfile.appendchangelog(self.sopener) oldheads = len(cl.heads()) # pull off the changeset group @@ -1848,8 +1826,7 @@ class localrepository(repo.repository): cl.cleanup() # make changelog see real files again - self.changelog = changelog.changelog(self.sopener, - self.changelog.version) + self.changelog = changelog.changelog(self.sopener) self.changelog.checkinlinesize(tr) newheads = len(self.changelog.heads()) diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -35,10 +35,10 @@ class manifestdict(dict): return manifestdict(dict.copy(self), dict.copy(self._flags)) class manifest(revlog): - def __init__(self, opener, defversion=REVLOGV0): + def __init__(self, opener): self.mapcache = None self.listcache = None - revlog.__init__(self, opener, "00manifest.i", defversion) + revlog.__init__(self, opener, "00manifest.i") def parselines(self, lines): for l in lines.splitlines(1): diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -311,7 +311,7 @@ class revlog(object): remove data, and can use some simple techniques to avoid the need for locking while reading. """ - def __init__(self, opener, indexfile, defversion=REVLOG_DEFAULT_VERSION): + def __init__(self, opener, indexfile): """ create a revlog object @@ -325,7 +325,9 @@ class revlog(object): self.indexstat = None self.cache = None self.chunkcache = None - self.defversion = defversion + self.defversion=REVLOG_DEFAULT_VERSION + if hasattr(opener, "defversion"): + self.defversion = opener.defversion self.load() def load(self): diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py --- a/mercurial/sshserver.py +++ b/mercurial/sshserver.py @@ -73,7 +73,7 @@ class sshserver(object): caps = ['unbundle', 'lookup', 'changegroupsubset'] if self.ui.configbool('server', 'uncompressed'): - caps.append('stream=%d' % self.repo.revlogversion) + caps.append('stream=%d' % self.repo.changelog.version) self.respond("capabilities: %s\n" % (' '.join(caps),)) def do_lock(self): diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py --- a/mercurial/statichttprepo.py +++ b/mercurial/statichttprepo.py @@ -32,7 +32,6 @@ class statichttprepository(localrepo.loc def __init__(self, ui, path): self._url = path self.ui = ui - self.revlogversion = 0 self.path = (path + "/.hg") self.opener = opener(self.path) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -325,12 +325,6 @@ class ui(object): result.append(os.path.expanduser(value)) return result - def configrevlog(self): - result = {} - for key, value in self.configitems("revlog"): - result[key.lower()] = value - return result - def username(self): """Return default username to be used in commits. diff --git a/mercurial/verify.py b/mercurial/verify.py --- a/mercurial/verify.py +++ b/mercurial/verify.py @@ -39,8 +39,8 @@ def verify(repo): elif revlogv1: warn(_("warning: `%s' uses revlog format 0") % name) - revlogv1 = repo.revlogversion != revlog.REVLOGV0 - if repo.ui.verbose or revlogv1 != repo.revlogv1: + revlogv1 = repo.changelog.version != revlog.REVLOGV0 + if repo.ui.verbose or not revlogv1: repo.ui.status(_("repository uses revlog format %d\n") % (revlogv1 and 1 or 0))