comparison mercurial/context.py @ 23584:db03ed8cbfa3

memctx: fix manifest for removed files (issue4470) filectxfn returns None for removed files, so we have to check for None before computing the new file content hash for the manifest. Includes a test that proves this works, by demonstrating that we can show the diff of an amended commit in the committemplate.
author Augie Fackler <augie@google.com>
date Mon, 15 Dec 2014 15:00:54 -0500
parents 114992041625
children 8063901e56cd
comparison
equal deleted inserted replaced
23583:a8edcb9c1199 23584:db03ed8cbfa3
1623 def _manifest(self): 1623 def _manifest(self):
1624 """generate a manifest based on the return values of filectxfn""" 1624 """generate a manifest based on the return values of filectxfn"""
1625 1625
1626 # keep this simple for now; just worry about p1 1626 # keep this simple for now; just worry about p1
1627 pctx = self._parents[0] 1627 pctx = self._parents[0]
1628 pman = pctx.manifest()
1628 man = pctx.manifest().copy() 1629 man = pctx.manifest().copy()
1629 1630
1630 for f, fnode in man.iteritems(): 1631 for f, fnode in pman.iteritems():
1631 p1node = nullid 1632 p1node = nullid
1632 p2node = nullid 1633 p2node = nullid
1633 p = pctx[f].parents() # if file isn't in pctx, check p2? 1634 p = pctx[f].parents() # if file isn't in pctx, check p2?
1634 if len(p) > 0: 1635 if len(p) > 0:
1635 p1node = p[0].node() 1636 p1node = p[0].node()
1636 if len(p) > 1: 1637 if len(p) > 1:
1637 p2node = p[1].node() 1638 p2node = p[1].node()
1638 man[f] = revlog.hash(self[f].data(), p1node, p2node) 1639 fctx = self[f]
1640 if fctx is None:
1641 # removed file
1642 del man[f]
1643 else:
1644 man[f] = revlog.hash(fctx.data(), p1node, p2node)
1639 1645
1640 return man 1646 return man
1641 1647
1642 1648
1643 class memfilectx(committablefilectx): 1649 class memfilectx(committablefilectx):