Mercurial > hg
changeset 11769:ca6cebd8734e stable
dirstate: ignore symlinks when fs cannot handle them (issue1888)
When the filesystem cannot handle the executable bit, we currently
ignore it completely when looking for modified files. Similarly, it is
impossible to set or clear the bit when the filesystem ignores it.
This patch makes Mercurial treat symbolic links the same way.
Symlinks are a little different since they manifest themselves as
small files containing a filename (the symlink target). On Windows,
these files show up as regular files, and on Linux and Mac they show
up as real symlinks.
Issue1888 presents a case where the symlink files are better ignored
from the Windows side. A Linux client creates symlinks in a working
copy which is shared over a network between Linux and Windows clients.
The Samba server is helpful and defererences the symlink when the
Windows client looks at it. This means that Mercurial on the Windows
side sees file content instead of a file name in the symlink, and
hence flags the link as modified. Ignoring the change would be much
more helpful, similarly to how Mercurial does not report any changes
when executable bits are ignored in a checkout on Windows.
An initial checkout of a symbolic link on a file system that cannot
handle symbolic links will still result in a regular file containing
the target file name as its content. Sharing such a checkout with a
Linux client will not turn the file into a symlink automatically, but
'hg revert' can fix that. After the revert, the Windows client will
see the correct file content (provided by the Samba server when it
follows the link on the Linux side) and otherwise ignore the change.
Running 'hg perfstatus' 10 times gives these results:
Before: After:
min: 0.544703 min: 0.546549
med: 0.547592 med: 0.548881
avg: 0.549146 avg: 0.548549
max: 0.564112 max: 0.551504
The median time is increased about 0.24%.
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Mon, 09 Aug 2010 15:31:56 +0200 |
parents | aff419e260f9 |
children | 4b8dc59e22b9 423ece53380e |
files | mercurial/dirstate.py tests/test-symlink-os-yes-fs-no.py tests/test-symlink-os-yes-fs-no.py.out |
diffstat | 3 files changed, 44 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Sat Aug 07 16:27:16 2010 +0900 +++ b/mercurial/dirstate.py Mon Aug 09 15:31:56 2010 +0200 @@ -625,6 +625,8 @@ dadd = deleted.append cadd = clean.append + lnkkind = stat.S_IFLNK + for fn, st in self.walk(match, subrepos, listunknown, listignored).iteritems(): if fn not in dmap: @@ -640,13 +642,19 @@ if not st and state in "nma": dadd(fn) elif state == 'n': + # The "mode & lnkkind != lnkkind or self._checklink" + # lines are an expansion of "islink => checklink" + # where islink means "is this a link?" and checklink + # means "can we check links?". if (size >= 0 and (size != st.st_size or ((mode ^ st.st_mode) & 0100 and self._checkexec)) + and (mode & lnkkind != lnkkind or self._checklink) or size == -2 # other parent or fn in self._copymap): madd(fn) - elif time != int(st.st_mtime): + elif (time != int(st.st_mtime) + and (mode & lnkkind != lnkkind or self._checklink)): ladd(fn) elif listclean: cadd(fn)
--- a/tests/test-symlink-os-yes-fs-no.py Sat Aug 07 16:27:16 2010 +0900 +++ b/tests/test-symlink-os-yes-fs-no.py Mon Aug 09 15:31:56 2010 +0200 @@ -1,5 +1,5 @@ -import os, sys -from mercurial import hg, ui +import os, sys, time +from mercurial import hg, ui, commands TESTDIR = os.environ["TESTDIR"] @@ -7,11 +7,35 @@ if not hasattr(os, "symlink"): sys.exit(80) # SKIPPED_STATUS defined in run-tests.py -# this is what symlink would do on a non-symlink file system +# clone with symlink support +u = ui.ui() +hg.clone(u, os.path.join(TESTDIR, 'test-no-symlinks.hg'), 'test0') + +repo = hg.repository(u, 'test0') + +# wait a bit, or the status call wont update the dirstate +time.sleep(1) +commands.status(u, repo) + +# now disable symlink support -- this is what os.symlink would do on a +# non-symlink file system def symlink_failure(src, dst): raise OSError, (1, "Operation not permitted") os.symlink = symlink_failure -# now try cloning a repo which contains symlinks +# dereference links as if a Samba server has exported this to a +# Windows client +for f in 'test0/a.lnk', 'test0/d/b.lnk': + os.unlink(f) + fp = open(f, 'wb') + fp.write(open(f[:-4]).read()) + fp.close() + +# reload repository +u = ui.ui() +repo = hg.repository(u, 'test0') +commands.status(u, repo) + +# try cloning a repo which contains symlinks u = ui.ui() hg.clone(u, os.path.join(TESTDIR, 'test-no-symlinks.hg'), 'test1')
--- a/tests/test-symlink-os-yes-fs-no.py.out Sat Aug 07 16:27:16 2010 +0900 +++ b/tests/test-symlink-os-yes-fs-no.py.out Mon Aug 09 15:31:56 2010 +0200 @@ -5,3 +5,10 @@ added 1 changesets with 4 changes to 4 files updating to branch default 4 files updated, 0 files merged, 0 files removed, 0 files unresolved +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 4 changes to 4 files +updating to branch default +4 files updated, 0 files merged, 0 files removed, 0 files unresolved