[PATCH 1 of 2 V2] memctx: calculate manifest more efficiently

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Dec 18 09:21:34 CST 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1418915516 -32400
#      Fri Dec 19 00:11:56 2014 +0900
# Node ID cb0aa20512befb6a8f5435c9b85a3b5335cad6c1
# Parent  c676d11f07d161d844beb02976f46a71b0c8a69e
memctx: calculate manifest more efficiently

Before this patch, "memctx._maniefst" updates all entries in the
(parent) manifest. But this is inefficiency, because almost all files
may be clean in that context.

On the other hand, just updating entries for changed "files" specified
at construction causes unexpected abortion, when there is at least one
newly removed file (see issue4470 for detail).

To calculate manifest more efficiently, this patch does:

  - replace "pman.iteritems()" for the loop by "self._status.modified"
    to avoid updating entries for clean or removed files

    Examination of removal is also omitted, because removed files
    aren't treated in this loop (= "self[f]" returns not None always).

  - remove entries for files in "self._status.removed" from the manifest

This patch adds a test to test-commit-amend.t, even though a similar
test for issue4470 already exists in test-commit.t, because:

  - another test for manifest calculation issue of memctx is added to
    test-commit-amend.t by previous patch, too

    centralization increases ease of maintenance

  - the test for issue4470 in test-commit.t should be placed in
    test-commit-amend.t, because it is the only test using "commit
    --amend" in test-commit.t

In this patch, amending is confirmed twice to examine that both (1)
newly removed file and (2) one already removed in amended revision
don't cause unexpected abortion like as issue4470.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1628,10 +1628,9 @@
 
         # keep this simple for now; just worry about p1
         pctx = self._parents[0]
-        pman = pctx.manifest()
         man = pctx.manifest().copy()
 
-        for f, fnode in pman.iteritems():
+        for f in self._status.modified:
             p1node = nullid
             p2node = nullid
             p = pctx[f].parents() # if file isn't in pctx, check p2?
@@ -1639,16 +1638,15 @@
                 p1node = p[0].node()
                 if len(p) > 1:
                     p2node = p[1].node()
-            fctx = self[f]
-            if fctx is None:
-                # removed file
-                del man[f]
-            else:
-                man[f] = revlog.hash(fctx.data(), p1node, p2node)
+            man[f] = revlog.hash(self[f].data(), p1node, p2node)
 
         for f in self._status.added:
             man[f] = revlog.hash(self[f].data(), nullid, nullid)
 
+        for f in self._status.removed:
+            if f in man:
+                del man[f]
+
         return man
 
     @propertycache
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -905,6 +905,58 @@
   HG: @@ -0,0 +1,1 @@
   HG: +y
 
+  $ hg rm a
+  $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo and y"
+  expecting diff of a, foo and y
+  
+  HG: M: 
+  HG: A: foo y
+  HG: R: a
+  HG: diff -r 6de0c1bde1c8 a
+  HG: --- a/a	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -1,2 +0,0 @@
+  HG: -a
+  HG: -a
+  HG: diff -r 6de0c1bde1c8 foo
+  HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -0,0 +1,1 @@
+  HG: +foo
+  HG: diff -r 6de0c1bde1c8 y
+  HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ b/y	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -0,0 +1,1 @@
+  HG: +y
+
+  $ hg rm x
+  $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo, x and y"
+  expecting diff of a, foo, x and y
+  
+  HG: M: 
+  HG: A: foo y
+  HG: R: a x
+  HG: diff -r 6de0c1bde1c8 a
+  HG: --- a/a	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -1,2 +0,0 @@
+  HG: -a
+  HG: -a
+  HG: diff -r 6de0c1bde1c8 foo
+  HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -0,0 +1,1 @@
+  HG: +foo
+  HG: diff -r 6de0c1bde1c8 x
+  HG: --- a/x	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -1,1 +0,0 @@
+  HG: -x
+  HG: diff -r 6de0c1bde1c8 y
+  HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ b/y	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -0,0 +1,1 @@
+  HG: +y
 
 Check for issue4405
 -------------------


More information about the Mercurial-devel mailing list