Mercurial > public > mercurial-scm > hg
comparison mercurial/manifest.py @ 30368:ed45283a0ca7
manifest: remove dependency on manifestrevlog being able to create trees
A future patch will be removing the read() function from the manifest class.
Since manifestrevlog currently depends on the read function that manifest
implements (as a derived class), we need to break the dependency from
manifestrevlog to read(). We do this by adding an argument to
manifestrevlog.write() which provides it with the ability to read a manifest.
This is good in general because it further separates revlog as the storage
format from the actual inmemory data structure implementation.
author | Durham Goode <durham@fb.com> |
---|---|
date | Thu, 10 Nov 2016 02:13:19 -0800 |
parents | fa54f7ade491 |
children | d79c141fdf41 |
comparison
equal
deleted
inserted
replaced
30367:e193870eb680 | 30368:ed45283a0ca7 |
---|---|
1181 if dir not in self._dirlogcache: | 1181 if dir not in self._dirlogcache: |
1182 self._dirlogcache[dir] = manifestrevlog(self.opener, dir, | 1182 self._dirlogcache[dir] = manifestrevlog(self.opener, dir, |
1183 self._dirlogcache) | 1183 self._dirlogcache) |
1184 return self._dirlogcache[dir] | 1184 return self._dirlogcache[dir] |
1185 | 1185 |
1186 def add(self, m, transaction, link, p1, p2, added, removed): | 1186 def add(self, m, transaction, link, p1, p2, added, removed, readtree=None): |
1187 if (p1 in self.fulltextcache and util.safehasattr(m, 'fastdelta') | 1187 if (p1 in self.fulltextcache and util.safehasattr(m, 'fastdelta') |
1188 and not self._usemanifestv2): | 1188 and not self._usemanifestv2): |
1189 # If our first parent is in the manifest cache, we can | 1189 # If our first parent is in the manifest cache, we can |
1190 # compute a delta here using properties we know about the | 1190 # compute a delta here using properties we know about the |
1191 # manifest up-front, which may save time later for the | 1191 # manifest up-front, which may save time later for the |
1204 # The first parent manifest isn't already loaded, so we'll | 1204 # The first parent manifest isn't already loaded, so we'll |
1205 # just encode a fulltext of the manifest and pass that | 1205 # just encode a fulltext of the manifest and pass that |
1206 # through to the revlog layer, and let it handle the delta | 1206 # through to the revlog layer, and let it handle the delta |
1207 # process. | 1207 # process. |
1208 if self._treeondisk: | 1208 if self._treeondisk: |
1209 m1 = self.read(p1) | 1209 assert readtree, "readtree must be set for treemanifest writes" |
1210 m2 = self.read(p2) | 1210 m1 = readtree(self._dir, p1) |
1211 n = self._addtree(m, transaction, link, m1, m2) | 1211 m2 = readtree(self._dir, p2) |
1212 n = self._addtree(m, transaction, link, m1, m2, readtree) | |
1212 arraytext = None | 1213 arraytext = None |
1213 else: | 1214 else: |
1214 text = m.text(self._usemanifestv2) | 1215 text = m.text(self._usemanifestv2) |
1215 n = self.addrevision(text, transaction, link, p1, p2) | 1216 n = self.addrevision(text, transaction, link, p1, p2) |
1216 arraytext = array.array('c', text) | 1217 arraytext = array.array('c', text) |
1218 if arraytext is not None: | 1219 if arraytext is not None: |
1219 self.fulltextcache[n] = arraytext | 1220 self.fulltextcache[n] = arraytext |
1220 | 1221 |
1221 return n | 1222 return n |
1222 | 1223 |
1223 def _addtree(self, m, transaction, link, m1, m2): | 1224 def _addtree(self, m, transaction, link, m1, m2, readtree): |
1224 # If the manifest is unchanged compared to one parent, | 1225 # If the manifest is unchanged compared to one parent, |
1225 # don't write a new revision | 1226 # don't write a new revision |
1226 if m.unmodifiedsince(m1) or m.unmodifiedsince(m2): | 1227 if m.unmodifiedsince(m1) or m.unmodifiedsince(m2): |
1227 return m.node() | 1228 return m.node() |
1228 def writesubtree(subm, subp1, subp2): | 1229 def writesubtree(subm, subp1, subp2): |
1229 sublog = self.dirlog(subm.dir()) | 1230 sublog = self.dirlog(subm.dir()) |
1230 sublog.add(subm, transaction, link, subp1, subp2, None, None) | 1231 sublog.add(subm, transaction, link, subp1, subp2, None, None, |
1232 readtree=readtree) | |
1231 m.writesubtrees(m1, m2, writesubtree) | 1233 m.writesubtrees(m1, m2, writesubtree) |
1232 text = m.dirtext(self._usemanifestv2) | 1234 text = m.dirtext(self._usemanifestv2) |
1233 # Double-check whether contents are unchanged to one parent | 1235 # Double-check whether contents are unchanged to one parent |
1234 if text == m1.dirtext(self._usemanifestv2): | 1236 if text == m1.dirtext(self._usemanifestv2): |
1235 n = m1.node() | 1237 n = m1.node() |
1447 | 1449 |
1448 def read(self): | 1450 def read(self): |
1449 return self._treemanifest | 1451 return self._treemanifest |
1450 | 1452 |
1451 def write(self, transaction, link, p1, p2, added, removed): | 1453 def write(self, transaction, link, p1, p2, added, removed): |
1454 def readtree(dir, node): | |
1455 return self._repo.manifestlog.get(dir, node).read() | |
1452 return self._revlog().add(self._treemanifest, transaction, link, p1, p2, | 1456 return self._revlog().add(self._treemanifest, transaction, link, p1, p2, |
1453 added, removed) | 1457 added, removed, readtree=readtree) |
1454 | 1458 |
1455 class treemanifestctx(object): | 1459 class treemanifestctx(object): |
1456 def __init__(self, repo, dir, node): | 1460 def __init__(self, repo, dir, node): |
1457 self._repo = repo | 1461 self._repo = repo |
1458 self._dir = dir | 1462 self._dir = dir |