diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -286,13 +286,12 @@ def addremove(repo, pats=[], opts={}, dr if not dry_run: repo.copy(old, new) -def copy(ui, repo, pats, opts): +def copy(ui, repo, pats, opts, rename=False): # called with the repo lock held # # hgsep => pathname that uses "/" to separate directories # ossep => pathname that uses os.sep to separate directories cwd = repo.getcwd() - copied = [] targets = {} after = opts.get("after") dryrun = opts.get("dry_run") @@ -359,7 +358,8 @@ def copy(ui, repo, pats, opts): return True # report a failure if ui.verbose or not exact: - ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) + action = rename and "moving" or "copying" + ui.status(_('%s %s to %s\n') % (action, relsrc, reltarget)) targets[abstarget] = abssrc @@ -378,7 +378,9 @@ def copy(ui, repo, pats, opts): repo.add([abstarget]) elif not dryrun: repo.copy(origsrc, abstarget) - copied.append((abssrc, relsrc, exact)) + + if rename and not dryrun: + repo.remove([abssrc], True) # pat: ossep # dest ossep @@ -482,7 +484,7 @@ def copy(ui, repo, pats, opts): if errors: ui.warn(_('(consider using --after)\n')) - return errors, copied + return errors def service(opts, parentfn=None, initfn=None, runfn=None): '''Run a command as a service.''' diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -454,10 +454,9 @@ def copy(ui, repo, *pats, **opts): """ wlock = repo.wlock(False) try: - errs, copied = cmdutil.copy(ui, repo, pats, opts) + return cmdutil.copy(ui, repo, pats, opts) finally: del wlock - return errs def debugancestor(ui, index, rev1, rev2): """find the ancestor revision of two revisions in a given index""" @@ -2062,15 +2061,7 @@ def rename(ui, repo, *pats, **opts): """ wlock = repo.wlock(False) try: - errs, copied = cmdutil.copy(ui, repo, pats, opts) - names = [] - for abs, rel, exact in copied: - if ui.verbose or not exact: - ui.status(_('removing %s\n') % rel) - names.append(abs) - if not opts.get('dry_run'): - repo.remove(names, True) - return errs + return cmdutil.copy(ui, repo, pats, opts, rename=True) finally: del wlock diff --git a/tests/test-issue612.out b/tests/test-issue612.out --- a/tests/test-issue612.out +++ b/tests/test-issue612.out @@ -1,6 +1,5 @@ adding src/a.c -copying src/a.c to source/a.c -removing src/a.c +moving src/a.c to source/a.c 1 files updated, 0 files merged, 1 files removed, 0 files unresolved ? src/a.o merging src/a.c and source/a.c diff --git a/tests/test-rename-dir-merge.out b/tests/test-rename-dir-merge.out --- a/tests/test-rename-dir-merge.out +++ b/tests/test-rename-dir-merge.out @@ -1,10 +1,8 @@ adding a/a adding a/b 0 files updated, 0 files merged, 0 files removed, 0 files unresolved -copying a/a to b/a -copying a/b to b/b -removing a/a -removing a/b +moving a/a to b/a +moving a/b to b/b 2 files updated, 0 files merged, 2 files removed, 0 files unresolved resolving manifests overwrite None partial False diff --git a/tests/test-rename-dir-merge2.out b/tests/test-rename-dir-merge2.out --- a/tests/test-rename-dir-merge2.out +++ b/tests/test-rename-dir-merge2.out @@ -1,7 +1,6 @@ adding a/f 1 files updated, 0 files merged, 0 files removed, 0 files unresolved -copying a/f to b/f -removing a/f +moving a/f to b/f adding a/aa/g pulling from ../r2 searching for changes diff --git a/tests/test-rename.out b/tests/test-rename.out --- a/tests/test-rename.out +++ b/tests/test-rename.out @@ -29,14 +29,10 @@ A d1/d11/e R d2/b 1 files updated, 0 files merged, 1 files removed, 0 files unresolved # rename directory d1 as d3 -copying d1/a to d3/a -copying d1/b to d3/b -copying d1/ba to d3/ba -copying d1/d11/a1 to d3/d11/a1 -removing d1/a -removing d1/b -removing d1/ba -removing d1/d11/a1 +moving d1/a to d3/a +moving d1/b to d3/b +moving d1/ba to d3/ba +moving d1/d11/a1 to d3/d11/a1 A d3/a d1/a A d3/b @@ -51,14 +47,10 @@ R d1/ba R d1/d11/a1 4 files updated, 0 files merged, 4 files removed, 0 files unresolved # rename --after directory d1 as d3 -copying d1/a to d3/a -copying d1/b to d3/b -copying d1/ba to d3/ba -copying d1/d11/a1 to d3/d11/a1 -removing d1/a -removing d1/b -removing d1/ba -removing d1/d11/a1 +moving d1/a to d3/a +moving d1/b to d3/b +moving d1/ba to d3/ba +moving d1/d11/a1 to d3/d11/a1 A d3/a d1/a A d3/b @@ -73,37 +65,29 @@ R d1/ba R d1/d11/a1 4 files updated, 0 files merged, 4 files removed, 0 files unresolved # move a directory using a relative path -copying ../d1/d11/a1 to d3/d11/a1 -removing ../d1/d11/a1 +moving ../d1/d11/a1 to d3/d11/a1 A d2/d3/d11/a1 d1/d11/a1 R d1/d11/a1 1 files updated, 0 files merged, 1 files removed, 0 files unresolved # move --after a directory using a relative path -copying ../d1/d11/a1 to d3/d11/a1 -removing ../d1/d11/a1 +moving ../d1/d11/a1 to d3/d11/a1 A d2/d3/d11/a1 d1/d11/a1 R d1/d11/a1 1 files updated, 0 files merged, 1 files removed, 0 files unresolved # move directory d1/d11 to an existing directory d2 (removes empty d1) -copying d1/d11/a1 to d2/d11/a1 -removing d1/d11/a1 +moving d1/d11/a1 to d2/d11/a1 A d2/d11/a1 d1/d11/a1 R d1/d11/a1 1 files updated, 0 files merged, 1 files removed, 0 files unresolved # move directories d1 and d2 to a new directory d3 -copying d1/a to d3/d1/a -copying d1/b to d3/d1/b -copying d1/ba to d3/d1/ba -copying d1/d11/a1 to d3/d1/d11/a1 -copying d2/b to d3/d2/b -removing d1/a -removing d1/b -removing d1/ba -removing d1/d11/a1 -removing d2/b +moving d1/a to d3/d1/a +moving d1/b to d3/d1/b +moving d1/ba to d3/d1/ba +moving d1/d11/a1 to d3/d1/d11/a1 +moving d2/b to d3/d2/b A d3/d1/a d1/a A d3/d1/b @@ -121,16 +105,11 @@ R d1/d11/a1 R d2/b 5 files updated, 0 files merged, 5 files removed, 0 files unresolved # move --after directories d1 and d2 to a new directory d3 -copying d1/a to d3/d1/a -copying d1/b to d3/d1/b -copying d1/ba to d3/d1/ba -copying d1/d11/a1 to d3/d1/d11/a1 -copying d2/b to d3/d2/b -removing d1/a -removing d1/b -removing d1/ba -removing d1/d11/a1 -removing d2/b +moving d1/a to d3/d1/a +moving d1/b to d3/d1/b +moving d1/ba to d3/d1/ba +moving d1/d11/a1 to d3/d1/d11/a1 +moving d2/b to d3/d2/b A d3/d1/a d1/a A d3/d1/b @@ -150,8 +129,7 @@ 5 files updated, 0 files merged, 5 files # move everything under directory d1 to existing directory d2, do not # overwrite existing files (d2/b) d2/b: not overwriting - file exists -copying d1/d11/a1 to d2/d11/a1 -removing d1/d11/a1 +moving d1/d11/a1 to d2/d11/a1 A d2/a d1/a A d2/ba @@ -173,14 +151,10 @@ 0 files updated, 0 files merged, 0 files # directory abort: with multiple sources, destination must be an existing directory # move every file under d1 to d2/d21 (glob) -copying d1/a to d2/d21/a -copying d1/b to d2/d21/b -copying d1/ba to d2/d21/ba -copying d1/d11/a1 to d2/d21/a1 -removing d1/a -removing d1/b -removing d1/ba -removing d1/d11/a1 +moving d1/a to d2/d21/a +moving d1/b to d2/d21/b +moving d1/ba to d2/d21/ba +moving d1/d11/a1 to d2/d21/a1 A d2/d21/a d1/a A d2/d21/a1 @@ -195,10 +169,8 @@ R d1/ba R d1/d11/a1 4 files updated, 0 files merged, 4 files removed, 0 files unresolved # move --after some files under d1 to d2/d21 (glob) -copying d1/a to d2/d21/a -copying d1/d11/a1 to d2/d21/a1 -removing d1/a -removing d1/d11/a1 +moving d1/a to d2/d21/a +moving d1/d11/a1 to d2/d21/a1 A d2/d21/a d1/a A d2/d21/a1 @@ -207,10 +179,8 @@ R d1/a R d1/d11/a1 2 files updated, 0 files merged, 2 files removed, 0 files unresolved # move every file under d1 starting with an 'a' to d2/d21 (regexp) -copying d1/a to d2/d21/a -copying d1/d11/a1 to d2/d21/a1 -removing d1/a -removing d1/d11/a1 +moving d1/a to d2/d21/a +moving d1/d11/a1 to d2/d21/a1 A d2/d21/a d1/a A d2/d21/a1 @@ -233,9 +203,8 @@ A d1/ca R d1/ba 1 files updated, 0 files merged, 1 files removed, 0 files unresolved # do not copy more than one source file to the same destination file -copying d1/d11/a1 to d3/d11/a1 +moving d1/d11/a1 to d3/d11/a1 d3/b: not overwriting - d2/b collides with d1/b -removing d1/d11/a1 A d3/a d1/a A d3/b @@ -250,14 +219,10 @@ R d1/ba R d1/d11/a1 4 files updated, 0 files merged, 4 files removed, 0 files unresolved # move a whole subtree with "hg rename ." -copying a to ../d3/d1/a -copying b to ../d3/d1/b -copying ba to ../d3/d1/ba -copying d11/a1 to ../d3/d1/d11/a1 -removing a -removing b -removing ba -removing d11/a1 +moving a to ../d3/d1/a +moving b to ../d3/d1/b +moving ba to ../d3/d1/ba +moving d11/a1 to ../d3/d1/d11/a1 A d3/d1/a d1/a A d3/d1/b @@ -272,14 +237,10 @@ R d1/ba R d1/d11/a1 4 files updated, 0 files merged, 4 files removed, 0 files unresolved # move a whole subtree with "hg rename --after ." -copying a to ../d3/a -copying b to ../d3/b -copying ba to ../d3/ba -copying d11/a1 to ../d3/d11/a1 -removing a -removing b -removing ba -removing d11/a1 +moving a to ../d3/a +moving b to ../d3/b +moving ba to ../d3/ba +moving d11/a1 to ../d3/d11/a1 A d3/a d1/a A d3/b @@ -294,14 +255,10 @@ R d1/ba R d1/d11/a1 4 files updated, 0 files merged, 4 files removed, 0 files unresolved # move the parent tree with "hg rename .." -copying ../a to ../../d3/a -copying ../b to ../../d3/b -copying ../ba to ../../d3/ba -copying a1 to ../../d3/d11/a1 -removing ../a -removing ../b -removing ../ba -removing a1 +moving ../a to ../../d3/a +moving ../b to ../../d3/b +moving ../ba to ../../d3/ba +moving a1 to ../../d3/d11/a1 A d3/a d1/a A d3/b @@ -316,12 +273,9 @@ R d1/ba R d1/d11/a1 4 files updated, 0 files merged, 4 files removed, 0 files unresolved # skip removed files -copying d1/a to d3/a -copying d1/ba to d3/ba -copying d1/d11/a1 to d3/d11/a1 -removing d1/a -removing d1/ba -removing d1/d11/a1 +moving d1/a to d3/a +moving d1/ba to d3/ba +moving d1/d11/a1 to d3/d11/a1 A d3/a d1/a A d3/ba