changeset 48775:b70c9697ab41

filemerge: put temporary files in single temp dir by default The feature introduced in D2888 seems like a pure improvement to me. It makes the names' of temporary file easier to read. Let's have it always enabled. I also removed the config option for the path prefix because it doesn't seem useful. I asked Kyle (the author of the feature) about it and he couldn't think of a reason to keep it. I suspect it was just that we to have a config to turn it on/off while it was experimental, so it might as well be a configurable prefix then. Differential Revision: https://phab.mercurial-scm.org/D12171
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 11 Feb 2022 16:52:48 -0800
parents 79a967128055
children 6cfa30681a1d
files mercurial/configitems.py mercurial/filemerge.py tests/test-merge-tools.t
diffstat 3 files changed, 9 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/configitems.py	Tue Feb 15 05:20:46 2022 +0100
+++ b/mercurial/configitems.py	Fri Feb 11 16:52:48 2022 -0800
@@ -1042,11 +1042,6 @@
 )
 coreconfigitem(
     b'experimental',
-    b'mergetempdirprefix',
-    default=None,
-)
-coreconfigitem(
-    b'experimental',
     b'mmapindexthreshold',
     default=None,
 )
--- a/mercurial/filemerge.py	Tue Feb 15 05:20:46 2022 +0100
+++ b/mercurial/filemerge.py	Fri Feb 11 16:52:48 2022 -0800
@@ -926,22 +926,15 @@
     copies `localpath` to another temporary file, so an external merge tool may
     use them.
     """
-    tmproot = None
-    tmprootprefix = repo.ui.config(b'experimental', b'mergetempdirprefix')
-    if tmprootprefix:
-        tmproot = pycompat.mkdtemp(prefix=tmprootprefix)
+    tmproot = pycompat.mkdtemp(prefix=b'hgmerge-')
 
     def maketempfrompath(prefix, path):
         fullbase, ext = os.path.splitext(path)
         pre = b"%s~%s" % (os.path.basename(fullbase), prefix)
-        if tmproot:
-            name = os.path.join(tmproot, pre)
-            if ext:
-                name += ext
-            f = open(name, "wb")
-        else:
-            fd, name = pycompat.mkstemp(prefix=pre + b'.', suffix=ext)
-            f = os.fdopen(fd, "wb")
+        name = os.path.join(tmproot, pre)
+        if ext:
+            name += ext
+        f = open(name, "wb")
         return f, name
 
     def tempfromcontext(prefix, ctx):
@@ -967,15 +960,7 @@
     try:
         yield b, c, d
     finally:
-        if tmproot:
-            shutil.rmtree(tmproot)
-        else:
-            util.unlink(b)
-            util.unlink(c)
-            # if not uselocalpath, d is the 'orig'/backup file which we
-            # shouldn't delete.
-            if d and uselocalpath:
-                util.unlink(d)
+        shutil.rmtree(tmproot)
 
 
 def filemerge(repo, wctx, mynode, orig, fcd, fco, fca, labels=None):
--- a/tests/test-merge-tools.t	Tue Feb 15 05:20:46 2022 +0100
+++ b/tests/test-merge-tools.t	Fri Feb 11 16:52:48 2022 -0800
@@ -1592,34 +1592,7 @@
   arg: "ll:working copy"
   arg: "lo:"
   arg: "merge rev"
-  arg: "lb:common ancestor: */f~base.*" (glob)
-  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
-  (branch merge, don't forget to commit)
-  $ rm -f 'printargs_merge_tool'
-
-Same test with experimental.mergetempdirprefix set:
-
-  $ beforemerge
-  [merge-tools]
-  false.whatever=
-  true.priority=1
-  true.executable=cat
-  # hg update -C 1
-  $ cat <<EOF > printargs_merge_tool
-  > while test \$# -gt 0; do echo arg: \""\$1"\"; shift; done
-  > EOF
-  $ hg --config experimental.mergetempdirprefix=$TESTTMP/hgmerge. \
-  >    --config merge-tools.true.executable='sh' \
-  >    --config merge-tools.true.args='./printargs_merge_tool ll:$labellocal lo: $labelother lb:$labelbase": "$base' \
-  >    --config merge-tools.true.mergemarkertemplate='tooltmpl {short(node)}' \
-  >    --config ui.mergemarkertemplate='uitmpl {rev}' \
-  >    --config ui.mergemarkers=detailed \
-  >    merge -r 2
-  merging f
-  arg: "ll:working copy"
-  arg: "lo:"
-  arg: "merge rev"
-  arg: "lb:common ancestor: */hgmerge.*/f~base" (glob)
+  arg: "lb:common ancestor: */f~base" (glob)
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ rm -f 'printargs_merge_tool'
@@ -1649,7 +1622,7 @@
   arg: "ll:working copy: tooltmpl ef83787e2614"
   arg: "lo:"
   arg: "merge rev: tooltmpl 0185f4e0cf02"
-  arg: "lb:common ancestor: */f~base.*" (glob)
+  arg: "lb:common ancestor: */f~base" (glob)
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ rm -f 'printargs_merge_tool'
@@ -1895,23 +1868,7 @@
   $ 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.* */f~local.*.txt */f~other.*.txt $TESTTMP/repo/f.txt (glob)
-  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
-  (branch merge, don't forget to commit)
-
-Verify naming of temporary files and that extension is preserved
-(experimental.mergetempdirprefix version):
-
-  $ hg update -q -C 1
-  $ hg mv f f.txt
-  $ hg ci -qm "f.txt"
-  warning: commit already existed in the repository!
-  $ hg update -q -C 2
-  $ hg merge -y -r tip --tool echo \
-  >    --config merge-tools.echo.args='$base $local $other $output' \
-  >    --config experimental.mergetempdirprefix=$TESTTMP/hgmerge.
-  merging f and f.txt to f.txt
-  $TESTTMP/hgmerge.*/f~base $TESTTMP/hgmerge.*/f~local.txt $TESTTMP/hgmerge.*/f~other.txt $TESTTMP/repo/f.txt (glob)
+  */hgmerge-*/f~base */hgmerge-*/f~local.txt */hgmerge-*/f~other.txt */repo/f.txt (glob)
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)