diff --git a/hgext/extdiff.py b/hgext/extdiff.py --- a/hgext/extdiff.py +++ b/hgext/extdiff.py @@ -67,7 +67,7 @@ def snapshot(ui, repo, files, node, tmpr 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 @@ def snapshot(ui, repo, files, node, tmpr 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 diff --git a/tests/test-extdiff b/tests/test-extdiff --- a/tests/test-extdiff +++ b/tests/test-extdiff @@ -28,7 +28,7 @@ hg ci -d '1 0' -mtest2 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 @@ hg falabala -c 1 # 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 diff --git a/tests/test-extdiff.out b/tests/test-extdiff.out --- a/tests/test-extdiff.out +++ b/tests/test-extdiff.out @@ -34,3 +34,38 @@ diffing a.2a13a4d2da36/a [tmp]/test-extd 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