comparison mercurial/cmdutil.py @ 29819:2cec6eaf3610

cmdutil: extract samefile function from amend()
author Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
date Sun, 21 Aug 2016 08:00:18 +0000
parents 35560189677c
children fa5e4f58dfbc
comparison
equal deleted inserted replaced
29818:407879b0893b 29819:2cec6eaf3610
2602 raise error.Abort( 2602 raise error.Abort(
2603 _("failed to mark all new/missing files as added/removed")) 2603 _("failed to mark all new/missing files as added/removed"))
2604 2604
2605 return commitfunc(ui, repo, message, matcher, opts) 2605 return commitfunc(ui, repo, message, matcher, opts)
2606 2606
2607 def samefile(f, ctx1, ctx2):
2608 if f in ctx1.manifest():
2609 a = ctx1.filectx(f)
2610 if f in ctx2.manifest():
2611 b = ctx2.filectx(f)
2612 return (not a.cmp(b)
2613 and a.flags() == b.flags())
2614 else:
2615 return False
2616 else:
2617 return f not in ctx2.manifest()
2618
2607 def amend(ui, repo, commitfunc, old, extra, pats, opts): 2619 def amend(ui, repo, commitfunc, old, extra, pats, opts):
2608 # avoid cycle context -> subrepo -> cmdutil 2620 # avoid cycle context -> subrepo -> cmdutil
2609 from . import context 2621 from . import context
2610 2622
2611 # amend will reuse the existing user if not specified, but the obsolete 2623 # amend will reuse the existing user if not specified, but the obsolete
2685 # introduced file X and our intermediate commit, node, 2697 # introduced file X and our intermediate commit, node,
2686 # renamed that file, then those two files are the same and 2698 # renamed that file, then those two files are the same and
2687 # we can discard X from our list of files. Likewise if X 2699 # we can discard X from our list of files. Likewise if X
2688 # was deleted, it's no longer relevant 2700 # was deleted, it's no longer relevant
2689 files.update(ctx.files()) 2701 files.update(ctx.files())
2690 2702 files = [f for f in files if not samefile(f, ctx, base)]
2691 def samefile(f):
2692 if f in ctx.manifest():
2693 a = ctx.filectx(f)
2694 if f in base.manifest():
2695 b = base.filectx(f)
2696 return (not a.cmp(b)
2697 and a.flags() == b.flags())
2698 else:
2699 return False
2700 else:
2701 return f not in base.manifest()
2702 files = [f for f in files if not samefile(f)]
2703 2703
2704 def filectxfn(repo, ctx_, path): 2704 def filectxfn(repo, ctx_, path):
2705 try: 2705 try:
2706 fctx = ctx[path] 2706 fctx = ctx[path]
2707 flags = fctx.flags() 2707 flags = fctx.flags()