project.py: Replace the relpath function with os.path.relpath
Change-Id: Ib313340344968211cecfc0a718f6072e41da1a91
diff --git a/project.py b/project.py
index b729579..00ebb17 100644
--- a/project.py
+++ b/project.py
@@ -80,21 +80,6 @@
_project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d))
return _project_hook_list
-def relpath(dst, src):
- src = os.path.dirname(src)
- top = os.path.commonprefix([dst, src])
- if top.endswith('/'):
- top = top[:-1]
- else:
- top = os.path.dirname(top)
-
- tmp = src
- rel = ''
- while top != tmp:
- rel += '../'
- tmp = os.path.dirname(tmp)
- return rel + dst[len(top) + 1:]
-
class DownloadedChange(object):
_commit_cache = None
@@ -1697,7 +1682,7 @@
_error("%s: Not replacing %s hook", self.relpath, name)
continue
try:
- os.symlink(relpath(stock_hook, dst), dst)
+ os.symlink(os.path.relpath(stock_hook, os.path.dirname(dst)), dst)
except OSError, e:
if e.errno == errno.EPERM:
raise GitError('filesystem must support symlinks')
@@ -1758,7 +1743,7 @@
src = os.path.join(self.gitdir, name)
dst = os.path.join(dotgit, name)
if os.path.islink(dst) or not os.path.exists(dst):
- os.symlink(relpath(src, dst), dst)
+ os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst)
else:
raise GitError('cannot overwrite a local work tree')
except OSError, e: