util: set_flags shouldn't know about repo flag formats
authorMatt Mackall <mpm@selenic.com>
Sun, 10 Aug 2008 21:55:06 -0500
changeset 6877 1d38f3605b20
parent 6875 0d714a48ab53
child 6878 202d178ec706
util: set_flags shouldn't know about repo flag formats
hgext/convert/subversion.py
mercurial/localrepo.py
mercurial/merge.py
mercurial/patch.py
mercurial/util.py
--- a/hgext/convert/subversion.py	Sun Aug 10 18:01:03 2008 -0500
+++ b/hgext/convert/subversion.py	Sun Aug 10 21:55:06 2008 -0500
@@ -999,7 +999,7 @@
             fp = open(hook, 'w')
             fp.write(pre_revprop_change)
             fp.close()
-            util.set_flags(hook, "x")
+            util.set_flags(hook, False, True)
 
         xport = transport.SvnRaTransport(url=geturl(path))
         self.uuid = svn.ra.get_uuid(xport.ra)
@@ -1026,7 +1026,7 @@
                 # systematically is just as expensive and much simpler.
                 was_exec = 'x' not in flags
 
-            util.set_flags(self.wjoin(filename), flags)
+            util.set_flags(self.wjoin(filename), False, 'x' in flags)
             if was_exec:
                 if 'x' not in flags:
                     self.delexec.append(filename)
--- a/mercurial/localrepo.py	Sun Aug 10 18:01:03 2008 -0500
+++ b/mercurial/localrepo.py	Sun Aug 10 21:55:06 2008 -0500
@@ -562,8 +562,12 @@
             os.unlink(self.wjoin(filename))
         except OSError:
             pass
-        self.wopener(filename, 'w').write(data)
-        util.set_flags(self.wjoin(filename), flags)
+        if 'l' in flags:
+            self.wopener.symlink(data, filename)
+        else:
+            self.wopener(filename, 'w').write(data)
+            if 'x' in flags:
+                util.set_flags(self.wjoin(filename), False, True)
 
     def wwritedata(self, filename, data):
         return self._filter("decode", filename, data)
--- a/mercurial/merge.py	Sun Aug 10 18:01:03 2008 -0500
+++ b/mercurial/merge.py	Sun Aug 10 21:55:06 2008 -0500
@@ -237,7 +237,7 @@
                     updated += 1
                 else:
                     merged += 1
-            util.set_flags(repo.wjoin(fd), flags)
+            util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags)
             if f != fd and move and util.lexists(repo.wjoin(f)):
                 repo.ui.debug(_("removing %s\n") % f)
                 os.unlink(repo.wjoin(f))
@@ -266,7 +266,7 @@
                 repo.ui.warn(" %s\n" % nf)
         elif m == "e": # exec
             flags = a[2]
-            util.set_flags(repo.wjoin(f), flags)
+            util.set_flags(repo.wjoin(f), 'l' in flags, 'x' in flags)
 
     return updated, merged, removed, unresolved
 
--- a/mercurial/patch.py	Sun Aug 10 18:01:03 2008 -0500
+++ b/mercurial/patch.py	Sun Aug 10 21:55:06 2008 -0500
@@ -1109,7 +1109,7 @@
             if ctype == 'ADD' and not os.path.exists(dst):
                 repo.wwrite(gp.path, '', flags)
             else:
-                util.set_flags(dst, flags)
+                util.set_flags(dst, 'l' in flags, 'x' in flags)
     cmdutil.addremove(repo, cfiles)
     files = patches.keys()
     files.extend([r for r in removes if r not in files])
--- a/mercurial/util.py	Sun Aug 10 18:01:03 2008 -0500
+++ b/mercurial/util.py	Sun Aug 10 21:55:06 2008 -0500
@@ -996,7 +996,7 @@
         '''return False if pid dead, True if running or not known'''
         return True
 
-    def set_flags(f, flags):
+    def set_flags(f, l, x):
         pass
 
     def set_binary(fd):
@@ -1143,10 +1143,8 @@
         """check whether a file is executable"""
         return (os.lstat(f).st_mode & 0100 != 0)
 
-    def set_flags(f, flags):
+    def set_flags(f, l, x):
         s = os.lstat(f).st_mode
-        x = "x" in flags
-        l = "l" in flags
         if l:
             if not stat.S_ISLNK(s):
                 # switch file to link