Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 1514:faf46d810a85
avoid to copy more than one file to the same destination file
author | Robin Farine <robin.farine@terminus.org> |
---|---|
date | Tue, 08 Nov 2005 10:35:13 -0800 |
parents | 5c3b93b244aa |
children | 0b1b029b4de3 |
comparison
equal
deleted
inserted
replaced
1513:5c3b93b244aa | 1514:faf46d810a85 |
---|---|
788 | 788 |
789 def docopy(ui, repo, pats, opts): | 789 def docopy(ui, repo, pats, opts): |
790 cwd = repo.getcwd() | 790 cwd = repo.getcwd() |
791 errors = 0 | 791 errors = 0 |
792 copied = [] | 792 copied = [] |
793 targets = {} | |
793 | 794 |
794 def okaytocopy(abs, rel, exact): | 795 def okaytocopy(abs, rel, exact): |
795 reasons = {'?': _('is not managed'), | 796 reasons = {'?': _('is not managed'), |
796 'a': _('has been marked for add')} | 797 'a': _('has been marked for add')} |
797 reason = reasons.get(repo.dirstate.state(abs)) | 798 reason = reasons.get(repo.dirstate.state(abs)) |
801 return True | 802 return True |
802 | 803 |
803 def copy(abssrc, relsrc, target, exact): | 804 def copy(abssrc, relsrc, target, exact): |
804 abstarget = util.canonpath(repo.root, cwd, target) | 805 abstarget = util.canonpath(repo.root, cwd, target) |
805 reltarget = util.pathto(cwd, abstarget) | 806 reltarget = util.pathto(cwd, abstarget) |
806 if os.path.exists(reltarget): | 807 prevsrc = targets.get(abstarget) |
808 if prevsrc is not None: | |
809 ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
810 (reltarget, abssrc, prevsrc)) | |
811 return | |
812 elif os.path.exists(reltarget): | |
807 if opts['force']: | 813 if opts['force']: |
808 os.unlink(reltarget) | 814 os.unlink(reltarget) |
809 else: | 815 else: |
810 ui.warn(_('%s: not overwriting - file exists\n') % | 816 ui.warn(_('%s: not overwriting - file exists\n') % |
811 reltarget) | 817 reltarget) |
827 else: | 833 else: |
828 ui.warn(_('%s: cannot copy - %s\n') % | 834 ui.warn(_('%s: cannot copy - %s\n') % |
829 (relsrc, inst.strerror)) | 835 (relsrc, inst.strerror)) |
830 errors += 1 | 836 errors += 1 |
831 return | 837 return |
838 targets[abstarget] = abssrc | |
832 repo.copy(abssrc, abstarget) | 839 repo.copy(abssrc, abstarget) |
833 copied.append((abssrc, relsrc, exact)) | 840 copied.append((abssrc, relsrc, exact)) |
834 | 841 |
835 pats = list(pats) | 842 pats = list(pats) |
836 if not pats: | 843 if not pats: |