[PATCH 2 of 3 STABLE] memctx: calculate manifest including newly added files correctly

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Dec 17 00:14:05 CST 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1418796583 -32400
#      Wed Dec 17 15:09:43 2014 +0900
# Branch stable
# Node ID cd53e1cddd771a95e6a2aa14a6539aa4449e3d05
# Parent  eb36b431bda6519e76b3f9868208272ebc0a3b12
memctx: calculate manifest including newly added files correctly

Before this patch, "memctx._manifest" calculates the manifest
according only form one of the 1st parent. This causes disappearance
of newly added files from the manifest.

For example, if newly added files aren't listed up in manifest of
memctx, they aren't listed up in "added" field of "status" returned by
"ctx.status()", and "{diff()}" (= "patch.diff") in "committemplate"
shows nothing for them.

To calculate manifest including newly added files correctly, this
patch puts newly added files (= ones in "self._status.added") into the
manifest.

Some details of changes for "test-commit-amend.t" in this patch:

  - "touch foo" is replaced by "echo foo > foo", because newly added
    empty file can't be shown in "diff()" output without "diff.git"
    configuration

  - amending is confirmed twice to examine both (1) newly added files
    and (2) ones already added in amended revision

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1693,6 +1693,9 @@
                     p2node = p[1].node()
             man[f] = revlog.hash(self[f].data(), p1node, p2node)
 
+        for f in self._status.added:
+            man[f] = revlog.hash(self[f].data(), nullid, nullid)
+
         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
@@ -805,7 +805,7 @@
   $ hg branch closewithamend
   marked working directory as branch closewithamend
   (branches are permanent and global, did you want a bookmark?)
-  $ touch foo
+  $ echo foo > foo
   $ hg add foo
   $ hg ci -m..
   $ hg ci --amend --close-branch -m 'closing'
@@ -857,6 +857,55 @@
   $ hg parents --template "{desc}\n"
   editor should be invoked
 
+Test that "diff()" in committemplate works correctly for amending
+-----------------------------------------------------------------
+
+  $ cat >> .hg/hgrc <<EOF
+  > [committemplate]
+  > changeset.commit.amend = {desc}\n
+  >     HG: M: {file_mods}
+  >     HG: A: {file_adds}
+  >     HG: R: {file_dels}
+  >     {splitlines(diff()) % 'HG: {line}\n'}
+  > EOF
+
+  $ hg parents --template "M: {file_mods}\nA: {file_adds}\nR: {file_dels}\n"
+  M: 
+  A: foo
+  R: 
+  $ hg status -amr
+  $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo"
+  expecting diff of foo
+  
+  HG: M: 
+  HG: A: foo
+  HG: R: 
+  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
+
+  $ echo y > y
+  $ hg add y
+  $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo and y"
+  expecting diff of foo and y
+  
+  HG: M: 
+  HG: A: foo y
+  HG: R: 
+  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
+
+
 Check for issue4405
 -------------------
 


More information about the Mercurial-devel mailing list