comparison mercurial/context.py @ 31259:6a9d0d24fdb4

context: move _manifest from committablectx to workingctx committablectx had a _manifest implementation that was only used by the derived workingctx class. The other derived versions, like memctx and metadataonlyctx, define their own _manifest functions. Let's move the function down to workingctx, and let's break it into two parts, the _manifest part that reads from self._status, and the part that actually builds the new manifest. This separation will let us reuse the builder code in a future patch to answer _buildstatus with varying status inputs, since workingctx has special behavior for _buildstatus that the other ctx's don't have.
author Durham Goode <durham@fb.com>
date Tue, 07 Mar 2017 17:56:30 -0800
parents c414e339e7af
children aac054e5389b
comparison
equal deleted inserted replaced
31258:c414e339e7af 31259:6a9d0d24fdb4
1264 @propertycache 1264 @propertycache
1265 def _flagfunc(self): 1265 def _flagfunc(self):
1266 return self._repo.dirstate.flagfunc(self._buildflagfunc) 1266 return self._repo.dirstate.flagfunc(self._buildflagfunc)
1267 1267
1268 @propertycache 1268 @propertycache
1269 def _manifest(self):
1270 """generate a manifest corresponding to the values in self._status
1271
1272 This reuse the file nodeid from parent, but we append an extra letter
1273 when modified. Modified files get an extra 'm' while added files get
1274 an extra 'a'. This is used by manifests merge to see that files
1275 are different and by update logic to avoid deleting newly added files.
1276 """
1277 parents = self.parents()
1278
1279 man = parents[0].manifest().copy()
1280
1281 ff = self._flagfunc
1282 for i, l in ((addednodeid, self._status.added),
1283 (modifiednodeid, self._status.modified)):
1284 for f in l:
1285 man[f] = i
1286 try:
1287 man.setflag(f, ff(f))
1288 except OSError:
1289 pass
1290
1291 for f in self._status.deleted + self._status.removed:
1292 if f in man:
1293 del man[f]
1294
1295 return man
1296
1297 @propertycache
1298 def _status(self): 1269 def _status(self):
1299 return self._repo.status() 1270 return self._repo.status()
1300 1271
1301 @propertycache 1272 @propertycache
1302 def _user(self): 1273 def _user(self):
1653 else: 1624 else:
1654 self._status = s 1625 self._status = s
1655 1626
1656 return s 1627 return s
1657 1628
1629 @propertycache
1630 def _manifest(self):
1631 """generate a manifest corresponding to the values in self._status
1632
1633 This reuse the file nodeid from parent, but we use special node
1634 identifiers for added and modified files. This is used by manifests
1635 merge to see that files are different and by update logic to avoid
1636 deleting newly added files.
1637 """
1638 return self._buildstatusmanifest(self._status)
1639
1640 def _buildstatusmanifest(self, status):
1641 """Builds a manifest that includes the given status results."""
1642 parents = self.parents()
1643
1644 man = parents[0].manifest().copy()
1645
1646 ff = self._flagfunc
1647 for i, l in ((addednodeid, status.added),
1648 (modifiednodeid, status.modified)):
1649 for f in l:
1650 man[f] = i
1651 try:
1652 man.setflag(f, ff(f))
1653 except OSError:
1654 pass
1655
1656 for f in status.deleted + status.removed:
1657 if f in man:
1658 del man[f]
1659
1660 return man
1661
1658 def _buildstatus(self, other, s, match, listignored, listclean, 1662 def _buildstatus(self, other, s, match, listignored, listclean,
1659 listunknown): 1663 listunknown):
1660 """build a status with respect to another context 1664 """build a status with respect to another context
1661 1665
1662 This includes logic for maintaining the fast path of status when 1666 This includes logic for maintaining the fast path of status when