Patchwork merge: use original file extension for temporary files

login
register
mail settings
Submitter Mads Kiilerich
Date Nov. 23, 2016, 10:47 p.m.
Message ID <9cee175ec5a6e2530190.1479941274@madski>
Download mbox | patch
Permalink /patch/17731/
State Accepted
Headers show

Comments

Mads Kiilerich - Nov. 23, 2016, 10:47 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1479941258 -3600
#      Wed Nov 23 23:47:38 2016 +0100
# Node ID 9cee175ec5a6e2530190a120244c0d210c469dd8
# Parent  b3808b2f2e8758f5c763344ce4b81dcf723028ae
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.
Yuya Nishihara - Nov. 27, 2016, 9:15 a.m.
On Wed, 23 Nov 2016 23:47:54 +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1479941258 -3600
> #      Wed Nov 23 23:47:38 2016 +0100
> # Node ID 9cee175ec5a6e2530190a120244c0d210c469dd8
> # Parent  b3808b2f2e8758f5c763344ce4b81dcf723028ae
> 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.

Makes sense. Queued, thanks.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -576,8 +576,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)