Patchwork D12190: filemerge: move removal of `.orig` extension on temp file close to context

login
register
mail settings
Submitter phabricator
Date Feb. 16, 2022, 4:09 a.m.
Message ID <differential-rev-PHID-DREV-b3wtis4x6jsz6m7mrgi6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50527/
State New
Headers show

Comments

phabricator - Feb. 16, 2022, 4:09 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The place where the `.orig` extension is removed in `_maketempfiles()`
  doesn't make it clear that it's the backup path, which is why we have
  a comment in the code explaining it. Let's instead move it out of the
  function and close to where we get it from `backup.path()`, so that
  becomes clear.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/filemerge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -746,6 +746,9 @@ 
     localoutputpath = None
     if b"$output" in args:
         localoutputpath = backup.path()
+        # Remove the .orig to make syntax-highlighting more likely.
+        if localoutputpath.endswith(b'.orig'):
+            localoutputpath, ext = os.path.splitext(localoutputpath)
 
     with _maketempfiles(
         fco,
@@ -940,10 +943,6 @@ 
     c = tempfromcontext(b"other", fco)
     d = localpath
     if localpath is not None:
-        # We start off with this being the backup filename, so remove the .orig
-        # to make syntax-highlighting more likely.
-        if d.endswith(b'.orig'):
-            d, _ = os.path.splitext(d)
         f, d = maketempfrompath(b"local", d)
         with open(localpath, b'rb') as src:
             f.write(src.read())