464 repo.commit(files, message, opts['user'], opts['date'], match, |
464 repo.commit(files, message, opts['user'], opts['date'], match, |
465 force_editor=opts.get('force_editor')) |
465 force_editor=opts.get('force_editor')) |
466 except ValueError, inst: |
466 except ValueError, inst: |
467 raise util.Abort(str(inst)) |
467 raise util.Abort(str(inst)) |
468 |
468 |
469 def docopy(ui, repo, pats, opts, wlock): |
469 def docopy(ui, repo, pats, opts): |
470 # called with the repo lock held |
470 # called with the repo lock held |
471 # |
471 # |
472 # hgsep => pathname that uses "/" to separate directories |
472 # hgsep => pathname that uses "/" to separate directories |
473 # ossep => pathname that uses os.sep to separate directories |
473 # ossep => pathname that uses os.sep to separate directories |
474 cwd = repo.getcwd() |
474 cwd = repo.getcwd() |
525 if not os.path.isdir(targetdir) and not opts.get('dry_run'): |
525 if not os.path.isdir(targetdir) and not opts.get('dry_run'): |
526 os.makedirs(targetdir) |
526 os.makedirs(targetdir) |
527 try: |
527 try: |
528 restore = repo.dirstate[abstarget] == 'r' |
528 restore = repo.dirstate[abstarget] == 'r' |
529 if restore and not opts.get('dry_run'): |
529 if restore and not opts.get('dry_run'): |
530 repo.undelete([abstarget], wlock) |
530 repo.undelete([abstarget]) |
531 try: |
531 try: |
532 if not opts.get('dry_run'): |
532 if not opts.get('dry_run'): |
533 util.copyfile(src, target) |
533 util.copyfile(src, target) |
534 restore = False |
534 restore = False |
535 finally: |
535 finally: |
536 if restore: |
536 if restore: |
537 repo.remove([abstarget], wlock=wlock) |
537 repo.remove([abstarget]) |
538 except IOError, inst: |
538 except IOError, inst: |
539 if inst.errno == errno.ENOENT: |
539 if inst.errno == errno.ENOENT: |
540 ui.warn(_('%s: deleted in working copy\n') % relsrc) |
540 ui.warn(_('%s: deleted in working copy\n') % relsrc) |
541 else: |
541 else: |
542 ui.warn(_('%s: cannot copy - %s\n') % |
542 ui.warn(_('%s: cannot copy - %s\n') % |
551 if not ui.quiet: |
551 if not ui.quiet: |
552 ui.warn(_("%s has not been committed yet, so no copy " |
552 ui.warn(_("%s has not been committed yet, so no copy " |
553 "data will be stored for %s.\n") |
553 "data will be stored for %s.\n") |
554 % (repo.pathto(origsrc, cwd), reltarget)) |
554 % (repo.pathto(origsrc, cwd), reltarget)) |
555 if abstarget not in repo.dirstate and not opts.get('dry_run'): |
555 if abstarget not in repo.dirstate and not opts.get('dry_run'): |
556 repo.add([abstarget], wlock) |
556 repo.add([abstarget]) |
557 elif not opts.get('dry_run'): |
557 elif not opts.get('dry_run'): |
558 repo.copy(origsrc, abstarget, wlock) |
558 repo.copy(origsrc, abstarget) |
559 copied.append((abssrc, relsrc, exact)) |
559 copied.append((abssrc, relsrc, exact)) |
560 |
560 |
561 # pat: ossep |
561 # pat: ossep |
562 # dest ossep |
562 # dest ossep |
563 # srcs: list of (hgsep, hgsep, ossep, bool) |
563 # srcs: list of (hgsep, hgsep, ossep, bool) |
675 This command takes effect in the next commit. To undo a copy |
675 This command takes effect in the next commit. To undo a copy |
676 before that, see hg revert. |
676 before that, see hg revert. |
677 """ |
677 """ |
678 wlock = repo.wlock(False) |
678 wlock = repo.wlock(False) |
679 try: |
679 try: |
680 errs, copied = docopy(ui, repo, pats, opts, wlock) |
680 errs, copied = docopy(ui, repo, pats, opts) |
681 finally: |
681 finally: |
682 del wlock |
682 del wlock |
683 return errs |
683 return errs |
684 |
684 |
685 def debugancestor(ui, index, rev1, rev2): |
685 def debugancestor(ui, index, rev1, rev2): |
1625 raise util.Abort(_('not a mercurial patch')) |
1625 raise util.Abort(_('not a mercurial patch')) |
1626 p1 = repo.lookup(p1) |
1626 p1 = repo.lookup(p1) |
1627 p2 = repo.lookup(p2 or hex(nullid)) |
1627 p2 = repo.lookup(p2 or hex(nullid)) |
1628 |
1628 |
1629 if p1 != wp[0].node(): |
1629 if p1 != wp[0].node(): |
1630 hg.clean(repo, p1, wlock=wlock) |
1630 hg.clean(repo, p1) |
1631 repo.dirstate.setparents(p1, p2) |
1631 repo.dirstate.setparents(p1, p2) |
1632 elif p2: |
1632 elif p2: |
1633 try: |
1633 try: |
1634 p1 = repo.lookup(p1) |
1634 p1 = repo.lookup(p1) |
1635 p2 = repo.lookup(p2) |
1635 p2 = repo.lookup(p2) |
1643 files = {} |
1643 files = {} |
1644 try: |
1644 try: |
1645 fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root, |
1645 fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root, |
1646 files=files) |
1646 files=files) |
1647 finally: |
1647 finally: |
1648 files = patch.updatedir(ui, repo, files, wlock=wlock) |
1648 files = patch.updatedir(ui, repo, files) |
1649 n = repo.commit(files, message, user, date, wlock=wlock, |
1649 n = repo.commit(files, message, user, date) |
1650 lock=lock) |
|
1651 if opts.get('exact'): |
1650 if opts.get('exact'): |
1652 if hex(n) != nodeid: |
1651 if hex(n) != nodeid: |
1653 repo.rollback(wlock=wlock, lock=lock) |
1652 repo.rollback() |
1654 raise util.Abort(_('patch is damaged' + |
1653 raise util.Abort(_('patch is damaged' + |
1655 ' or loses information')) |
1654 ' or loses information')) |
1656 finally: |
1655 finally: |
1657 os.unlink(tmpname) |
1656 os.unlink(tmpname) |
1658 finally: |
1657 finally: |
2259 This command takes effect in the next commit. To undo a rename |
2258 This command takes effect in the next commit. To undo a rename |
2260 before that, see hg revert. |
2259 before that, see hg revert. |
2261 """ |
2260 """ |
2262 wlock = repo.wlock(False) |
2261 wlock = repo.wlock(False) |
2263 try: |
2262 try: |
2264 errs, copied = docopy(ui, repo, pats, opts, wlock) |
2263 errs, copied = docopy(ui, repo, pats, opts) |
2265 names = [] |
2264 names = [] |
2266 for abs, rel, exact in copied: |
2265 for abs, rel, exact in copied: |
2267 if ui.verbose or not exact: |
2266 if ui.verbose or not exact: |
2268 ui.status(_('removing %s\n') % rel) |
2267 ui.status(_('removing %s\n') % rel) |
2269 names.append(abs) |
2268 names.append(abs) |
2270 if not opts.get('dry_run'): |
2269 if not opts.get('dry_run'): |
2271 repo.remove(names, True, wlock=wlock) |
2270 repo.remove(names, True) |
2272 return errs |
2271 return errs |
2273 finally: |
2272 finally: |
2274 del wlock |
2273 del wlock |
2275 |
2274 |
2276 def revert(ui, repo, *pats, **opts): |
2275 def revert(ui, repo, *pats, **opts): |
2357 if abs in names or src == 'b': |
2356 if abs in names or src == 'b': |
2358 continue |
2357 continue |
2359 names[abs] = (rel, exact) |
2358 names[abs] = (rel, exact) |
2360 target_only[abs] = True |
2359 target_only[abs] = True |
2361 |
2360 |
2362 changes = repo.status(match=names.has_key, wlock=wlock)[:5] |
2361 changes = repo.status(match=names.has_key)[:5] |
2363 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
2362 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
2364 |
2363 |
2365 revert = ([], _('reverting %s\n')) |
2364 revert = ([], _('reverting %s\n')) |
2366 add = ([], _('adding %s\n')) |
2365 add = ([], _('adding %s\n')) |
2367 remove = ([], _('removing %s\n')) |
2366 remove = ([], _('removing %s\n')) |
2430 handle(remove, False) |
2429 handle(remove, False) |
2431 |
2430 |
2432 if not opts.get('dry_run'): |
2431 if not opts.get('dry_run'): |
2433 for f in forget[0]: |
2432 for f in forget[0]: |
2434 repo.dirstate.forget(f) |
2433 repo.dirstate.forget(f) |
2435 r = hg.revert(repo, node, update.has_key, wlock) |
2434 r = hg.revert(repo, node, update.has_key) |
2436 for f in add[0]: |
2435 for f in add[0]: |
2437 repo.dirstate.add(f) |
2436 repo.dirstate.add(f) |
2438 for f in undelete[0]: |
2437 for f in undelete[0]: |
2439 repo.dirstate.normal(f) |
2438 repo.dirstate.normal(f) |
2440 for f in remove[0]: |
2439 for f in remove[0]: |