changeset 44394:2bd3b95fdce0

copy: rewrite walkpat() to depend less on dirstate I want to add a `hg cp/mv -r <rev>` option to mark files as copied/moved in an existing commit (amending that commit). The code needs to not depend on the dirstate for that. Differential Revision: https://phab.mercurial-scm.org/D8031
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 20 Dec 2019 14:03:12 -0800
parents a69c08cdb2a8
children 27a78ea30b48
files mercurial/cmdutil.py
diffstat 1 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Feb 13 10:12:12 2020 -0800
+++ b/mercurial/cmdutil.py	Fri Dec 20 14:03:12 2019 -0800
@@ -1419,32 +1419,35 @@
     after = opts.get(b"after")
     dryrun = opts.get(b"dry_run")
     wctx = repo[None]
+    pctx = wctx.p1()
 
     uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
 
     def walkpat(pat):
         srcs = []
-        if after:
-            badstates = b'?'
-        else:
-            badstates = b'?r'
         m = scmutil.match(wctx, [pat], opts, globbed=True)
         for abs in wctx.walk(m):
-            state = repo.dirstate[abs]
             rel = uipathfn(abs)
             exact = m.exact(abs)
-            if state in badstates:
-                if exact and state == b'?':
-                    ui.warn(_(b'%s: not copying - file is not managed\n') % rel)
-                if exact and state == b'r':
-                    ui.warn(
-                        _(
-                            b'%s: not copying - file has been marked for'
-                            b' remove\n'
+            if abs not in wctx:
+                if abs in pctx:
+                    if not after:
+                        if exact:
+                            ui.warn(
+                                _(
+                                    b'%s: not copying - file has been marked '
+                                    b'for remove\n'
+                                )
+                                % rel
+                            )
+                        continue
+                else:
+                    if exact:
+                        ui.warn(
+                            _(b'%s: not copying - file is not managed\n') % rel
                         )
-                        % rel
-                    )
-                continue
+                    continue
+
             # abs: hgsep
             # rel: ossep
             srcs.append((abs, rel, exact))