changeset 41628:36ee0d6d64c5

convert: handle exec bit removal while converting to svn Subversion `putcommit` method checks original file's executablity to decide if executable property should be removed from svn. It is checked right after writing file contents. Content writing is implemented using `vfs.write` and vfs seems to remove exec bit, at least in some cases. This leads to executability checks being ineffective. If cset contains only this ignored exec bit removal, conversion stops with an error, because it fails to to compose svn commit properly. This fix moves exec bit checking so that it's performed before dumping file contents. Added test to check executable bit removal.
author Nikita Slyusarev <nslus@yandex-team.com>
date Thu, 07 Feb 2019 21:48:50 +0300
parents 2c13e91ede6e
children e834f6f6f221
files hgext/convert/subversion.py tests/test-convert-svn-sink.t
diffstat 2 files changed, 48 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/subversion.py	Thu Feb 07 18:57:54 2019 +0300
+++ b/hgext/convert/subversion.py	Thu Feb 07 21:48:50 2019 +0300
@@ -1206,10 +1206,18 @@
                     os.unlink(filename)
             except OSError:
                 pass
+
+            if self.is_exec:
+                # We need to check executability of the file before the change,
+                # because `vfs.write` is able to reset exec bit.
+                wasexec = False
+                if os.path.exists(self.wjoin(filename)):
+                    wasexec = self.is_exec(self.wjoin(filename))
+
             self.wopener.write(filename, data)
 
             if self.is_exec:
-                if self.is_exec(self.wjoin(filename)):
+                if wasexec:
                     if 'x' not in flags:
                         self.delexec.append(filename)
                 else:
--- a/tests/test-convert-svn-sink.t	Thu Feb 07 18:57:54 2019 +0300
+++ b/tests/test-convert-svn-sink.t	Thu Feb 07 21:48:50 2019 +0300
@@ -467,6 +467,45 @@
    A /a
   $ rm -rf a a-hg a-hg-wc
 
+#if execbit
+
+Executable bit removal
+
+  $ hg init a
+
+  $ echo a > a/exec
+  $ chmod +x a/exec
+  $ hg --cwd a ci -d '1 0' -A -m 'create executable'
+  adding exec
+  $ chmod -x a/exec
+  $ hg --cwd a ci -d '2 0' -A -m 'remove executable bit'
+
+  $ hg convert -d svn a
+  assuming destination a-hg
+  initializing svn repository 'a-hg'
+  initializing svn working copy 'a-hg-wc'
+  scanning source...
+  sorting...
+  converting...
+  1 create executable
+  0 remove executable bit
+  $ svnupanddisplay a-hg-wc 0
+   2 2 test .
+   2 2 test exec
+  revision: 2
+  author: test
+  msg: remove executable bit
+   M /exec
+  revision: 1
+  author: test
+  msg: create executable
+   A /exec
+  $ test ! -x a-hg-wc/exec
+
+  $ rm -rf a a-hg a-hg-wc
+
+#endif
+
 Skipping empty commits
 
   $ hg init a