|
@@ -219,13 +219,42 @@ def path_to_tree_path(repopath, path, tree_encoding=DEFAULT_ENCODING):
|
|
|
path: A path, absolute or relative to the cwd
|
|
|
Returns: A path formatted for use in e.g. an index
|
|
|
"""
|
|
|
- path = Path(path).resolve()
|
|
|
- repopath = Path(repopath).resolve()
|
|
|
- relpath = path.relative_to(repopath)
|
|
|
- if sys.platform == 'win32':
|
|
|
- return str(relpath).replace(os.path.sep, '/').encode(tree_encoding)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if sys.version_info < (3, 6):
|
|
|
+ if not isinstance(path, bytes):
|
|
|
+ path = os.fsencode(path)
|
|
|
+ if not isinstance(repopath, bytes):
|
|
|
+ repopath = os.fsencode(repopath)
|
|
|
+ treepath = os.path.relpath(path, repopath)
|
|
|
+ if treepath.startswith(b'..'):
|
|
|
+ err_msg = 'Path %r not in repo path (%r)' % (path, repopath)
|
|
|
+ raise ValueError(err_msg)
|
|
|
+ if os.path.sep != '/':
|
|
|
+ treepath = treepath.replace(os.path.sep.encode('ascii'), b'/')
|
|
|
+ return treepath
|
|
|
else:
|
|
|
- return bytes(relpath)
|
|
|
+
|
|
|
+
|
|
|
+ if sys.platform == 'win32':
|
|
|
+ path = os.path.abspath(path)
|
|
|
+
|
|
|
+ path = Path(path).resolve()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if sys.platform == 'win32':
|
|
|
+ repopath = os.path.abspath(repopath)
|
|
|
+
|
|
|
+ repopath = Path(repopath).resolve()
|
|
|
+
|
|
|
+ relpath = path.relative_to(repopath)
|
|
|
+ if sys.platform == 'win32':
|
|
|
+ return str(relpath).replace(os.path.sep, '/').encode(tree_encoding)
|
|
|
+ else:
|
|
|
+ return bytes(relpath)
|
|
|
|
|
|
|
|
|
class DivergedBranches(Error):
|