[Request] [+ ] D12149: filemerge: when not keeping premerge, don't write markers to context

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Feb 8 21:28:12 UTC 2022


martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  When premerge is enabled (as it is for non-binary inputs by default)
  and the markers are not kept, we currently still write it to the
  output context and then restore the previous content right after. With
  the refactoring in the previous patch, we can easily avoid that step
  and instead write the output in the opposite case (i.e. when it's
  successful or when the markers are supposed to be kept).

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/filemerge.py

CHANGE DETAILS

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -439,16 +439,15 @@
             merged_text, conflicts = simplemerge.simplemerge(
                 ui, local, base, other, mode=mode
             )
-            # fcd.flags() already has the merged flags (done in
-            # mergestate.resolve())
-            if merged_text is not None:
+            if merged_text is not None and (
+                not conflicts or premerge in validkeep
+            ):
+                # fcd.flags() already has the merged flags (done in
+                # mergestate.resolve())
                 local.fctx.write(merged_text, local.fctx.flags())
             if not conflicts:
                 ui.debug(b" premerge successful\n")
                 return 0
-        if premerge not in validkeep:
-            # restore from backup and try again
-            _restorebackup(local.fctx, backup)
     return 1  # continue merging
 
 
@@ -875,12 +874,6 @@
     }
 
 
-def _restorebackup(fcd, backup):
-    # TODO: Add a workingfilectx.write(otherfilectx) path so we can use
-    # util.copy here instead.
-    fcd.write(backup.data(), fcd.flags())
-
-
 def _makebackup(repo, ui, wctx, fcd):
     """Makes and returns a filectx-like object for ``fcd``'s backup file.
 



To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20220208/d6d1c33a/attachment.html>


More information about the Mercurial-patches mailing list