comparison mercurial/context.py @ 23587:8063901e56cd

memctx: calculate exact status being committed from specified files Before this patch, "memctx._status" is initialized by "(files, [], [], [], [], [], [])" and this causes "memctx.modified" to include not only modified files but also added and removed ones incorrectly. This patch adds "_status" method to calculate exact status being committed according to "files" specified at construction time. Exact "_status" is useful to share/reuse logic of committablectx. This patch is also preparation for issues fixed by subsequent patches. Some details of changes for tests in this patch: - some filename lines are omitted in "test-convert-svn-encoding.t", because they are correctly listed up as "removed" files those lines are written out in "localrepository.commitctx" for "modified" and "added" files by "ui.note". - "| fixbundle" filterring in "test-histedit-fold.t" is omitted to check lines including "added" correctly "fixbundle" discards all lines including "added".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 17 Dec 2014 15:09:38 +0900
parents db03ed8cbfa3
children 87a76cff7147
comparison
equal deleted inserted replaced
23586:112f9c73a0e5 23587:8063901e56cd
1581 self._node = None 1581 self._node = None
1582 parents = [(p or nullid) for p in parents] 1582 parents = [(p or nullid) for p in parents]
1583 p1, p2 = parents 1583 p1, p2 = parents
1584 self._parents = [changectx(self._repo, p) for p in (p1, p2)] 1584 self._parents = [changectx(self._repo, p) for p in (p1, p2)]
1585 files = sorted(set(files)) 1585 files = sorted(set(files))
1586 self._status = scmutil.status(files, [], [], [], [], [], []) 1586 self._files = files
1587 self._filectxfn = filectxfn
1588 self.substate = {} 1587 self.substate = {}
1589 1588
1590 # if store is not callable, wrap it in a function 1589 # if store is not callable, wrap it in a function
1591 if not callable(filectxfn): 1590 if not callable(filectxfn):
1592 def getfilectx(repo, memctx, path): 1591 def getfilectx(repo, memctx, path):
1598 copied = copied[0] 1597 copied = copied[0]
1599 return memfilectx(repo, path, fctx.data(), 1598 return memfilectx(repo, path, fctx.data(),
1600 islink=fctx.islink(), isexec=fctx.isexec(), 1599 islink=fctx.islink(), isexec=fctx.isexec(),
1601 copied=copied, memctx=memctx) 1600 copied=copied, memctx=memctx)
1602 self._filectxfn = getfilectx 1601 self._filectxfn = getfilectx
1602 else:
1603 # "util.cachefunc" reduces invocation of possibly expensive
1604 # "filectxfn" for performance (e.g. converting from another VCS)
1605 self._filectxfn = util.cachefunc(filectxfn)
1603 1606
1604 self._extra = extra and extra.copy() or {} 1607 self._extra = extra and extra.copy() or {}
1605 if self._extra.get('branch', '') == '': 1608 if self._extra.get('branch', '') == '':
1606 self._extra['branch'] = 'default' 1609 self._extra['branch'] = 'default'
1607 1610
1643 else: 1646 else:
1644 man[f] = revlog.hash(fctx.data(), p1node, p2node) 1647 man[f] = revlog.hash(fctx.data(), p1node, p2node)
1645 1648
1646 return man 1649 return man
1647 1650
1651 @propertycache
1652 def _status(self):
1653 """Calculate exact status from ``files`` specified at construction
1654 """
1655 man1 = self.p1().manifest()
1656 p2 = self._parents[1]
1657 # "1 < len(self._parents)" can't be used for checking
1658 # existence of the 2nd parent, because "memctx._parents" is
1659 # explicitly initialized by the list, of which length is 2.
1660 if p2.node() != nullid:
1661 man2 = p2.manifest()
1662 managing = lambda f: f in man1 or f in man2
1663 else:
1664 managing = lambda f: f in man1
1665
1666 modified, added, removed = [], [], []
1667 for f in self._files:
1668 if not managing(f):
1669 added.append(f)
1670 elif self[f]:
1671 modified.append(f)
1672 else:
1673 removed.append(f)
1674
1675 return scmutil.status(modified, added, removed, [], [], [], [])
1648 1676
1649 class memfilectx(committablefilectx): 1677 class memfilectx(committablefilectx):
1650 """memfilectx represents an in-memory file to commit. 1678 """memfilectx represents an in-memory file to commit.
1651 1679
1652 See memctx and committablefilectx for more details. 1680 See memctx and committablefilectx for more details.