equal
deleted
inserted
replaced
326 if not n1: return localpath(n2) |
326 if not n1: return localpath(n2) |
327 if os.path.isabs(n1): |
327 if os.path.isabs(n1): |
328 if os.path.splitdrive(root)[0] != os.path.splitdrive(n1)[0]: |
328 if os.path.splitdrive(root)[0] != os.path.splitdrive(n1)[0]: |
329 return os.path.join(root, localpath(n2)) |
329 return os.path.join(root, localpath(n2)) |
330 n2 = '/'.join((pconvert(root), n2)) |
330 n2 = '/'.join((pconvert(root), n2)) |
331 a, b = n1.split(os.sep), n2.split('/') |
331 a, b = splitpath(n1), n2.split('/') |
332 a.reverse() |
332 a.reverse() |
333 b.reverse() |
333 b.reverse() |
334 while a and b and a[-1] == b[-1]: |
334 while a and b and a[-1] == b[-1]: |
335 a.pop() |
335 a.pop() |
336 b.pop() |
336 b.pop() |
690 |
690 |
691 def __call__(self, path): |
691 def __call__(self, path): |
692 if path in self.audited: |
692 if path in self.audited: |
693 return |
693 return |
694 normpath = os.path.normcase(path) |
694 normpath = os.path.normcase(path) |
695 parts = normpath.split(os.sep) |
695 parts = splitpath(normpath) |
696 if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') |
696 if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') |
697 or os.pardir in parts): |
697 or os.pardir in parts): |
698 raise Abort(_("path contains illegal component: %s") % path) |
698 raise Abort(_("path contains illegal component: %s") % path) |
699 def check(prefix): |
699 def check(prefix): |
700 curpath = os.path.join(self.root, prefix) |
700 curpath = os.path.join(self.root, prefix) |
884 |
884 |
885 def endswithsep(path): |
885 def endswithsep(path): |
886 '''Check path ends with os.sep or os.altsep.''' |
886 '''Check path ends with os.sep or os.altsep.''' |
887 return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep) |
887 return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep) |
888 |
888 |
|
889 def splitpath(path): |
|
890 '''Split path by os.sep. |
|
891 Note that this function does not use os.altsep because this is |
|
892 an alternative of simple "xxx.split(os.sep)". |
|
893 It is recommended to use os.path.normpath() before using this |
|
894 function if need.''' |
|
895 return path.split(os.sep) |
|
896 |
889 # Platform specific variants |
897 # Platform specific variants |
890 if os.name == 'nt': |
898 if os.name == 'nt': |
891 import msvcrt |
899 import msvcrt |
892 nulldev = 'NUL:' |
900 nulldev = 'NUL:' |
893 |
901 |
981 |
989 |
982 def set_binary(fd): |
990 def set_binary(fd): |
983 msvcrt.setmode(fd.fileno(), os.O_BINARY) |
991 msvcrt.setmode(fd.fileno(), os.O_BINARY) |
984 |
992 |
985 def pconvert(path): |
993 def pconvert(path): |
986 return path.replace("\\", "/") |
994 return '/'.join(splitpath(path)) |
987 |
995 |
988 def localpath(path): |
996 def localpath(path): |
989 return path.replace('/', '\\') |
997 return path.replace('/', '\\') |
990 |
998 |
991 def normpath(path): |
999 def normpath(path): |