summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorMickaël Salaün <mic@digikod.net>2012-08-05 13:39:26 +0200
committerMickaël Salaün <mic@digikod.net>2012-08-06 23:51:43 +0200
commitb9477bc2dd8ef1e931f208733976c56a0f2344a3 (patch)
tree02351b9af113f854c9b5e84c5f6567d78c40d06b /project.py
parent5e7127d00baf5bdad3e52cf8784c8aaa736395e1 (diff)
downloadgit-repo-b9477bc2dd8ef1e931f208733976c56a0f2344a3.tar.gz
project.py: Replace the relpath function with os.path.relpath
Change-Id: Ib313340344968211cecfc0a718f6072e41da1a91
Diffstat (limited to 'project.py')
-rw-r--r--project.py19
1 files changed, 2 insertions, 17 deletions
diff --git a/project.py b/project.py
index b7295790..00ebb17f 100644
--- a/project.py
+++ b/project.py
@@ -80,21 +80,6 @@ def _ProjectHooks():
80 _project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d)) 80 _project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d))
81 return _project_hook_list 81 return _project_hook_list
82 82
83def relpath(dst, src):
84 src = os.path.dirname(src)
85 top = os.path.commonprefix([dst, src])
86 if top.endswith('/'):
87 top = top[:-1]
88 else:
89 top = os.path.dirname(top)
90
91 tmp = src
92 rel = ''
93 while top != tmp:
94 rel += '../'
95 tmp = os.path.dirname(tmp)
96 return rel + dst[len(top) + 1:]
97
98 83
99class DownloadedChange(object): 84class DownloadedChange(object):
100 _commit_cache = None 85 _commit_cache = None
@@ -1697,7 +1682,7 @@ class Project(object):
1697 _error("%s: Not replacing %s hook", self.relpath, name) 1682 _error("%s: Not replacing %s hook", self.relpath, name)
1698 continue 1683 continue
1699 try: 1684 try:
1700 os.symlink(relpath(stock_hook, dst), dst) 1685 os.symlink(os.path.relpath(stock_hook, os.path.dirname(dst)), dst)
1701 except OSError, e: 1686 except OSError, e:
1702 if e.errno == errno.EPERM: 1687 if e.errno == errno.EPERM:
1703 raise GitError('filesystem must support symlinks') 1688 raise GitError('filesystem must support symlinks')
@@ -1758,7 +1743,7 @@ class Project(object):
1758 src = os.path.join(self.gitdir, name) 1743 src = os.path.join(self.gitdir, name)
1759 dst = os.path.join(dotgit, name) 1744 dst = os.path.join(dotgit, name)
1760 if os.path.islink(dst) or not os.path.exists(dst): 1745 if os.path.islink(dst) or not os.path.exists(dst):
1761 os.symlink(relpath(src, dst), dst) 1746 os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst)
1762 else: 1747 else:
1763 raise GitError('cannot overwrite a local work tree') 1748 raise GitError('cannot overwrite a local work tree')
1764 except OSError, e: 1749 except OSError, e: