D468: util: use ~ as a suffix for a temp file in the same directory as a source file

quark (Jun Wu) phabricator at mercurial-scm.org
Wed Aug 23 15:05:01 EDT 2017


quark added a comment.


  In https://phab.mercurial-scm.org/D468#7833, @smf wrote:
  
  > Basically, I'd like a more unified approach for all types of temp files (commit message, histedit, conflicts, etc).
  
  
  I think this patch is about low-level `util` function that shouldn't be coupled with `ui` or config. It has value on its own and I don't think such "unified approach" should block this patch - we can always add configs and make callers of `util.mktempcopy` pass `suffix` down here AFTER this patch.

INLINE COMMENTS

> util.py:1517
>  
>  def mktempcopy(name, emptyok=False, createmode=None):
>      """Create a temporary file with the same contents from name

Could you make `suffix` a keyword argument here, default to `~`?

Therefore we can give callsite control about what extension it wants.

> util.py:1528
>      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)

And use `suffix=suffix` here.

REPOSITORY
  rHG Mercurial

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

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


More information about the Mercurial-devel mailing list