# HG changeset patch # User Mads Kiilerich # Date 2016-11-23 22:47:38 # Node ID c2154979409d5b9077b88c181f07da69a6f680dc # Parent 4b0e6677eed193148e6ed7071ed666bdf09f3580 merge: use original file extension for temporary files Some merge tools (like Araxis?) can pick merge mode based on the file extension. That didn't work well when temporary files were given random suffixes. It seems to work better when the random part is before the extension. As usual, when using $output, $local will have the .orig extension. That could perhaps be the subject of another change another day. diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -577,8 +577,9 @@ def _filemerge(premerge, repo, mynode, o a boolean indicating whether the file was deleted from disk.""" def temp(prefix, ctx): - pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) - (fd, name) = tempfile.mkstemp(prefix=pre) + fullbase, ext = os.path.splitext(ctx.path()) + pre = "%s~%s." % (os.path.basename(fullbase), prefix) + (fd, name) = tempfile.mkstemp(prefix=pre, suffix=ext) data = repo.wwritedata(ctx.path(), ctx.data()) f = os.fdopen(fd, "wb") f.write(data) diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t --- a/tests/test-merge-tools.t +++ b/tests/test-merge-tools.t @@ -1209,3 +1209,15 @@ internal merge cannot handle symlinks an [1] #endif + +Verify naming of temporary files and that extension is preserved: + + $ hg update -q -C 1 + $ hg mv f f.txt + $ hg ci -qm "f.txt" + $ hg update -q -C 2 + $ hg merge -y -r tip --tool echo --config merge-tools.echo.args='$base $local $other $output' + merging f and f.txt to f.txt + */f~base.?????? $TESTTMP/f.txt.orig */f~other.??????.txt $TESTTMP/f.txt (glob) + 0 files updated, 1 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit)