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).
--- 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: