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