[PATCH 1 of 2] opener: add new resetflags param to __call__

Adrian Buehlmann adrian at cadifra.com
Sun Dec 5 12:49:17 CST 2010


On 2010-12-04 23:45, Matt Mackall wrote:
> On Sat, 2010-12-04 at 13:39 +0100, Adrian Buehlmann wrote:
>>              try:
>>                  if 'w' in mode:
>> -                    st_mode = os.lstat(f).st_mode & 0777
>> +                    if not resetflags:
>> +                        st_mode = os.lstat(f).st_mode & 0777
> 
> When do we not want to reset the mode on write?
> 

Probably not an exhaustive answer to this good question, but

   test-record.t

fails if I hack util.py to unconditionally reset the flags.


As an experiment, I found that with the following patch (alone), the
testsuite passes:


diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -433,7 +433,7 @@ class patchfile(object):
         if islink:
             fp = cStringIO.StringIO()
         else:
-            fp = self.opener(fname, 'w')
+            fp = self.opener(fname, 'w', preserveflags=True)
         try:
             if self.eolmode == 'auto':
                 eol = self.eol
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -871,7 +871,8 @@ class opener(object):
             return
         os.chmod(name, self.createmode & 0666)

-    def __call__(self, path, mode="r", text=False, atomictemp=False):
+    def __call__(self, path, mode="r", text=False, atomictemp=False,
+                 preserveflags=False):
         self.auditor(path)
         f = os.path.join(self.base, path)

@@ -890,7 +891,8 @@ class opener(object):
                 return atomictempfile(f, mode, self.createmode)
             try:
                 if 'w' in mode:
-                    st_mode = os.lstat(f).st_mode & 0777
+                    if preserveflags:
+                        st_mode = os.lstat(f).st_mode & 0777
                     os.unlink(f)
                     nlink = 0
                 else:


More information about the Mercurial-devel mailing list