mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
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
This commit is contained in:
parent
9c9f979f96
commit
06d5fbf2a5
@ -286,13 +286,12 @@ def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None):
|
|||||||
if not dry_run:
|
if not dry_run:
|
||||||
repo.copy(old, new)
|
repo.copy(old, new)
|
||||||
|
|
||||||
def copy(ui, repo, pats, opts):
|
def copy(ui, repo, pats, opts, rename=False):
|
||||||
# called with the repo lock held
|
# called with the repo lock held
|
||||||
#
|
#
|
||||||
# hgsep => pathname that uses "/" to separate directories
|
# hgsep => pathname that uses "/" to separate directories
|
||||||
# ossep => pathname that uses os.sep to separate directories
|
# ossep => pathname that uses os.sep to separate directories
|
||||||
cwd = repo.getcwd()
|
cwd = repo.getcwd()
|
||||||
copied = []
|
|
||||||
targets = {}
|
targets = {}
|
||||||
after = opts.get("after")
|
after = opts.get("after")
|
||||||
dryrun = opts.get("dry_run")
|
dryrun = opts.get("dry_run")
|
||||||
@ -359,7 +358,8 @@ def copy(ui, repo, pats, opts):
|
|||||||
return True # report a failure
|
return True # report a failure
|
||||||
|
|
||||||
if ui.verbose or not exact:
|
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
|
targets[abstarget] = abssrc
|
||||||
|
|
||||||
@ -378,7 +378,9 @@ def copy(ui, repo, pats, opts):
|
|||||||
repo.add([abstarget])
|
repo.add([abstarget])
|
||||||
elif not dryrun:
|
elif not dryrun:
|
||||||
repo.copy(origsrc, abstarget)
|
repo.copy(origsrc, abstarget)
|
||||||
copied.append((abssrc, relsrc, exact))
|
|
||||||
|
if rename and not dryrun:
|
||||||
|
repo.remove([abssrc], True)
|
||||||
|
|
||||||
# pat: ossep
|
# pat: ossep
|
||||||
# dest ossep
|
# dest ossep
|
||||||
@ -482,7 +484,7 @@ def copy(ui, repo, pats, opts):
|
|||||||
if errors:
|
if errors:
|
||||||
ui.warn(_('(consider using --after)\n'))
|
ui.warn(_('(consider using --after)\n'))
|
||||||
|
|
||||||
return errors, copied
|
return errors
|
||||||
|
|
||||||
def service(opts, parentfn=None, initfn=None, runfn=None):
|
def service(opts, parentfn=None, initfn=None, runfn=None):
|
||||||
'''Run a command as a service.'''
|
'''Run a command as a service.'''
|
||||||
|
@ -454,10 +454,9 @@ def copy(ui, repo, *pats, **opts):
|
|||||||
"""
|
"""
|
||||||
wlock = repo.wlock(False)
|
wlock = repo.wlock(False)
|
||||||
try:
|
try:
|
||||||
errs, copied = cmdutil.copy(ui, repo, pats, opts)
|
return cmdutil.copy(ui, repo, pats, opts)
|
||||||
finally:
|
finally:
|
||||||
del wlock
|
del wlock
|
||||||
return errs
|
|
||||||
|
|
||||||
def debugancestor(ui, index, rev1, rev2):
|
def debugancestor(ui, index, rev1, rev2):
|
||||||
"""find the ancestor revision of two revisions in a given index"""
|
"""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)
|
wlock = repo.wlock(False)
|
||||||
try:
|
try:
|
||||||
errs, copied = cmdutil.copy(ui, repo, pats, opts)
|
return cmdutil.copy(ui, repo, pats, opts, rename=True)
|
||||||
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
|
|
||||||
finally:
|
finally:
|
||||||
del wlock
|
del wlock
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
adding src/a.c
|
adding src/a.c
|
||||||
copying src/a.c to source/a.c
|
moving src/a.c to source/a.c
|
||||||
removing src/a.c
|
|
||||||
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
||||||
? src/a.o
|
? src/a.o
|
||||||
merging src/a.c and source/a.c
|
merging src/a.c and source/a.c
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
adding a/a
|
adding a/a
|
||||||
adding a/b
|
adding a/b
|
||||||
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
||||||
copying a/a to b/a
|
moving a/a to b/a
|
||||||
copying a/b to b/b
|
moving a/b to b/b
|
||||||
removing a/a
|
|
||||||
removing a/b
|
|
||||||
2 files updated, 0 files merged, 2 files removed, 0 files unresolved
|
2 files updated, 0 files merged, 2 files removed, 0 files unresolved
|
||||||
resolving manifests
|
resolving manifests
|
||||||
overwrite None partial False
|
overwrite None partial False
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
adding a/f
|
adding a/f
|
||||||
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
||||||
copying a/f to b/f
|
moving a/f to b/f
|
||||||
removing a/f
|
|
||||||
adding a/aa/g
|
adding a/aa/g
|
||||||
pulling from ../r2
|
pulling from ../r2
|
||||||
searching for changes
|
searching for changes
|
||||||
|
@ -29,14 +29,10 @@ A d1/d11/e
|
|||||||
R d2/b
|
R d2/b
|
||||||
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
||||||
# rename directory d1 as d3
|
# rename directory d1 as d3
|
||||||
copying d1/a to d3/a
|
moving d1/a to d3/a
|
||||||
copying d1/b to d3/b
|
moving d1/b to d3/b
|
||||||
copying d1/ba to d3/ba
|
moving d1/ba to d3/ba
|
||||||
copying d1/d11/a1 to d3/d11/a1
|
moving d1/d11/a1 to d3/d11/a1
|
||||||
removing d1/a
|
|
||||||
removing d1/b
|
|
||||||
removing d1/ba
|
|
||||||
removing d1/d11/a1
|
|
||||||
A d3/a
|
A d3/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/b
|
A d3/b
|
||||||
@ -51,14 +47,10 @@ R d1/ba
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
||||||
# rename --after directory d1 as d3
|
# rename --after directory d1 as d3
|
||||||
copying d1/a to d3/a
|
moving d1/a to d3/a
|
||||||
copying d1/b to d3/b
|
moving d1/b to d3/b
|
||||||
copying d1/ba to d3/ba
|
moving d1/ba to d3/ba
|
||||||
copying d1/d11/a1 to d3/d11/a1
|
moving d1/d11/a1 to d3/d11/a1
|
||||||
removing d1/a
|
|
||||||
removing d1/b
|
|
||||||
removing d1/ba
|
|
||||||
removing d1/d11/a1
|
|
||||||
A d3/a
|
A d3/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/b
|
A d3/b
|
||||||
@ -73,37 +65,29 @@ R d1/ba
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
||||||
# move a directory using a relative path
|
# move a directory using a relative path
|
||||||
copying ../d1/d11/a1 to d3/d11/a1
|
moving ../d1/d11/a1 to d3/d11/a1
|
||||||
removing ../d1/d11/a1
|
|
||||||
A d2/d3/d11/a1
|
A d2/d3/d11/a1
|
||||||
d1/d11/a1
|
d1/d11/a1
|
||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
||||||
# move --after a directory using a relative path
|
# move --after a directory using a relative path
|
||||||
copying ../d1/d11/a1 to d3/d11/a1
|
moving ../d1/d11/a1 to d3/d11/a1
|
||||||
removing ../d1/d11/a1
|
|
||||||
A d2/d3/d11/a1
|
A d2/d3/d11/a1
|
||||||
d1/d11/a1
|
d1/d11/a1
|
||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
||||||
# move directory d1/d11 to an existing directory d2 (removes empty d1)
|
# move directory d1/d11 to an existing directory d2 (removes empty d1)
|
||||||
copying d1/d11/a1 to d2/d11/a1
|
moving d1/d11/a1 to d2/d11/a1
|
||||||
removing d1/d11/a1
|
|
||||||
A d2/d11/a1
|
A d2/d11/a1
|
||||||
d1/d11/a1
|
d1/d11/a1
|
||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
||||||
# move directories d1 and d2 to a new directory d3
|
# move directories d1 and d2 to a new directory d3
|
||||||
copying d1/a to d3/d1/a
|
moving d1/a to d3/d1/a
|
||||||
copying d1/b to d3/d1/b
|
moving d1/b to d3/d1/b
|
||||||
copying d1/ba to d3/d1/ba
|
moving d1/ba to d3/d1/ba
|
||||||
copying d1/d11/a1 to d3/d1/d11/a1
|
moving d1/d11/a1 to d3/d1/d11/a1
|
||||||
copying d2/b to d3/d2/b
|
moving d2/b to d3/d2/b
|
||||||
removing d1/a
|
|
||||||
removing d1/b
|
|
||||||
removing d1/ba
|
|
||||||
removing d1/d11/a1
|
|
||||||
removing d2/b
|
|
||||||
A d3/d1/a
|
A d3/d1/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/d1/b
|
A d3/d1/b
|
||||||
@ -121,16 +105,11 @@ R d1/d11/a1
|
|||||||
R d2/b
|
R d2/b
|
||||||
5 files updated, 0 files merged, 5 files removed, 0 files unresolved
|
5 files updated, 0 files merged, 5 files removed, 0 files unresolved
|
||||||
# move --after directories d1 and d2 to a new directory d3
|
# move --after directories d1 and d2 to a new directory d3
|
||||||
copying d1/a to d3/d1/a
|
moving d1/a to d3/d1/a
|
||||||
copying d1/b to d3/d1/b
|
moving d1/b to d3/d1/b
|
||||||
copying d1/ba to d3/d1/ba
|
moving d1/ba to d3/d1/ba
|
||||||
copying d1/d11/a1 to d3/d1/d11/a1
|
moving d1/d11/a1 to d3/d1/d11/a1
|
||||||
copying d2/b to d3/d2/b
|
moving d2/b to d3/d2/b
|
||||||
removing d1/a
|
|
||||||
removing d1/b
|
|
||||||
removing d1/ba
|
|
||||||
removing d1/d11/a1
|
|
||||||
removing d2/b
|
|
||||||
A d3/d1/a
|
A d3/d1/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/d1/b
|
A d3/d1/b
|
||||||
@ -150,8 +129,7 @@ R d2/b
|
|||||||
# move everything under directory d1 to existing directory d2, do not
|
# move everything under directory d1 to existing directory d2, do not
|
||||||
# overwrite existing files (d2/b)
|
# overwrite existing files (d2/b)
|
||||||
d2/b: not overwriting - file exists
|
d2/b: not overwriting - file exists
|
||||||
copying d1/d11/a1 to d2/d11/a1
|
moving d1/d11/a1 to d2/d11/a1
|
||||||
removing d1/d11/a1
|
|
||||||
A d2/a
|
A d2/a
|
||||||
d1/a
|
d1/a
|
||||||
A d2/ba
|
A d2/ba
|
||||||
@ -173,14 +151,10 @@ abort: destination dx/ is not a directory
|
|||||||
# directory
|
# directory
|
||||||
abort: with multiple sources, destination must be an existing directory
|
abort: with multiple sources, destination must be an existing directory
|
||||||
# move every file under d1 to d2/d21 (glob)
|
# move every file under d1 to d2/d21 (glob)
|
||||||
copying d1/a to d2/d21/a
|
moving d1/a to d2/d21/a
|
||||||
copying d1/b to d2/d21/b
|
moving d1/b to d2/d21/b
|
||||||
copying d1/ba to d2/d21/ba
|
moving d1/ba to d2/d21/ba
|
||||||
copying d1/d11/a1 to d2/d21/a1
|
moving d1/d11/a1 to d2/d21/a1
|
||||||
removing d1/a
|
|
||||||
removing d1/b
|
|
||||||
removing d1/ba
|
|
||||||
removing d1/d11/a1
|
|
||||||
A d2/d21/a
|
A d2/d21/a
|
||||||
d1/a
|
d1/a
|
||||||
A d2/d21/a1
|
A d2/d21/a1
|
||||||
@ -195,10 +169,8 @@ R d1/ba
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
||||||
# move --after some files under d1 to d2/d21 (glob)
|
# move --after some files under d1 to d2/d21 (glob)
|
||||||
copying d1/a to d2/d21/a
|
moving d1/a to d2/d21/a
|
||||||
copying d1/d11/a1 to d2/d21/a1
|
moving d1/d11/a1 to d2/d21/a1
|
||||||
removing d1/a
|
|
||||||
removing d1/d11/a1
|
|
||||||
A d2/d21/a
|
A d2/d21/a
|
||||||
d1/a
|
d1/a
|
||||||
A d2/d21/a1
|
A d2/d21/a1
|
||||||
@ -207,10 +179,8 @@ R d1/a
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
2 files updated, 0 files merged, 2 files removed, 0 files unresolved
|
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)
|
# move every file under d1 starting with an 'a' to d2/d21 (regexp)
|
||||||
copying d1/a to d2/d21/a
|
moving d1/a to d2/d21/a
|
||||||
copying d1/d11/a1 to d2/d21/a1
|
moving d1/d11/a1 to d2/d21/a1
|
||||||
removing d1/a
|
|
||||||
removing d1/d11/a1
|
|
||||||
A d2/d21/a
|
A d2/d21/a
|
||||||
d1/a
|
d1/a
|
||||||
A d2/d21/a1
|
A d2/d21/a1
|
||||||
@ -233,9 +203,8 @@ A d1/ca
|
|||||||
R d1/ba
|
R d1/ba
|
||||||
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
|
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
|
# 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
|
d3/b: not overwriting - d2/b collides with d1/b
|
||||||
removing d1/d11/a1
|
|
||||||
A d3/a
|
A d3/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/b
|
A d3/b
|
||||||
@ -250,14 +219,10 @@ R d1/ba
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
||||||
# move a whole subtree with "hg rename ."
|
# move a whole subtree with "hg rename ."
|
||||||
copying a to ../d3/d1/a
|
moving a to ../d3/d1/a
|
||||||
copying b to ../d3/d1/b
|
moving b to ../d3/d1/b
|
||||||
copying ba to ../d3/d1/ba
|
moving ba to ../d3/d1/ba
|
||||||
copying d11/a1 to ../d3/d1/d11/a1
|
moving d11/a1 to ../d3/d1/d11/a1
|
||||||
removing a
|
|
||||||
removing b
|
|
||||||
removing ba
|
|
||||||
removing d11/a1
|
|
||||||
A d3/d1/a
|
A d3/d1/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/d1/b
|
A d3/d1/b
|
||||||
@ -272,14 +237,10 @@ R d1/ba
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
||||||
# move a whole subtree with "hg rename --after ."
|
# move a whole subtree with "hg rename --after ."
|
||||||
copying a to ../d3/a
|
moving a to ../d3/a
|
||||||
copying b to ../d3/b
|
moving b to ../d3/b
|
||||||
copying ba to ../d3/ba
|
moving ba to ../d3/ba
|
||||||
copying d11/a1 to ../d3/d11/a1
|
moving d11/a1 to ../d3/d11/a1
|
||||||
removing a
|
|
||||||
removing b
|
|
||||||
removing ba
|
|
||||||
removing d11/a1
|
|
||||||
A d3/a
|
A d3/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/b
|
A d3/b
|
||||||
@ -294,14 +255,10 @@ R d1/ba
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
||||||
# move the parent tree with "hg rename .."
|
# move the parent tree with "hg rename .."
|
||||||
copying ../a to ../../d3/a
|
moving ../a to ../../d3/a
|
||||||
copying ../b to ../../d3/b
|
moving ../b to ../../d3/b
|
||||||
copying ../ba to ../../d3/ba
|
moving ../ba to ../../d3/ba
|
||||||
copying a1 to ../../d3/d11/a1
|
moving a1 to ../../d3/d11/a1
|
||||||
removing ../a
|
|
||||||
removing ../b
|
|
||||||
removing ../ba
|
|
||||||
removing a1
|
|
||||||
A d3/a
|
A d3/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/b
|
A d3/b
|
||||||
@ -316,12 +273,9 @@ R d1/ba
|
|||||||
R d1/d11/a1
|
R d1/d11/a1
|
||||||
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
4 files updated, 0 files merged, 4 files removed, 0 files unresolved
|
||||||
# skip removed files
|
# skip removed files
|
||||||
copying d1/a to d3/a
|
moving d1/a to d3/a
|
||||||
copying d1/ba to d3/ba
|
moving d1/ba to d3/ba
|
||||||
copying d1/d11/a1 to d3/d11/a1
|
moving d1/d11/a1 to d3/d11/a1
|
||||||
removing d1/a
|
|
||||||
removing d1/ba
|
|
||||||
removing d1/d11/a1
|
|
||||||
A d3/a
|
A d3/a
|
||||||
d1/a
|
d1/a
|
||||||
A d3/ba
|
A d3/ba
|
||||||
|
Loading…
Reference in New Issue
Block a user