merge: sort filemap only if requested by the caller stable
authorManuel Jacob <me@manueljacob.de>
Wed, 07 Aug 2024 22:05:36 +0200
branchstable
changeset 51681 23116aefe786
parent 51680 187d7c859be7
child 51682 6388fd855f66
merge: sort filemap only if requested by the caller The name `sorted` refers to a built-in function, which is always true, so the else branch of this if statement was dead code. Because, with this fix, the function can iterate over the dict items while yielding values, the dict should not change size while the generator is running. Because of that, it is required to re-introduce code that makes a caller copy the filemap before modification, which was removed in 3c783ff08d40cbaf36eb27ffe1d296718c0f1d77 (that changeset also introduced the filemap() method including the bug that’s being fixed by this changeset).
mercurial/merge.py
--- a/mercurial/merge.py	Fri Aug 09 22:45:32 2024 +0200
+++ b/mercurial/merge.py	Wed Aug 07 22:05:36 2024 +0200
@@ -521,7 +521,7 @@
     """
     # We mutate the items in the dict during iteration, so iterate
     # over a copy.
-    for f, action in mresult.filemap():
+    for f, action in list(mresult.filemap()):
         if narrowmatch(f):
             pass
         elif not branchmerge:
@@ -662,7 +662,7 @@
         return sum(len(self._actionmapping[a]) for a in actions)
 
     def filemap(self, sort=False):
-        if sorted:
+        if sort:
             for key, val in sorted(self._filemapping.items()):
                 yield key, val
         else: