changeset 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 112f9c73a0e5
children 87a76cff7147
files mercurial/context.py tests/test-commit-amend.t tests/test-convert-svn-encoding.t tests/test-histedit-fold.t
diffstat 4 files changed, 45 insertions(+), 13 deletions(-) [+]
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.
--- a/tests/test-commit-amend.t	Fri Dec 12 12:31:41 2014 -0800
+++ b/tests/test-commit-amend.t	Wed Dec 17 15:09:38 2014 +0900
@@ -842,6 +842,8 @@
   $ hg parents --template "{desc}\n"
   editor should be suppressed
 
+  $ hg status --rev '.^1::.'
+  A foo
   $ HGEDITOR=cat hg commit --amend -m "editor should be invoked" --edit
   editor should be invoked
   
@@ -851,7 +853,7 @@
   HG: --
   HG: user: test
   HG: branch 'silliness'
-  HG: changed foo
+  HG: added foo
   $ hg parents --template "{desc}\n"
   editor should be invoked
 
--- a/tests/test-convert-svn-encoding.t	Fri Dec 12 12:31:41 2014 -0800
+++ b/tests/test-convert-svn-encoding.t	Wed Dec 17 15:09:38 2014 +0900
@@ -78,13 +78,11 @@
   reparent to file://*/svn-repo/trunk (glob)
   scanning paths: /trunk/\xc3\xb9 3/4 (75.00%) (esc)
   mark /trunk/\xc3\xb9 came from \xc3\xa0:2 (esc)
-  \xc3\xa0/e\xcc\x81 (esc)
   getting files: \xc3\xa0/e\xcc\x81 1/4 (25.00%) (esc)
+  getting files: \xc3\xa9 2/4 (50.00%) (esc)
   \xc3\xa8 (esc)
-  getting files: \xc3\xa8 2/4 (50.00%) (esc)
+  getting files: \xc3\xa8 3/4 (75.00%) (esc)
    \xc3\xa8: copy \xc3\xa9:6b67ccefd5ce6de77e7ead4f5292843a0255329f (esc)
-  \xc3\xa9 (esc)
-  getting files: \xc3\xa9 3/4 (75.00%) (esc)
   \xc3\xb9/e\xcc\x81 (esc)
   getting files: \xc3\xb9/e\xcc\x81 4/4 (100.00%) (esc)
    \xc3\xb9/e\xcc\x81: copy \xc3\xa0/e\xcc\x81:a9092a3d84a37b9993b5c73576f6de29b7ea50f6 (esc)
@@ -99,9 +97,7 @@
   gone from -1
   reparent to file://*/svn-repo (glob)
   reparent to file://*/svn-repo/trunk (glob)
-  \xc3\xa8 (esc)
   getting files: \xc3\xa8 1/2 (50.00%) (esc)
-  \xc3\xb9/e\xcc\x81 (esc)
   getting files: \xc3\xb9/e\xcc\x81 2/2 (100.00%) (esc)
   1 branch to branch?
   source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/branches/branch?@5
--- a/tests/test-histedit-fold.t	Fri Dec 12 12:31:41 2014 -0800
+++ b/tests/test-histedit-fold.t	Wed Dec 17 15:09:38 2014 +0900
@@ -172,11 +172,16 @@
   > EOF
 
   $ rm -f .hg/last-message.txt
-  $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit 8e03a72b6f83 --commands - 2>&1 <<EOF | fixbundle
+  $ hg status --rev '8e03a72b6f83^1::c4a9eb7989fc'
+  A c
+  A d
+  A f
+  $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit 8e03a72b6f83 --commands - 2>&1 <<EOF
   > pick 8e03a72b6f83 f
   > fold c4a9eb7989fc d
   > EOF
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  adding d
   allow non-folding commit
   0 files updated, 0 files merged, 3 files removed, 0 files unresolved
   ==== before editing
@@ -193,13 +198,14 @@
   HG: --
   HG: user: test
   HG: branch 'default'
-  HG: changed c
-  HG: changed d
-  HG: changed f
+  HG: added c
+  HG: added d
+  HG: added f
   ====
   transaction abort!
   rollback completed
   abort: pretxncommit.abortfolding hook failed
+  [255]
 
   $ cat .hg/last-message.txt
   f