Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 3672:e8730b5b8a32
Merge with crew.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Thu, 16 Nov 2006 08:52:55 +0100 |
parents | 86d3f966201d d2d8d23944a9 |
children | eb0b4a2d70a9 |
comparison
equal
deleted
inserted
replaced
3671:86d3f966201d | 3672:e8730b5b8a32 |
---|---|
435 except ValueError, inst: | 435 except ValueError, inst: |
436 raise util.Abort(str(inst)) | 436 raise util.Abort(str(inst)) |
437 | 437 |
438 def docopy(ui, repo, pats, opts, wlock): | 438 def docopy(ui, repo, pats, opts, wlock): |
439 # called with the repo lock held | 439 # called with the repo lock held |
440 # | |
441 # hgsep => pathname that uses "/" to separate directories | |
442 # ossep => pathname that uses os.sep to separate directories | |
440 cwd = repo.getcwd() | 443 cwd = repo.getcwd() |
441 errors = 0 | 444 errors = 0 |
442 copied = [] | 445 copied = [] |
443 targets = {} | 446 targets = {} |
444 | 447 |
448 # abs: hgsep | |
449 # rel: ossep | |
450 # return: hgsep | |
445 def okaytocopy(abs, rel, exact): | 451 def okaytocopy(abs, rel, exact): |
446 reasons = {'?': _('is not managed'), | 452 reasons = {'?': _('is not managed'), |
447 'a': _('has been marked for add'), | 453 'a': _('has been marked for add'), |
448 'r': _('has been marked for remove')} | 454 'r': _('has been marked for remove')} |
449 state = repo.dirstate.state(abs) | 455 state = repo.dirstate.state(abs) |
456 if exact: | 462 if exact: |
457 ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | 463 ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
458 else: | 464 else: |
459 return abs | 465 return abs |
460 | 466 |
467 # origsrc: hgsep | |
468 # abssrc: hgsep | |
469 # relsrc: ossep | |
470 # target: ossep | |
461 def copy(origsrc, abssrc, relsrc, target, exact): | 471 def copy(origsrc, abssrc, relsrc, target, exact): |
462 abstarget = util.canonpath(repo.root, cwd, target) | 472 abstarget = util.canonpath(repo.root, cwd, target) |
463 reltarget = util.pathto(cwd, abstarget) | 473 reltarget = util.pathto(cwd, abstarget) |
464 prevsrc = targets.get(abstarget) | 474 prevsrc = targets.get(abstarget) |
465 if prevsrc is not None: | 475 if prevsrc is not None: |
466 ui.warn(_('%s: not overwriting - %s collides with %s\n') % | 476 ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
467 (reltarget, abssrc, prevsrc)) | 477 (reltarget, util.localpath(abssrc), |
478 util.localpath(prevsrc))) | |
468 return | 479 return |
469 if (not opts['after'] and os.path.exists(reltarget) or | 480 if (not opts['after'] and os.path.exists(reltarget) or |
470 opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | 481 opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
471 if not opts['force']: | 482 if not opts['force']: |
472 ui.warn(_('%s: not overwriting - file exists\n') % | 483 ui.warn(_('%s: not overwriting - file exists\n') % |
505 targets[abstarget] = abssrc | 516 targets[abstarget] = abssrc |
506 if abstarget != origsrc and not opts.get('dry_run'): | 517 if abstarget != origsrc and not opts.get('dry_run'): |
507 repo.copy(origsrc, abstarget, wlock) | 518 repo.copy(origsrc, abstarget, wlock) |
508 copied.append((abssrc, relsrc, exact)) | 519 copied.append((abssrc, relsrc, exact)) |
509 | 520 |
521 # pat: ossep | |
522 # dest ossep | |
523 # srcs: list of (hgsep, hgsep, ossep, bool) | |
524 # return: function that takes hgsep and returns ossep | |
510 def targetpathfn(pat, dest, srcs): | 525 def targetpathfn(pat, dest, srcs): |
511 if os.path.isdir(pat): | 526 if os.path.isdir(pat): |
512 abspfx = util.canonpath(repo.root, cwd, pat) | 527 abspfx = util.canonpath(repo.root, cwd, pat) |
528 abspfx = util.localpath(abspfx) | |
513 if destdirexists: | 529 if destdirexists: |
514 striplen = len(os.path.split(abspfx)[0]) | 530 striplen = len(os.path.split(abspfx)[0]) |
515 else: | 531 else: |
516 striplen = len(abspfx) | 532 striplen = len(abspfx) |
517 if striplen: | 533 if striplen: |
518 striplen += len(os.sep) | 534 striplen += len(os.sep) |
519 res = lambda p: os.path.join(dest, p[striplen:]) | 535 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
520 elif destdirexists: | 536 elif destdirexists: |
521 res = lambda p: os.path.join(dest, os.path.basename(p)) | 537 res = lambda p: os.path.join(dest, |
538 os.path.basename(util.localpath(p))) | |
522 else: | 539 else: |
523 res = lambda p: dest | 540 res = lambda p: dest |
524 return res | 541 return res |
525 | 542 |
543 # pat: ossep | |
544 # dest ossep | |
545 # srcs: list of (hgsep, hgsep, ossep, bool) | |
546 # return: function that takes hgsep and returns ossep | |
526 def targetpathafterfn(pat, dest, srcs): | 547 def targetpathafterfn(pat, dest, srcs): |
527 if util.patkind(pat, None)[0]: | 548 if util.patkind(pat, None)[0]: |
528 # a mercurial pattern | 549 # a mercurial pattern |
529 res = lambda p: os.path.join(dest, os.path.basename(p)) | 550 res = lambda p: os.path.join(dest, |
551 os.path.basename(util.localpath(p))) | |
530 else: | 552 else: |
531 abspfx = util.canonpath(repo.root, cwd, pat) | 553 abspfx = util.canonpath(repo.root, cwd, pat) |
532 if len(abspfx) < len(srcs[0][0]): | 554 if len(abspfx) < len(srcs[0][0]): |
533 # A directory. Either the target path contains the last | 555 # A directory. Either the target path contains the last |
534 # component of the source path or it does not. | 556 # component of the source path or it does not. |
535 def evalpath(striplen): | 557 def evalpath(striplen): |
536 score = 0 | 558 score = 0 |
537 for s in srcs: | 559 for s in srcs: |
538 t = os.path.join(dest, s[0][striplen:]) | 560 t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
539 if os.path.exists(t): | 561 if os.path.exists(t): |
540 score += 1 | 562 score += 1 |
541 return score | 563 return score |
542 | 564 |
565 abspfx = util.localpath(abspfx) | |
543 striplen = len(abspfx) | 566 striplen = len(abspfx) |
544 if striplen: | 567 if striplen: |
545 striplen += len(os.sep) | 568 striplen += len(os.sep) |
546 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | 569 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
547 score = evalpath(striplen) | 570 score = evalpath(striplen) |
548 striplen1 = len(os.path.split(abspfx)[0]) | 571 striplen1 = len(os.path.split(abspfx)[0]) |
549 if striplen1: | 572 if striplen1: |
550 striplen1 += len(os.sep) | 573 striplen1 += len(os.sep) |
551 if evalpath(striplen1) > score: | 574 if evalpath(striplen1) > score: |
552 striplen = striplen1 | 575 striplen = striplen1 |
553 res = lambda p: os.path.join(dest, p[striplen:]) | 576 res = lambda p: os.path.join(dest, |
577 util.localpath(p)[striplen:]) | |
554 else: | 578 else: |
555 # a file | 579 # a file |
556 if destdirexists: | 580 if destdirexists: |
557 res = lambda p: os.path.join(dest, os.path.basename(p)) | 581 res = lambda p: os.path.join(dest, |
582 os.path.basename(util.localpath(p))) | |
558 else: | 583 else: |
559 res = lambda p: dest | 584 res = lambda p: dest |
560 return res | 585 return res |
561 | 586 |
562 | 587 |