##// END OF EJS Templates
copy: handle rename internally...
Matt Mackall -
r5610:2493a478 default
parent child Browse files
Show More
@@ -286,13 +286,12 b' def addremove(repo, pats=[], opts={}, dr'
286 if not dry_run:
286 if not dry_run:
287 repo.copy(old, new)
287 repo.copy(old, new)
288
288
289 def copy(ui, repo, pats, opts):
289 def copy(ui, repo, pats, opts, rename=False):
290 # called with the repo lock held
290 # called with the repo lock held
291 #
291 #
292 # hgsep => pathname that uses "/" to separate directories
292 # hgsep => pathname that uses "/" to separate directories
293 # ossep => pathname that uses os.sep to separate directories
293 # ossep => pathname that uses os.sep to separate directories
294 cwd = repo.getcwd()
294 cwd = repo.getcwd()
295 copied = []
296 targets = {}
295 targets = {}
297 after = opts.get("after")
296 after = opts.get("after")
298 dryrun = opts.get("dry_run")
297 dryrun = opts.get("dry_run")
@@ -359,7 +358,8 b' def copy(ui, repo, pats, opts):'
359 return True # report a failure
358 return True # report a failure
360
359
361 if ui.verbose or not exact:
360 if ui.verbose or not exact:
362 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
361 action = rename and "moving" or "copying"
362 ui.status(_('%s %s to %s\n') % (action, relsrc, reltarget))
363
363
364 targets[abstarget] = abssrc
364 targets[abstarget] = abssrc
365
365
@@ -378,7 +378,9 b' def copy(ui, repo, pats, opts):'
378 repo.add([abstarget])
378 repo.add([abstarget])
379 elif not dryrun:
379 elif not dryrun:
380 repo.copy(origsrc, abstarget)
380 repo.copy(origsrc, abstarget)
381 copied.append((abssrc, relsrc, exact))
381
382 if rename and not dryrun:
383 repo.remove([abssrc], True)
382
384
383 # pat: ossep
385 # pat: ossep
384 # dest ossep
386 # dest ossep
@@ -482,7 +484,7 b' def copy(ui, repo, pats, opts):'
482 if errors:
484 if errors:
483 ui.warn(_('(consider using --after)\n'))
485 ui.warn(_('(consider using --after)\n'))
484
486
485 return errors, copied
487 return errors
486
488
487 def service(opts, parentfn=None, initfn=None, runfn=None):
489 def service(opts, parentfn=None, initfn=None, runfn=None):
488 '''Run a command as a service.'''
490 '''Run a command as a service.'''
@@ -454,10 +454,9 b' def copy(ui, repo, *pats, **opts):'
454 """
454 """
455 wlock = repo.wlock(False)
455 wlock = repo.wlock(False)
456 try:
456 try:
457 errs, copied = cmdutil.copy(ui, repo, pats, opts)
457 return cmdutil.copy(ui, repo, pats, opts)
458 finally:
458 finally:
459 del wlock
459 del wlock
460 return errs
461
460
462 def debugancestor(ui, index, rev1, rev2):
461 def debugancestor(ui, index, rev1, rev2):
463 """find the ancestor revision of two revisions in a given index"""
462 """find the ancestor revision of two revisions in a given index"""
@@ -2062,15 +2061,7 b' def rename(ui, repo, *pats, **opts):'
2062 """
2061 """
2063 wlock = repo.wlock(False)
2062 wlock = repo.wlock(False)
2064 try:
2063 try:
2065 errs, copied = cmdutil.copy(ui, repo, pats, opts)
2064 return cmdutil.copy(ui, repo, pats, opts, rename=True)
2066 names = []
2067 for abs, rel, exact in copied:
2068 if ui.verbose or not exact:
2069 ui.status(_('removing %s\n') % rel)
2070 names.append(abs)
2071 if not opts.get('dry_run'):
2072 repo.remove(names, True)
2073 return errs
2074 finally:
2065 finally:
2075 del wlock
2066 del wlock
2076
2067
@@ -1,6 +1,5 b''
1 adding src/a.c
1 adding src/a.c
2 copying src/a.c to source/a.c
2 moving src/a.c to source/a.c
3 removing src/a.c
4 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
3 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
5 ? src/a.o
4 ? src/a.o
6 merging src/a.c and source/a.c
5 merging src/a.c and source/a.c
@@ -1,10 +1,8 b''
1 adding a/a
1 adding a/a
2 adding a/b
2 adding a/b
3 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
3 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
4 copying a/a to b/a
4 moving a/a to b/a
5 copying a/b to b/b
5 moving a/b to b/b
6 removing a/a
7 removing a/b
8 2 files updated, 0 files merged, 2 files removed, 0 files unresolved
6 2 files updated, 0 files merged, 2 files removed, 0 files unresolved
9 resolving manifests
7 resolving manifests
10 overwrite None partial False
8 overwrite None partial False
@@ -1,7 +1,6 b''
1 adding a/f
1 adding a/f
2 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
2 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
3 copying a/f to b/f
3 moving a/f to b/f
4 removing a/f
5 adding a/aa/g
4 adding a/aa/g
6 pulling from ../r2
5 pulling from ../r2
7 searching for changes
6 searching for changes
@@ -29,14 +29,10 b' A d1/d11/e'
29 R d2/b
29 R d2/b
30 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
30 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
31 # rename directory d1 as d3
31 # rename directory d1 as d3
32 copying d1/a to d3/a
32 moving d1/a to d3/a
33 copying d1/b to d3/b
33 moving d1/b to d3/b
34 copying d1/ba to d3/ba
34 moving d1/ba to d3/ba
35 copying d1/d11/a1 to d3/d11/a1
35 moving d1/d11/a1 to d3/d11/a1
36 removing d1/a
37 removing d1/b
38 removing d1/ba
39 removing d1/d11/a1
40 A d3/a
36 A d3/a
41 d1/a
37 d1/a
42 A d3/b
38 A d3/b
@@ -51,14 +47,10 b' R d1/ba'
51 R d1/d11/a1
47 R d1/d11/a1
52 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
48 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
53 # rename --after directory d1 as d3
49 # rename --after directory d1 as d3
54 copying d1/a to d3/a
50 moving d1/a to d3/a
55 copying d1/b to d3/b
51 moving d1/b to d3/b
56 copying d1/ba to d3/ba
52 moving d1/ba to d3/ba
57 copying d1/d11/a1 to d3/d11/a1
53 moving d1/d11/a1 to d3/d11/a1
58 removing d1/a
59 removing d1/b
60 removing d1/ba
61 removing d1/d11/a1
62 A d3/a
54 A d3/a
63 d1/a
55 d1/a
64 A d3/b
56 A d3/b
@@ -73,37 +65,29 b' R d1/ba'
73 R d1/d11/a1
65 R d1/d11/a1
74 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
66 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
75 # move a directory using a relative path
67 # move a directory using a relative path
76 copying ../d1/d11/a1 to d3/d11/a1
68 moving ../d1/d11/a1 to d3/d11/a1
77 removing ../d1/d11/a1
78 A d2/d3/d11/a1
69 A d2/d3/d11/a1
79 d1/d11/a1
70 d1/d11/a1
80 R d1/d11/a1
71 R d1/d11/a1
81 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
72 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
82 # move --after a directory using a relative path
73 # move --after a directory using a relative path
83 copying ../d1/d11/a1 to d3/d11/a1
74 moving ../d1/d11/a1 to d3/d11/a1
84 removing ../d1/d11/a1
85 A d2/d3/d11/a1
75 A d2/d3/d11/a1
86 d1/d11/a1
76 d1/d11/a1
87 R d1/d11/a1
77 R d1/d11/a1
88 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
78 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
89 # move directory d1/d11 to an existing directory d2 (removes empty d1)
79 # move directory d1/d11 to an existing directory d2 (removes empty d1)
90 copying d1/d11/a1 to d2/d11/a1
80 moving d1/d11/a1 to d2/d11/a1
91 removing d1/d11/a1
92 A d2/d11/a1
81 A d2/d11/a1
93 d1/d11/a1
82 d1/d11/a1
94 R d1/d11/a1
83 R d1/d11/a1
95 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
84 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
96 # move directories d1 and d2 to a new directory d3
85 # move directories d1 and d2 to a new directory d3
97 copying d1/a to d3/d1/a
86 moving d1/a to d3/d1/a
98 copying d1/b to d3/d1/b
87 moving d1/b to d3/d1/b
99 copying d1/ba to d3/d1/ba
88 moving d1/ba to d3/d1/ba
100 copying d1/d11/a1 to d3/d1/d11/a1
89 moving d1/d11/a1 to d3/d1/d11/a1
101 copying d2/b to d3/d2/b
90 moving d2/b to d3/d2/b
102 removing d1/a
103 removing d1/b
104 removing d1/ba
105 removing d1/d11/a1
106 removing d2/b
107 A d3/d1/a
91 A d3/d1/a
108 d1/a
92 d1/a
109 A d3/d1/b
93 A d3/d1/b
@@ -121,16 +105,11 b' R d1/d11/a1'
121 R d2/b
105 R d2/b
122 5 files updated, 0 files merged, 5 files removed, 0 files unresolved
106 5 files updated, 0 files merged, 5 files removed, 0 files unresolved
123 # move --after directories d1 and d2 to a new directory d3
107 # move --after directories d1 and d2 to a new directory d3
124 copying d1/a to d3/d1/a
108 moving d1/a to d3/d1/a
125 copying d1/b to d3/d1/b
109 moving d1/b to d3/d1/b
126 copying d1/ba to d3/d1/ba
110 moving d1/ba to d3/d1/ba
127 copying d1/d11/a1 to d3/d1/d11/a1
111 moving d1/d11/a1 to d3/d1/d11/a1
128 copying d2/b to d3/d2/b
112 moving d2/b to d3/d2/b
129 removing d1/a
130 removing d1/b
131 removing d1/ba
132 removing d1/d11/a1
133 removing d2/b
134 A d3/d1/a
113 A d3/d1/a
135 d1/a
114 d1/a
136 A d3/d1/b
115 A d3/d1/b
@@ -150,8 +129,7 b' 5 files updated, 0 files merged, 5 files'
150 # move everything under directory d1 to existing directory d2, do not
129 # move everything under directory d1 to existing directory d2, do not
151 # overwrite existing files (d2/b)
130 # overwrite existing files (d2/b)
152 d2/b: not overwriting - file exists
131 d2/b: not overwriting - file exists
153 copying d1/d11/a1 to d2/d11/a1
132 moving d1/d11/a1 to d2/d11/a1
154 removing d1/d11/a1
155 A d2/a
133 A d2/a
156 d1/a
134 d1/a
157 A d2/ba
135 A d2/ba
@@ -173,14 +151,10 b' 0 files updated, 0 files merged, 0 files'
173 # directory
151 # directory
174 abort: with multiple sources, destination must be an existing directory
152 abort: with multiple sources, destination must be an existing directory
175 # move every file under d1 to d2/d21 (glob)
153 # move every file under d1 to d2/d21 (glob)
176 copying d1/a to d2/d21/a
154 moving d1/a to d2/d21/a
177 copying d1/b to d2/d21/b
155 moving d1/b to d2/d21/b
178 copying d1/ba to d2/d21/ba
156 moving d1/ba to d2/d21/ba
179 copying d1/d11/a1 to d2/d21/a1
157 moving d1/d11/a1 to d2/d21/a1
180 removing d1/a
181 removing d1/b
182 removing d1/ba
183 removing d1/d11/a1
184 A d2/d21/a
158 A d2/d21/a
185 d1/a
159 d1/a
186 A d2/d21/a1
160 A d2/d21/a1
@@ -195,10 +169,8 b' R d1/ba'
195 R d1/d11/a1
169 R d1/d11/a1
196 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
170 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
197 # move --after some files under d1 to d2/d21 (glob)
171 # move --after some files under d1 to d2/d21 (glob)
198 copying d1/a to d2/d21/a
172 moving d1/a to d2/d21/a
199 copying d1/d11/a1 to d2/d21/a1
173 moving d1/d11/a1 to d2/d21/a1
200 removing d1/a
201 removing d1/d11/a1
202 A d2/d21/a
174 A d2/d21/a
203 d1/a
175 d1/a
204 A d2/d21/a1
176 A d2/d21/a1
@@ -207,10 +179,8 b' R d1/a'
207 R d1/d11/a1
179 R d1/d11/a1
208 2 files updated, 0 files merged, 2 files removed, 0 files unresolved
180 2 files updated, 0 files merged, 2 files removed, 0 files unresolved
209 # move every file under d1 starting with an 'a' to d2/d21 (regexp)
181 # move every file under d1 starting with an 'a' to d2/d21 (regexp)
210 copying d1/a to d2/d21/a
182 moving d1/a to d2/d21/a
211 copying d1/d11/a1 to d2/d21/a1
183 moving d1/d11/a1 to d2/d21/a1
212 removing d1/a
213 removing d1/d11/a1
214 A d2/d21/a
184 A d2/d21/a
215 d1/a
185 d1/a
216 A d2/d21/a1
186 A d2/d21/a1
@@ -233,9 +203,8 b' A d1/ca'
233 R d1/ba
203 R d1/ba
234 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
204 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
235 # do not copy more than one source file to the same destination file
205 # do not copy more than one source file to the same destination file
236 copying d1/d11/a1 to d3/d11/a1
206 moving d1/d11/a1 to d3/d11/a1
237 d3/b: not overwriting - d2/b collides with d1/b
207 d3/b: not overwriting - d2/b collides with d1/b
238 removing d1/d11/a1
239 A d3/a
208 A d3/a
240 d1/a
209 d1/a
241 A d3/b
210 A d3/b
@@ -250,14 +219,10 b' R d1/ba'
250 R d1/d11/a1
219 R d1/d11/a1
251 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
220 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
252 # move a whole subtree with "hg rename ."
221 # move a whole subtree with "hg rename ."
253 copying a to ../d3/d1/a
222 moving a to ../d3/d1/a
254 copying b to ../d3/d1/b
223 moving b to ../d3/d1/b
255 copying ba to ../d3/d1/ba
224 moving ba to ../d3/d1/ba
256 copying d11/a1 to ../d3/d1/d11/a1
225 moving d11/a1 to ../d3/d1/d11/a1
257 removing a
258 removing b
259 removing ba
260 removing d11/a1
261 A d3/d1/a
226 A d3/d1/a
262 d1/a
227 d1/a
263 A d3/d1/b
228 A d3/d1/b
@@ -272,14 +237,10 b' R d1/ba'
272 R d1/d11/a1
237 R d1/d11/a1
273 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
238 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
274 # move a whole subtree with "hg rename --after ."
239 # move a whole subtree with "hg rename --after ."
275 copying a to ../d3/a
240 moving a to ../d3/a
276 copying b to ../d3/b
241 moving b to ../d3/b
277 copying ba to ../d3/ba
242 moving ba to ../d3/ba
278 copying d11/a1 to ../d3/d11/a1
243 moving d11/a1 to ../d3/d11/a1
279 removing a
280 removing b
281 removing ba
282 removing d11/a1
283 A d3/a
244 A d3/a
284 d1/a
245 d1/a
285 A d3/b
246 A d3/b
@@ -294,14 +255,10 b' R d1/ba'
294 R d1/d11/a1
255 R d1/d11/a1
295 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
256 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
296 # move the parent tree with "hg rename .."
257 # move the parent tree with "hg rename .."
297 copying ../a to ../../d3/a
258 moving ../a to ../../d3/a
298 copying ../b to ../../d3/b
259 moving ../b to ../../d3/b
299 copying ../ba to ../../d3/ba
260 moving ../ba to ../../d3/ba
300 copying a1 to ../../d3/d11/a1
261 moving a1 to ../../d3/d11/a1
301 removing ../a
302 removing ../b
303 removing ../ba
304 removing a1
305 A d3/a
262 A d3/a
306 d1/a
263 d1/a
307 A d3/b
264 A d3/b
@@ -316,12 +273,9 b' R d1/ba'
316 R d1/d11/a1
273 R d1/d11/a1
317 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
274 4 files updated, 0 files merged, 4 files removed, 0 files unresolved
318 # skip removed files
275 # skip removed files
319 copying d1/a to d3/a
276 moving d1/a to d3/a
320 copying d1/ba to d3/ba
277 moving d1/ba to d3/ba
321 copying d1/d11/a1 to d3/d11/a1
278 moving d1/d11/a1 to d3/d11/a1
322 removing d1/a
323 removing d1/ba
324 removing d1/d11/a1
325 A d3/a
279 A d3/a
326 d1/a
280 d1/a
327 A d3/ba
281 A d3/ba
General Comments 0
You need to be logged in to leave comments. Login now