D468: Use ~ as a suffix when creating a temp file in the same directory as a source file.

mbolin (Michael Bolin) phabricator at mercurial-scm.org
Tue Aug 22 00:39:22 UTC 2017


mbolin created this revision.
Herald added a subscriber: mercurial-devel.

REVISION SUMMARY
  Tools like Buck have patterns to ignore the creation of files (in the working
  copy) that match certain patterns:
  
  https://github.com/facebook/buck/blob/39278a4f0701c5239eae148968dc1ed4cc8661f7/src/com/facebook/buck/cli/Main.java#L259-L299
  
  When Buck sees a new source file (as reported by Watchman), it has to invalidate
  a number of caches associated with the directory that contains the file.
  Using a standard suffix, such as `~`, would make it easier for Buck and others
  to filter out these types of file creation events.
  
  The other uses of `tempfile.mkstemp()` in Hg do not appear to be problematic
  because they (generally speaking) do not specify the `dir` parameter, so the
  new file is created in the system-appropriate temp directory, which is outside
  the working copy.

TEST PLAN
  CI

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D468

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1525,7 +1525,7 @@
     Returns the name of the temporary file.
     """
     d, fn = os.path.split(name)
-    fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d)
+    fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d)
     os.close(fd)
     # Temporary files are created with mode 0600, which is usually not
     # what we want.  If the original file already exists, just copy



To: mbolin, #hg-reviewers, quark, durin42
Cc: mercurial-devel


More information about the Mercurial-devel mailing list