##// END OF EJS Templates
commands.docopy: pay attention on whether paths use "/" or os.sep
Alexis S. L. Carvalho -
r3670:d2d8d239 default
parent child Browse files
Show More
@@ -829,11 +829,17 b' def commit(ui, repo, *pats, **opts):'
829 829
830 830 def docopy(ui, repo, pats, opts, wlock):
831 831 # called with the repo lock held
832 #
833 # hgsep => pathname that uses "/" to separate directories
834 # ossep => pathname that uses os.sep to separate directories
832 835 cwd = repo.getcwd()
833 836 errors = 0
834 837 copied = []
835 838 targets = {}
836 839
840 # abs: hgsep
841 # rel: ossep
842 # return: hgsep
837 843 def okaytocopy(abs, rel, exact):
838 844 reasons = {'?': _('is not managed'),
839 845 'a': _('has been marked for add'),
@@ -850,13 +856,18 b' def docopy(ui, repo, pats, opts, wlock):'
850 856 else:
851 857 return abs
852 858
859 # origsrc: hgsep
860 # abssrc: hgsep
861 # relsrc: ossep
862 # target: ossep
853 863 def copy(origsrc, abssrc, relsrc, target, exact):
854 864 abstarget = util.canonpath(repo.root, cwd, target)
855 865 reltarget = util.pathto(cwd, abstarget)
856 866 prevsrc = targets.get(abstarget)
857 867 if prevsrc is not None:
858 868 ui.warn(_('%s: not overwriting - %s collides with %s\n') %
859 (reltarget, abssrc, prevsrc))
869 (reltarget, util.localpath(abssrc),
870 util.localpath(prevsrc)))
860 871 return
861 872 if (not opts['after'] and os.path.exists(reltarget) or
862 873 opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
@@ -899,26 +910,37 b' def docopy(ui, repo, pats, opts, wlock):'
899 910 repo.copy(origsrc, abstarget, wlock)
900 911 copied.append((abssrc, relsrc, exact))
901 912
913 # pat: ossep
914 # dest ossep
915 # srcs: list of (hgsep, hgsep, ossep, bool)
916 # return: function that takes hgsep and returns ossep
902 917 def targetpathfn(pat, dest, srcs):
903 918 if os.path.isdir(pat):
904 919 abspfx = util.canonpath(repo.root, cwd, pat)
920 abspfx = util.localpath(abspfx)
905 921 if destdirexists:
906 922 striplen = len(os.path.split(abspfx)[0])
907 923 else:
908 924 striplen = len(abspfx)
909 925 if striplen:
910 926 striplen += len(os.sep)
911 res = lambda p: os.path.join(dest, p[striplen:])
927 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:])
912 928 elif destdirexists:
913 res = lambda p: os.path.join(dest, os.path.basename(p))
929 res = lambda p: os.path.join(dest,
930 os.path.basename(util.localpath(p)))
914 931 else:
915 932 res = lambda p: dest
916 933 return res
917 934
935 # pat: ossep
936 # dest ossep
937 # srcs: list of (hgsep, hgsep, ossep, bool)
938 # return: function that takes hgsep and returns ossep
918 939 def targetpathafterfn(pat, dest, srcs):
919 940 if util.patkind(pat, None)[0]:
920 941 # a mercurial pattern
921 res = lambda p: os.path.join(dest, os.path.basename(p))
942 res = lambda p: os.path.join(dest,
943 os.path.basename(util.localpath(p)))
922 944 else:
923 945 abspfx = util.canonpath(repo.root, cwd, pat)
924 946 if len(abspfx) < len(srcs[0][0]):
@@ -927,11 +949,12 b' def docopy(ui, repo, pats, opts, wlock):'
927 949 def evalpath(striplen):
928 950 score = 0
929 951 for s in srcs:
930 t = os.path.join(dest, s[0][striplen:])
952 t = os.path.join(dest, util.localpath(s[0])[striplen:])
931 953 if os.path.exists(t):
932 954 score += 1
933 955 return score
934 956
957 abspfx = util.localpath(abspfx)
935 958 striplen = len(abspfx)
936 959 if striplen:
937 960 striplen += len(os.sep)
@@ -942,11 +965,13 b' def docopy(ui, repo, pats, opts, wlock):'
942 965 striplen1 += len(os.sep)
943 966 if evalpath(striplen1) > score:
944 967 striplen = striplen1
945 res = lambda p: os.path.join(dest, p[striplen:])
968 res = lambda p: os.path.join(dest,
969 util.localpath(p)[striplen:])
946 970 else:
947 971 # a file
948 972 if destdirexists:
949 res = lambda p: os.path.join(dest, os.path.basename(p))
973 res = lambda p: os.path.join(dest,
974 os.path.basename(util.localpath(p)))
950 975 else:
951 976 res = lambda p: dest
952 977 return res
General Comments 0
You need to be logged in to leave comments. Login now