##// END OF EJS Templates
copy: refactor okaytocopy into walkpat...
Matt Mackall -
r5605:e7a9ad99 default
parent child Browse files
Show More
@@ -296,29 +296,26 def copy(ui, repo, pats, opts):
296 296 copied = []
297 297 targets = {}
298 298
299 def walkpat(pat):
300 srcs = []
301 for tag, abs, rel, exact in walk(repo, [pat], opts, globbed=True):
302 state = repo.dirstate[abs]
303 if state in '?r':
304 if exact and state == '?':
305 ui.warn(_('%s: not copying - file is not managed\n') % rel)
306 if exact and state == 'r':
307 ui.warn(_('%s: not copying - file has been marked for'
308 ' remove\n') % rel)
309 continue
299 310 # abs: hgsep
300 311 # rel: ossep
301 # return: hgsep
302 def okaytocopy(abs, rel, exact):
303 reasons = {'?': _('is not managed'),
304 'r': _('has been marked for remove')}
305 state = repo.dirstate[abs]
306 reason = reasons.get(state)
307 if reason:
308 if exact:
309 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
310 else:
311 if state == 'a':
312 origsrc = repo.dirstate.copied(abs)
313 if origsrc is not None:
314 return origsrc
315 return abs
312 srcs.append((abs, rel, exact))
313 return srcs
316 314
317 # origsrc: hgsep
318 315 # abssrc: hgsep
319 316 # relsrc: ossep
320 317 # otarget: ossep
321 def copy(origsrc, abssrc, relsrc, otarget, exact):
318 def copyfile(abssrc, relsrc, otarget, exact):
322 319 abstarget = util.canonpath(repo.root, cwd, otarget)
323 320 reltarget = repo.pathto(abstarget, cwd)
324 321 prevsrc = targets.get(abstarget)
@@ -366,6 +363,7 def copy(ui, repo, pats, opts):
366 363 if ui.verbose or not exact:
367 364 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
368 365 targets[abstarget] = abssrc
366 origsrc = repo.dirstate.copied(abssrc) or abssrc
369 367 if abstarget == origsrc: # copying back a copy?
370 368 if repo.dirstate[abstarget] not in 'mn':
371 369 if not opts.get('dry_run'):
@@ -468,12 +466,7 def copy(ui, repo, pats, opts):
468 466 tfn = targetpathfn
469 467 copylist = []
470 468 for pat in pats:
471 srcs = []
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))
469 srcs = walkpat(pat)
477 470 if not srcs:
478 471 continue
479 472 copylist.append((tfn(pat, dest, srcs), srcs))
@@ -481,8 +474,8 def copy(ui, repo, pats, opts):
481 474 raise util.Abort(_('no files to copy'))
482 475
483 476 for targetpath, srcs in copylist:
484 for origsrc, abssrc, relsrc, exact in srcs:
485 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact)
477 for abssrc, relsrc, exact in srcs:
478 copyfile(abssrc, relsrc, targetpath(abssrc), exact)
486 479
487 480 if errors:
488 481 ui.warn(_('(consider using --after)\n'))
General Comments 0
You need to be logged in to leave comments. Login now