symlinks: add _link checking function
authorMatt Mackall <mpm@selenic.com>
Fri, 29 Dec 2006 20:04:31 -0600
changeset 4003 616806f74f0f
parent 4002 d7b9ec589546
child 4004 c83c35f2f4e2
symlinks: add _link checking function
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Fri Dec 29 20:04:31 2006 -0600
+++ b/mercurial/localrepo.py	Fri Dec 29 20:04:31 2006 -0600
@@ -121,6 +121,11 @@
         self.decodepats = None
         self.transhandle = None
 
+        self._link = lambda x: False
+        if util.checklink(self.root):
+            r = self.root # avoid circular reference in lambda
+            self._link = lambda x: util.is_link(os.path.join(r, x))
+
         self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
 
     def url(self):
@@ -486,7 +491,10 @@
                 l.append((mf, cmd))
             self.encodepats = l
 
-        data = self.wopener(filename, 'r').read()
+        if self._link(filename):
+            data = os.readlink(self.wjoin(filename))
+        else:
+            data = self.wopener(filename, 'r').read()
 
         for mf, cmd in self.encodepats:
             if mf(filename):
@@ -719,7 +727,7 @@
             try:
                 new[f] = self.filecommit(f, m1, m2, linkrev, tr, changed)
                 m1.set(f, is_exec(f), is_link(f))
-            except IOError:
+            except OSError:
                 if use_dirstate:
                     self.ui.warn(_("trouble committing %s!\n") % f)
                     raise