Patchwork D8840: rename: add support for --at-rev, which marks as copy and removes the source

login
register
mail settings
Submitter phabricator
Date July 28, 2020, 5:24 p.m.
Message ID <differential-rev-PHID-DREV-2cqqkqfbcc33atwz2v4s-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46914/
State New
Headers show

Comments

phabricator - July 28, 2020, 5:24 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I had previously only added support for `--at-rev` to `hg cp`, but not
  to `hg mv`. This patch adds that support. Just like for `hg cp`, it
  marks the destination as copied from the source. Unlike `hg cp`, it
  also removes the source file. It works whether or not the source file
  still exists. This matches the behavior of `hg mv -A` in the working
  copy.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8840

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/commands.py
  tests/test-completion.t
  tests/test-rename-rev.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-rename-rev.t b/tests/test-rename-rev.t
--- a/tests/test-rename-rev.t
+++ b/tests/test-rename-rev.t
@@ -43,7 +43,7 @@ 
   A d1/d
     d1/b
 
-Test moved file (not copied)
+Test moved file (not copied) using 'hg cp' command
 
   $ hg co 0
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
@@ -59,6 +59,37 @@ 
     d1/b
   R d1/b
 
+Test moved file (not copied) using 'hg mv' command
+
+  $ hg co 0
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ mv d1/b d1/d
+  $ hg rm -A d1/b
+  $ hg add d1/d
+  $ hg ci -m 'move d1/b to d1/d'
+  created new head
+  $ hg mv -A --at-rev . d1/b d1/d
+  saved backup bundle to $TESTTMP/.hg/strip-backup/519850c3ea27-153c8fbb-copy.hg
+  $ hg st -C --change .
+  A d1/d
+    d1/b
+  R d1/b
+
+Test moved file (not copied) for which source still exists
+
+  $ hg co 0
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ cp d1/b d1/d
+  $ hg add d1/d
+  $ hg ci -m 'copy d1/b to d1/d'
+  created new head
+  $ hg mv -A --at-rev . d1/b d1/d
+  saved backup bundle to $TESTTMP/.hg/strip-backup/c8d0f6bcf7ca-1c9bb53e-copy.hg
+  $ hg st -C --change .
+  A d1/d
+    d1/b
+  R d1/b
+
 Test using directory as destination
 
   $ hg co 0
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -353,7 +353,7 @@ 
   push: force, rev, bookmark, branch, new-branch, pushvars, publish, ssh, remotecmd, insecure
   recover: verify
   remove: after, force, subrepos, include, exclude, dry-run
-  rename: after, force, include, exclude, dry-run
+  rename: after, at-rev, force, include, exclude, dry-run
   resolve: all, list, mark, unmark, no-status, re-merge, tool, include, exclude, template
   revert: all, date, rev, no-backup, interactive, include, exclude, dry-run
   rollback: dry-run, force
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5781,6 +5781,13 @@ 
     [
         (b'A', b'after', None, _(b'record a rename that has already occurred')),
         (
+            b'',
+            b'at-rev',
+            b'',
+            _(b'(un)mark renames in the given revision (EXPERIMENTAL)'),
+            _(b'REV'),
+        ),
+        (
             b'f',
             b'force',
             None,
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1566,6 +1566,8 @@ 
         mergemod.graft(repo, ctx, wctx=new_ctx)
 
         new_ctx.markcopied(absdest, copylist[0])
+        if rename:
+            new_ctx.remove(copylist[0])
 
         with repo.lock():
             mem_ctx = new_ctx.tomemctx_for_amend(ctx)