##// END OF EJS Templates
copy/rename to a removed destination file...
Robin Farine -
r1822:64df4220 default
parent child Browse files
Show More
@@ -825,7 +825,8 b' def commit(ui, repo, *pats, **opts):'
825 except ValueError, inst:
825 except ValueError, inst:
826 raise util.Abort(str(inst))
826 raise util.Abort(str(inst))
827
827
828 def docopy(ui, repo, pats, opts):
828 def docopy(ui, repo, pats, opts, wlock):
829 # called with the repo lock held
829 cwd = repo.getcwd()
830 cwd = repo.getcwd()
830 errors = 0
831 errors = 0
831 copied = []
832 copied = []
@@ -871,8 +872,16 b' def docopy(ui, repo, pats, opts):'
871 if not os.path.isdir(targetdir):
872 if not os.path.isdir(targetdir):
872 os.makedirs(targetdir)
873 os.makedirs(targetdir)
873 try:
874 try:
874 shutil.copyfile(relsrc, reltarget)
875 restore = repo.dirstate.state(abstarget) == 'r'
875 shutil.copymode(relsrc, reltarget)
876 if restore:
877 repo.undelete([abstarget], wlock)
878 try:
879 shutil.copyfile(relsrc, reltarget)
880 shutil.copymode(relsrc, reltarget)
881 restore = False
882 finally:
883 if restore:
884 repo.remove([abstarget], wlock)
876 except shutil.Error, inst:
885 except shutil.Error, inst:
877 raise util.Abort(str(inst))
886 raise util.Abort(str(inst))
878 except IOError, inst:
887 except IOError, inst:
@@ -886,7 +895,8 b' def docopy(ui, repo, pats, opts):'
886 if ui.verbose or not exact:
895 if ui.verbose or not exact:
887 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
896 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
888 targets[abstarget] = abssrc
897 targets[abstarget] = abssrc
889 repo.copy(origsrc, abstarget)
898 if abstarget != origsrc:
899 repo.copy(origsrc, abstarget, wlock)
890 copied.append((abssrc, relsrc, exact))
900 copied.append((abssrc, relsrc, exact))
891
901
892 def targetpathfn(pat, dest, srcs):
902 def targetpathfn(pat, dest, srcs):
@@ -994,7 +1004,12 b' def copy(ui, repo, *pats, **opts):'
994 should properly record copied files, this information is not yet
1004 should properly record copied files, this information is not yet
995 fully used by merge, nor fully reported by log.
1005 fully used by merge, nor fully reported by log.
996 """
1006 """
997 errs, copied = docopy(ui, repo, pats, opts)
1007 try:
1008 wlock = repo.wlock(0)
1009 errs, copied = docopy(ui, repo, pats, opts, wlock)
1010 except lock.LockHeld, inst:
1011 ui.warn(_("repository lock held by %s\n") % inst.args[0])
1012 errs = 1
998 return errs
1013 return errs
999
1014
1000 def debugancestor(ui, index, rev1, rev2):
1015 def debugancestor(ui, index, rev1, rev2):
@@ -1953,13 +1968,18 b' def rename(ui, repo, *pats, **opts):'
1953 should properly record rename files, this information is not yet
1968 should properly record rename files, this information is not yet
1954 fully used by merge, nor fully reported by log.
1969 fully used by merge, nor fully reported by log.
1955 """
1970 """
1956 errs, copied = docopy(ui, repo, pats, opts)
1971 try:
1957 names = []
1972 wlock = repo.wlock(0)
1958 for abs, rel, exact in copied:
1973 errs, copied = docopy(ui, repo, pats, opts, wlock)
1959 if ui.verbose or not exact:
1974 names = []
1960 ui.status(_('removing %s\n') % rel)
1975 for abs, rel, exact in copied:
1961 names.append(abs)
1976 if ui.verbose or not exact:
1962 repo.remove(names, unlink=True)
1977 ui.status(_('removing %s\n') % rel)
1978 names.append(abs)
1979 repo.remove(names, True, wlock)
1980 except lock.LockHeld, inst:
1981 ui.warn(_("repository lock held by %s\n") % inst.args[0])
1982 errs = 1
1963 return errs
1983 return errs
1964
1984
1965 def revert(ui, repo, *pats, **opts):
1985 def revert(ui, repo, *pats, **opts):
@@ -171,3 +171,11 b' mv d1/bb d1/bc'
171 hg rename --after d1/bb d1/bc
171 hg rename --after d1/bb d1/bc
172 hg status
172 hg status
173 hg update -C
173 hg update -C
174
175 echo "# idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)"
176 hg rename d1/b d1/bb
177 echo "some stuff added to d1/bb" >> d1/bb
178 hg rename d1/bb d1/b
179 hg status
180 hg debugstate | grep copy
181 hg update -C
@@ -252,3 +252,5 b' R d1/b'
252 # transitive rename --after
252 # transitive rename --after
253 A d1/bc
253 A d1/bc
254 R d1/b
254 R d1/b
255 # idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)
256 M d1/b
General Comments 0
You need to be logged in to leave comments. Login now