294 cwd = repo.getcwd() |
294 cwd = repo.getcwd() |
295 errors = 0 |
295 errors = 0 |
296 copied = [] |
296 copied = [] |
297 targets = {} |
297 targets = {} |
298 |
298 |
299 # abs: hgsep |
299 def walkpat(pat): |
300 # rel: ossep |
300 srcs = [] |
301 # return: hgsep |
301 for tag, abs, rel, exact in walk(repo, [pat], opts, globbed=True): |
302 def okaytocopy(abs, rel, exact): |
302 state = repo.dirstate[abs] |
303 reasons = {'?': _('is not managed'), |
303 if state in '?r': |
304 'r': _('has been marked for remove')} |
304 if exact and state == '?': |
305 state = repo.dirstate[abs] |
305 ui.warn(_('%s: not copying - file is not managed\n') % rel) |
306 reason = reasons.get(state) |
306 if exact and state == 'r': |
307 if reason: |
307 ui.warn(_('%s: not copying - file has been marked for' |
308 if exact: |
308 ' remove\n') % rel) |
309 ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
309 continue |
310 else: |
310 # abs: hgsep |
311 if state == 'a': |
311 # rel: ossep |
312 origsrc = repo.dirstate.copied(abs) |
312 srcs.append((abs, rel, exact)) |
313 if origsrc is not None: |
313 return srcs |
314 return origsrc |
314 |
315 return abs |
|
316 |
|
317 # origsrc: hgsep |
|
318 # abssrc: hgsep |
315 # abssrc: hgsep |
319 # relsrc: ossep |
316 # relsrc: ossep |
320 # otarget: ossep |
317 # otarget: ossep |
321 def copy(origsrc, abssrc, relsrc, otarget, exact): |
318 def copyfile(abssrc, relsrc, otarget, exact): |
322 abstarget = util.canonpath(repo.root, cwd, otarget) |
319 abstarget = util.canonpath(repo.root, cwd, otarget) |
323 reltarget = repo.pathto(abstarget, cwd) |
320 reltarget = repo.pathto(abstarget, cwd) |
324 prevsrc = targets.get(abstarget) |
321 prevsrc = targets.get(abstarget) |
325 src = repo.wjoin(abssrc) |
322 src = repo.wjoin(abssrc) |
326 target = repo.wjoin(abstarget) |
323 target = repo.wjoin(abstarget) |
364 errors += 1 |
361 errors += 1 |
365 return |
362 return |
366 if ui.verbose or not exact: |
363 if ui.verbose or not exact: |
367 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
364 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
368 targets[abstarget] = abssrc |
365 targets[abstarget] = abssrc |
|
366 origsrc = repo.dirstate.copied(abssrc) or abssrc |
369 if abstarget == origsrc: # copying back a copy? |
367 if abstarget == origsrc: # copying back a copy? |
370 if repo.dirstate[abstarget] not in 'mn': |
368 if repo.dirstate[abstarget] not in 'mn': |
371 if not opts.get('dry_run'): |
369 if not opts.get('dry_run'): |
372 repo.add([abstarget]) |
370 repo.add([abstarget]) |
373 else: |
371 else: |
466 tfn = targetpathafterfn |
464 tfn = targetpathafterfn |
467 else: |
465 else: |
468 tfn = targetpathfn |
466 tfn = targetpathfn |
469 copylist = [] |
467 copylist = [] |
470 for pat in pats: |
468 for pat in pats: |
471 srcs = [] |
469 srcs = walkpat(pat) |
472 for tag, abssrc, relsrc, exact in walk(repo, [pat], opts, |
|
473 globbed=True): |
|
474 origsrc = okaytocopy(abssrc, relsrc, exact) |
|
475 if origsrc: |
|
476 srcs.append((origsrc, abssrc, relsrc, exact)) |
|
477 if not srcs: |
470 if not srcs: |
478 continue |
471 continue |
479 copylist.append((tfn(pat, dest, srcs), srcs)) |
472 copylist.append((tfn(pat, dest, srcs), srcs)) |
480 if not copylist: |
473 if not copylist: |
481 raise util.Abort(_('no files to copy')) |
474 raise util.Abort(_('no files to copy')) |
482 |
475 |
483 for targetpath, srcs in copylist: |
476 for targetpath, srcs in copylist: |
484 for origsrc, abssrc, relsrc, exact in srcs: |
477 for abssrc, relsrc, exact in srcs: |
485 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
478 copyfile(abssrc, relsrc, targetpath(abssrc), exact) |
486 |
479 |
487 if errors: |
480 if errors: |
488 ui.warn(_('(consider using --after)\n')) |
481 ui.warn(_('(consider using --after)\n')) |
489 return errors, copied |
482 return errors, copied |
490 |
483 |