[PATCH 1 of 2 STABLE resend] keyword: preserve file mode when overwriting

Christian Ebert blacktrash at gmx.net
Thu Sep 8 13:33:32 CDT 2011


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1315506625 -3600
# Node ID 1e6056cf1f266f91c703c38dbb24a1b854752bbd
# Parent  6ab8b17adc03c423b53fb50951058915edc4ca60
keyword: preserve file mode when overwriting

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -270,7 +270,10 @@
                 data, found = _shrinktext(data, re_kw.subn)
             if found:
                 self.ui.note(msg % f)
+                fpath = self.repo.wjoin(f)
+                mode = os.lstat(fpath).st_mode
                 self.repo.wwrite(f, data, ctx.flags(f))
+                os.chmod(fpath, mode)
                 if kwcmd:
                     self.repo.dirstate.normal(f)
                 elif self.record:
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -270,15 +270,20 @@
   xxx $
   ignore $Id$
 
-Check whether expansion is filewise
+Check whether expansion is filewise and file mode is preserved
 
   $ echo '$Id$' > c
   $ echo 'tests for different changenodes' >> c
+  $ chmod 600 c
+  $ ls -l c | cut -b 1-10
+  -rw-------
 
 commit file c
 
   $ hg commit -A -mcndiff -d '1 0' -u 'User Name <user at example.com>'
   adding c
+  $ ls -l c | cut -b 1-10
+  -rw-------
 
 force expansion
 


More information about the Mercurial-devel mailing list