Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/context.py Fri Dec 12 12:31:41 2014 -0800 +++ b/mercurial/context.py Wed Dec 17 15:09:38 2014 +0900 @@ -1583,8 +1583,7 @@ p1, p2 = parents self._parents = [changectx(self._repo, p) for p in (p1, p2)] files = sorted(set(files)) - self._status = scmutil.status(files, [], [], [], [], [], []) - self._filectxfn = filectxfn + self._files = files self.substate = {} # if store is not callable, wrap it in a function @@ -1600,6 +1599,10 @@ islink=fctx.islink(), isexec=fctx.isexec(), copied=copied, memctx=memctx) self._filectxfn = getfilectx + else: + # "util.cachefunc" reduces invocation of possibly expensive + # "filectxfn" for performance (e.g. converting from another VCS) + self._filectxfn = util.cachefunc(filectxfn) self._extra = extra and extra.copy() or {} if self._extra.get('branch', '') == '': @@ -1645,6 +1648,31 @@ return man + @propertycache + def _status(self): + """Calculate exact status from ``files`` specified at construction + """ + man1 = self.p1().manifest() + p2 = self._parents[1] + # "1 < len(self._parents)" can't be used for checking + # existence of the 2nd parent, because "memctx._parents" is + # explicitly initialized by the list, of which length is 2. + if p2.node() != nullid: + man2 = p2.manifest() + managing = lambda f: f in man1 or f in man2 + else: + managing = lambda f: f in man1 + + modified, added, removed = [], [], [] + for f in self._files: + if not managing(f): + added.append(f) + elif self[f]: + modified.append(f) + else: + removed.append(f) + + return scmutil.status(modified, added, removed, [], [], [], []) class memfilectx(committablefilectx): """memfilectx represents an in-memory file to commit.