Patchwork [10,of,11] amend: use overlayfilectx

login
register
mail settings
Submitter Jun Wu
Date May 10, 2017, 8:34 a.m.
Message ID <c8bef30e0a55b7f71add.1494405269@x1c>
Download mbox | patch
Permalink /patch/20556/
State Accepted
Headers show

Comments

Jun Wu - May 10, 2017, 8:34 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1494397814 25200
#      Tue May 09 23:30:14 2017 -0700
# Node ID c8bef30e0a55b7f71add722b4f584bd813140eca
# Parent  9d4e0dc68196d113a7dd153748eea1cc731734d3
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r c8bef30e0a55
amend: use overlayfilectx

This simplifies the code and could speed things up, especially when
expensive flag processors are involved.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2658,13 +2658,9 @@  def amend(ui, repo, commitfunc, old, ext
                     try:
                         fctx = ctx[path]
-                        flags = fctx.flags()
-                        mctx = context.memfilectx(repo,
-                                                  fctx.path(), fctx.data(),
-                                                  islink='l' in flags,
-                                                  isexec='x' in flags,
-                                                  copied=copied.get(path))
-                        return mctx
                     except KeyError:
                         return None
+                    else:
+                        c = copied.get(path, False)
+                        return context.overlayfilectx(fctx, copied=c)
             else:
                 ui.note(_('copying changeset %s to %s\n') % (old, base))
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
@@ -1201,6 +1201,4 @@  File node could be reused
   committed changeset 2:92bc7a9d76f010337ece134e095054c094d44760
 
-(but is not smart enough to reuse manifest-only changes)
-
   $ chmod +x b
   $ hg ci --debug --amend -m 'without content change'
@@ -1214,5 +1212,7 @@  File node could be reused
   committing files:
   a
+  reusing a filelog node (exact match)
   b
+  reusing b filelog node (parent match)
   committing manifest
   committing changelog