[PATCH] memctx: fix manifest for removed files (issue4470)

Augie Fackler raf at durin42.com
Tue Dec 16 15:43:21 UTC 2014


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1418673654 18000
#      Mon Dec 15 15:00:54 2014 -0500
# Node ID 40bd85091fb37fc992e3af2128a8ed31f31a47ff
# Parent  65c854f92d6ba8861414ff3191182fba28777a82
memctx: fix manifest for removed files (issue4470)

filectxfn returns None for removed files, so we have to check for None
before computing the new file content hash for the manifest.

Includes a test that proves this works, by demonstrating that we can
show the diff of an amended commit in the committemplate.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1630,9 +1630,10 @@ class memctx(committablectx):
 
         # keep this simple for now; just worry about p1
         pctx = self._parents[0]
+        pman = pctx.manifest()
         man = pctx.manifest().copy()
 
-        for f, fnode in man.iteritems():
+        for f, fnode in pman.iteritems():
             p1node = nullid
             p2node = nullid
             p = pctx[f].parents() # if file isn't in pctx, check p2?
@@ -1640,7 +1641,12 @@ class memctx(committablectx):
                 p1node = p[0].node()
                 if len(p) > 1:
                     p2node = p[1].node()
-            man[f] = revlog.hash(self[f].data(), p1node, p2node)
+            fctx = self[f]
+            if fctx is None:
+                # removed file
+                del man[f]
+            else:
+                man[f] = revlog.hash(fctx.data(), p1node, p2node)
 
         return man
 
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -429,6 +429,68 @@ specific template keywords work well
   abort: empty commit message
   [255]
 
+prove that we can show a diff of an amend using committemplate:
+
+  $ hg init lol
+  $ cd lol
+  $ cat >> .hg/hgrc <<EOF
+  > [committemplate]
+  > changeset = {desc}\n\n
+  >      HG: {extramsg}
+  >      HG: user: {author}\n{ifeq(p2rev, "-1", "",
+  >     "HG: branch merge\n")
+  >     }HG: branch '{branch}'\n{if(currentbookmark,
+  >     "HG: bookmark '{currentbookmark}'\n")  }{subrepos %
+  >     "HG: subrepo {subrepo}\n"              }
+  >     {splitlines(diff()) % 'HG: {line}\n'}
+  > EOF
+  $ echo a > a
+  $ echo b > b
+  $ hg addr
+  adding a
+  adding b
+  $ hg ci -m 'init'
+  $ hg rm b
+  $ hg ci -m 'rm b'
+  $ hg export .
+  # HG changeset patch
+  # User test
+  # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
+  # Node ID 88d0ffa85e7a92ccc7c9cc187f9b17858bd206a7
+  # Parent  9118d25c26b1ca5cab5683b02100e7eb2c0d9471
+  rm b
+  
+  diff -r 9118d25c26b1 -r 88d0ffa85e7a b
+  --- a/b	Thu Jan 01 00:00:00 1970 +0000
+  +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,1 +0,0 @@
+  -b
+  $ echo a >> a
+  $ HGEDITOR=cat hg commit --amend
+  rm b
+  
+  
+  HG: Leave message empty to abort commit.
+  HG: user: test
+  HG: branch 'default'
+  
+  HG: diff -r 9118d25c26b1 a
+  HG: --- a/a	Thu Jan 01 00:00:00 1970 +0000
+  HG: +++ b/a	Thu Jan 01 00:00:00 1970 +0000
+  HG: @@ -1,1 +1,2 @@
+  HG:  a
+  HG: +a
+  HG: diff -r 9118d25c26b1 b
+  HG: --- a/b	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: -b
+  saved backup bundle to $TESTTMP/*/*-amend-backup.hg (glob)
+  $ cd ..
+  $ rm -r lol
+
+cleanup
   $ cat >> .hg/hgrc <<EOF
   > # disable customizing for subsequent tests
   > [committemplate]


More information about the Mercurial-devel mailing list