1
mirror of https://gerrit.googlesource.com/git-repo synced 2025-01-04 16:14:25 +00:00

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
This commit is contained in:
Colin Cross 2015-05-05 00:24:54 -07:00 committed by David Pursehouse
parent 35de228f33
commit 0184dcc510

View File

@ -233,14 +233,14 @@ class _CopyFile(object):
_error('Cannot copy file %s to %s', src, dest)
class _LinkFile(object):
def __init__(self, src, dest, abssrc, absdest):
def __init__(self, src, dest, relsrc, absdest):
self.src = src
self.dest = dest
self.abs_src = abssrc
self.src_rel_to_dest = relsrc
self.abs_dest = absdest
def _Link(self):
src = self.abs_src
src = self.src_rel_to_dest
dest = self.abs_dest
# link file if it does not exist or is out of date
if not os.path.islink(dest) or os.readlink(dest) != src:
@ -1359,9 +1359,10 @@ class Project(object):
def AddLinkFile(self, src, dest, absdest):
# dest should already be an absolute path, but src is project relative
# make src an absolute path
abssrc = os.path.join(self.worktree, src)
self.linkfiles.append(_LinkFile(src, dest, abssrc, absdest))
# make src relative path to dest
absdestdir = os.path.dirname(absdest)
relsrc = os.path.relpath(os.path.join(self.worktree, src), absdestdir)
self.linkfiles.append(_LinkFile(src, dest, relsrc, absdest))
def AddAnnotation(self, name, value, keep):
self.annotations.append(_Annotation(name, value, keep))