summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-05-05 00:24:54 -0700
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-06-01 01:24:38 +0000
commit0184dcc510969d6e7cb2525da8e7e2a87ed5f012 (patch)
tree26bfadcbc767c526e1f275cc7f52ac9d1490bf16 /project.py
parent35de228f331101ba17bbc658c3cd910e54725517 (diff)
downloadgit-repo-0184dcc510969d6e7cb2525da8e7e2a87ed5f012.tar.gz
Make linkfile symlinks relative
The source (target) of the symlink is specified relative to a project within a tree, and the destination is specified relative to the top of the tree, so it should always be possible to create a relative symlink to the target file. Relative symlinks will allow moving an entire tree without breaking the symlink, and copying a tree (with -p) without leaving a symlink to the old tree. Change-Id: I16492a8b59a137d2abe43ca78e3b212e2c835599
Diffstat (limited to 'project.py')
-rw-r--r--project.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/project.py b/project.py
index 00e41ada..86e2756d 100644
--- a/project.py
+++ b/project.py
@@ -233,14 +233,14 @@ class _CopyFile(object):
233 _error('Cannot copy file %s to %s', src, dest) 233 _error('Cannot copy file %s to %s', src, dest)
234 234
235class _LinkFile(object): 235class _LinkFile(object):
236 def __init__(self, src, dest, abssrc, absdest): 236 def __init__(self, src, dest, relsrc, absdest):
237 self.src = src 237 self.src = src
238 self.dest = dest 238 self.dest = dest
239 self.abs_src = abssrc 239 self.src_rel_to_dest = relsrc
240 self.abs_dest = absdest 240 self.abs_dest = absdest
241 241
242 def _Link(self): 242 def _Link(self):
243 src = self.abs_src 243 src = self.src_rel_to_dest
244 dest = self.abs_dest 244 dest = self.abs_dest
245 # link file if it does not exist or is out of date 245 # link file if it does not exist or is out of date
246 if not os.path.islink(dest) or os.readlink(dest) != src: 246 if not os.path.islink(dest) or os.readlink(dest) != src:
@@ -1359,9 +1359,10 @@ class Project(object):
1359 1359
1360 def AddLinkFile(self, src, dest, absdest): 1360 def AddLinkFile(self, src, dest, absdest):
1361 # dest should already be an absolute path, but src is project relative 1361 # dest should already be an absolute path, but src is project relative
1362 # make src an absolute path 1362 # make src relative path to dest
1363 abssrc = os.path.join(self.worktree, src) 1363 absdestdir = os.path.dirname(absdest)
1364 self.linkfiles.append(_LinkFile(src, dest, abssrc, absdest)) 1364 relsrc = os.path.relpath(os.path.join(self.worktree, src), absdestdir)
1365 self.linkfiles.append(_LinkFile(src, dest, relsrc, absdest))
1365 1366
1366 def AddAnnotation(self, name, value, keep): 1367 def AddAnnotation(self, name, value, keep):
1367 self.annotations.append(_Annotation(name, value, keep)) 1368 self.annotations.append(_Annotation(name, value, keep))