Patchwork [1,of,2] cmdutil: extract samefile function from amend()

login
register
mail settings
Submitter Hannes Oldenburg
Date Aug. 21, 2016, 9:41 a.m.
Message ID <72c8a126a490dcb86903.1471772466@localhost.localdomain>
Download mbox | patch
Permalink /patch/16371/
State Accepted
Headers show

Comments

Hannes Oldenburg - Aug. 21, 2016, 9:41 a.m.
# HG changeset patch
# User Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
# Date 1471766418 0
#      Sun Aug 21 08:00:18 2016 +0000
# Node ID 72c8a126a490dcb86903b31632cb69f0803484d8
# Parent  b1809f5d7630a3fff0fa715bbd30dba0f07672a8
cmdutil: extract samefile function from amend()

Patch

diff -r b1809f5d7630 -r 72c8a126a490 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Mon Aug 15 20:39:33 2016 -0700
+++ 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: