mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-01-02 16:14:25 +00:00
project.py: Replace the relpath function with os.path.relpath
Change-Id: Ib313340344968211cecfc0a718f6072e41da1a91
This commit is contained in:
parent
5e7127d00b
commit
b9477bc2dd
19
project.py
19
project.py
@ -80,21 +80,6 @@ def _ProjectHooks():
|
|||||||
_project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d))
|
_project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d))
|
||||||
return _project_hook_list
|
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):
|
class DownloadedChange(object):
|
||||||
_commit_cache = None
|
_commit_cache = None
|
||||||
@ -1697,7 +1682,7 @@ class Project(object):
|
|||||||
_error("%s: Not replacing %s hook", self.relpath, name)
|
_error("%s: Not replacing %s hook", self.relpath, name)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
os.symlink(relpath(stock_hook, dst), dst)
|
os.symlink(os.path.relpath(stock_hook, os.path.dirname(dst)), dst)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno == errno.EPERM:
|
if e.errno == errno.EPERM:
|
||||||
raise GitError('filesystem must support symlinks')
|
raise GitError('filesystem must support symlinks')
|
||||||
@ -1758,7 +1743,7 @@ class Project(object):
|
|||||||
src = os.path.join(self.gitdir, name)
|
src = os.path.join(self.gitdir, name)
|
||||||
dst = os.path.join(dotgit, name)
|
dst = os.path.join(dotgit, name)
|
||||||
if os.path.islink(dst) or not os.path.exists(dst):
|
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:
|
else:
|
||||||
raise GitError('cannot overwrite a local work tree')
|
raise GitError('cannot overwrite a local work tree')
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
|
Loading…
Reference in New Issue
Block a user