Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 1747:91c56c427171
transitive copy/rename
Add support for transitive copy or rename operations, e.g.
hg rename a b
... (possibly edit b)
hg rename b c
hg commit ...
by actually renaming "b" as "c" while recording a copy of
"a" to "c" and a removal of "a".
author | Robin Farine <robin.farine@terminus.org> |
---|---|
date | Sat, 18 Feb 2006 07:37:59 -0800 |
parents | 813f9f5fe837 |
children | d457fec76ab0 f29857aaa053 |
comparison
equal
deleted
inserted
replaced
1746:299c3e26ee45 | 1747:91c56c427171 |
---|---|
816 | 816 |
817 def okaytocopy(abs, rel, exact): | 817 def okaytocopy(abs, rel, exact): |
818 reasons = {'?': _('is not managed'), | 818 reasons = {'?': _('is not managed'), |
819 'a': _('has been marked for add'), | 819 'a': _('has been marked for add'), |
820 'r': _('has been marked for remove')} | 820 'r': _('has been marked for remove')} |
821 reason = reasons.get(repo.dirstate.state(abs)) | 821 state = repo.dirstate.state(abs) |
822 reason = reasons.get(state) | |
822 if reason: | 823 if reason: |
824 if state == 'a': | |
825 origsrc = repo.dirstate.copied(abs) | |
826 if origsrc is not None: | |
827 return origsrc | |
823 if exact: | 828 if exact: |
824 ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | 829 ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
825 else: | 830 else: |
826 return True | 831 return abs |
827 | 832 |
828 def copy(abssrc, relsrc, target, exact): | 833 def copy(origsrc, abssrc, relsrc, target, exact): |
829 abstarget = util.canonpath(repo.root, cwd, target) | 834 abstarget = util.canonpath(repo.root, cwd, target) |
830 reltarget = util.pathto(cwd, abstarget) | 835 reltarget = util.pathto(cwd, abstarget) |
831 prevsrc = targets.get(abstarget) | 836 prevsrc = targets.get(abstarget) |
832 if prevsrc is not None: | 837 if prevsrc is not None: |
833 ui.warn(_('%s: not overwriting - %s collides with %s\n') % | 838 ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
862 errors += 1 | 867 errors += 1 |
863 return | 868 return |
864 if ui.verbose or not exact: | 869 if ui.verbose or not exact: |
865 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | 870 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
866 targets[abstarget] = abssrc | 871 targets[abstarget] = abssrc |
867 repo.copy(abssrc, abstarget) | 872 repo.copy(origsrc, abstarget) |
868 copied.append((abssrc, relsrc, exact)) | 873 copied.append((abssrc, relsrc, exact)) |
869 | 874 |
870 def targetpathfn(pat, dest, srcs): | 875 def targetpathfn(pat, dest, srcs): |
871 if os.path.isdir(pat): | 876 if os.path.isdir(pat): |
872 abspfx = util.canonpath(repo.root, cwd, pat) | 877 abspfx = util.canonpath(repo.root, cwd, pat) |
936 tfn = targetpathfn | 941 tfn = targetpathfn |
937 copylist = [] | 942 copylist = [] |
938 for pat in pats: | 943 for pat in pats: |
939 srcs = [] | 944 srcs = [] |
940 for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | 945 for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
941 if okaytocopy(abssrc, relsrc, exact): | 946 origsrc = okaytocopy(abssrc, relsrc, exact) |
942 srcs.append((abssrc, relsrc, exact)) | 947 if origsrc: |
948 srcs.append((origsrc, abssrc, relsrc, exact)) | |
943 if not srcs: | 949 if not srcs: |
944 continue | 950 continue |
945 copylist.append((tfn(pat, dest, srcs), srcs)) | 951 copylist.append((tfn(pat, dest, srcs), srcs)) |
946 if not copylist: | 952 if not copylist: |
947 raise util.Abort(_('no files to copy')) | 953 raise util.Abort(_('no files to copy')) |
948 | 954 |
949 for targetpath, srcs in copylist: | 955 for targetpath, srcs in copylist: |
950 for abssrc, relsrc, exact in srcs: | 956 for origsrc, abssrc, relsrc, exact in srcs: |
951 copy(abssrc, relsrc, targetpath(abssrc), exact) | 957 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
952 | 958 |
953 if errors: | 959 if errors: |
954 ui.warn(_('(consider using --after)\n')) | 960 ui.warn(_('(consider using --after)\n')) |
955 return errors, copied | 961 return errors, copied |
956 | 962 |