cmdutil: extract samefile function from amend()
authorHannes Oldenburg <hannes.christian.oldenburg@gmail.com>
Sun, 21 Aug 2016 08:00:18 +0000
changeset 29819 2cec6eaf3610
parent 29818 407879b0893b
child 29820 e1a4015f5e34
cmdutil: extract samefile function from amend()
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Fri Apr 22 21:32:30 2016 +0900
+++ b/mercurial/cmdutil.py	Sun Aug 21 08:00:18 2016 +0000
@@ -2604,6 +2604,18 @@
 
     return commitfunc(ui, repo, message, matcher, opts)
 
+def samefile(f, ctx1, ctx2):
+    if f in ctx1.manifest():
+        a = ctx1.filectx(f)
+        if f in ctx2.manifest():
+            b = ctx2.filectx(f)
+            return (not a.cmp(b)
+                    and a.flags() == b.flags())
+        else:
+            return False
+    else:
+        return f not in ctx2.manifest()
+
 def amend(ui, repo, commitfunc, old, extra, pats, opts):
     # avoid cycle context -> subrepo -> cmdutil
     from . import context
@@ -2687,19 +2699,7 @@
                 # we can discard X from our list of files. Likewise if X
                 # was deleted, it's no longer relevant
                 files.update(ctx.files())
-
-                def samefile(f):
-                    if f in ctx.manifest():
-                        a = ctx.filectx(f)
-                        if f in base.manifest():
-                            b = base.filectx(f)
-                            return (not a.cmp(b)
-                                    and a.flags() == b.flags())
-                        else:
-                            return False
-                    else:
-                        return f not in base.manifest()
-                files = [f for f in files if not samefile(f)]
+                files = [f for f in files if not samefile(f, ctx, base)]
 
                 def filectxfn(repo, ctx_, path):
                     try: