[PATCH] convert: handle exec bit removal while converting to svn

Nikita Slyusarev nslus at yandex-team.com
Thu Feb 7 19:21:29 UTC 2019


# HG changeset patch
# User Nikita Slyusarev <nslus at yandex-team.com>
# Date 1549565330 -10800
#      Thu Feb 07 21:48:50 2019 +0300
# Node ID afd7bd1378b43b306567245ac0e394c4432e944d
# Parent  286eeed148932d53eab7193c8e5deda39f9131f9
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.

diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -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:
diff --git a/tests/test-convert-svn-sink.t b/tests/test-convert-svn-sink.t
--- a/tests/test-convert-svn-sink.t
+++ b/tests/test-convert-svn-sink.t
@@ -466,3 +466,42 @@
   msg: Add file a
    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


More information about the Mercurial-devel mailing list