# HG changeset patch # User Manuel Jacob # Date 2024-08-07 20:05:36 # Node ID 23116aefe7865adc67e95b641607d5082c88adbb # Parent 187d7c859be70e0e054b50072679869220c63e33 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). diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -521,7 +521,7 @@ def _filternarrowactions(narrowmatch, br """ # 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 @@ class mergeresult: 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: