Mercurial > hg
changeset 5610:2493a478f395
copy: handle rename internally
- add rename parameter
- don't collect copied list
- report "moving" rather than "copying"
- remove renamed files
- don't return copied list
- simplify callers
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 07 Dec 2007 02:29:55 -0600 |
parents | a783d3627144 |
children | 652f57de3ccf |
files | mercurial/cmdutil.py mercurial/commands.py tests/test-issue612.out tests/test-rename-dir-merge.out tests/test-rename-dir-merge2.out tests/test-rename.out |
diffstat | 6 files changed, 59 insertions(+), 116 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Fri Dec 07 02:03:42 2007 -0600 +++ b/mercurial/cmdutil.py Fri Dec 07 02:29:55 2007 -0600 @@ -286,13 +286,12 @@ 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 @@ 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 @@ 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 @@ 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.'''
--- a/mercurial/commands.py Fri Dec 07 02:03:42 2007 -0600 +++ b/mercurial/commands.py Fri Dec 07 02:29:55 2007 -0600 @@ -454,10 +454,9 @@ """ 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 @@ """ 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
--- a/tests/test-issue612.out Fri Dec 07 02:03:42 2007 -0600 +++ b/tests/test-issue612.out Fri Dec 07 02:29:55 2007 -0600 @@ -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
--- a/tests/test-rename-dir-merge.out Fri Dec 07 02:03:42 2007 -0600 +++ b/tests/test-rename-dir-merge.out Fri Dec 07 02:29:55 2007 -0600 @@ -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
--- a/tests/test-rename-dir-merge2.out Fri Dec 07 02:03:42 2007 -0600 +++ b/tests/test-rename-dir-merge2.out Fri Dec 07 02:29:55 2007 -0600 @@ -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
--- a/tests/test-rename.out Fri Dec 07 02:03:42 2007 -0600 +++ b/tests/test-rename.out Fri Dec 07 02:29:55 2007 -0600 @@ -29,14 +29,10 @@ 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/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/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 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 @@ # 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 @@ # 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/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/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 @@ 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/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/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/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/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