changeset 8065:66d0a03d3afc

extdiff: preserve execute-bit across copies (issue1562) Bug report and test by Mads Kiilerich <mads@kiilerich.com>
author Patrick Mezard <pmezard@gmail.com>
date Thu, 09 Apr 2009 14:32:44 +0200
parents 5c7bc1aece9e
children aece3c9e62f1 6c3b8132078e fd7cc930ab8f
files hgext/extdiff.py tests/test-extdiff tests/test-extdiff.out
diffstat 3 files changed, 66 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/extdiff.py	Mon Apr 13 21:21:01 2009 +0200
+++ b/hgext/extdiff.py	Thu Apr 09 14:32:44 2009 +0200
@@ -67,7 +67,7 @@
     else:
         ui.note(_('making snapshot of %d files from working dir\n') %
             (len(files)))
-        
+    wopener = util.opener(base)
     fns_and_mtime = []
     ctx = repo[node]
     for fn in files:
@@ -77,11 +77,14 @@
             continue
         ui.note('  %s\n' % wfn)
         dest = os.path.join(base, wfn)
-        destdir = os.path.dirname(dest)
-        if not os.path.isdir(destdir):
-            os.makedirs(destdir)
-        data = repo.wwritedata(wfn, ctx[wfn].data())
-        open(dest, 'wb').write(data)
+        fctx = ctx[wfn]
+        data = repo.wwritedata(wfn, fctx.data())
+        if 'l' in fctx.flags():
+            wopener.symlink(data, wfn)
+        else:
+            wopener(wfn, 'w').write(data)
+            if 'x' in fctx.flags():
+                util.set_flags(dest, False, True)
         if node is None:
             fns_and_mtime.append((dest, repo.wjoin(fn), os.path.getmtime(dest)))
     return dirname, fns_and_mtime
--- a/tests/test-extdiff	Mon Apr 13 21:21:01 2009 +0200
+++ b/tests/test-extdiff	Thu Apr 09 14:32:44 2009 +0200
@@ -28,7 +28,7 @@
 hg falabala -r 0:1
 
 # test diff during merge
-hg update 0
+hg update -C 0
 echo c >> c
 hg add c
 hg ci -m "new branch" -d '1 0'
@@ -43,3 +43,24 @@
 # check diff are made from the first parent
 hg falabala -c 3 || echo "diff-like tools yield a non-zero exit code"
 #hg log
+
+echo
+echo '% test extdiff of multiple files in tmp dir:'
+hg update -C 0 > /dev/null
+echo changed > a
+echo changed > b
+chmod +x b
+echo '% diff in working directory, before'
+hg diff --git
+echo '% edit with extdiff -p'
+# prepare custom diff/edit tool
+cat > differ.sh << EOT
+#!/bin/sh
+sleep 1 # avoid unchanged-timestamp problems
+echo edited >> a/a
+echo edited >> a/b
+EOT
+chmod +x differ.sh
+hg extdiff -p `pwd`/differ.sh # will change to /tmp/extdiff.TMP and populate directories a.TMP and a and start tool
+echo '% diff in working directory, after'
+hg diff --git
--- a/tests/test-extdiff.out	Mon Apr 13 21:21:01 2009 +0200
+++ b/tests/test-extdiff.out	Thu Apr 09 14:32:44 2009 +0200
@@ -34,3 +34,38 @@
 diffing a.8a5febb7f867/a a.34eed99112ab/a
 diffing a.2a13a4d2da36/a a.46c0e4daeb72/a
 diff-like tools yield a non-zero exit code
+
+% test extdiff of multiple files in tmp dir:
+% diff in working directory, before
+diff --git a/a b/a
+--- a/a
++++ b/a
+@@ -1,1 +1,1 @@
+-a
++changed
+diff --git a/b b/b
+old mode 100644
+new mode 100755
+--- a/b
++++ b/b
+@@ -1,1 +1,1 @@
+-b
++changed
+% edit with extdiff -p
+% diff in working directory, after
+diff --git a/a b/a
+--- a/a
++++ b/a
+@@ -1,1 +1,2 @@
+-a
++changed
++edited
+diff --git a/b b/b
+old mode 100644
+new mode 100755
+--- a/b
++++ b/b
+@@ -1,1 +1,2 @@
+-b
++changed
++edited