How to name template filter to remove duplicates from list?
Manuel Jacob
me at manueljacob.de
Fri Sep 16 01:38:42 UTC 2022
Original motivation: In one of my repositories, when merging from the
development branch to the production branch, I’d like to list all
branches that were merged into the development branch since the last
merge from the development branch into the production branch. If a
branch consists of multiple changesets or the branch was merged multiple
times, the branch should not be listed multiple times (at least not in a
row). There doesn’t seem to be a way to remove duplicates from a list
with existing template filters.
While I have not decided whether I want to remove all duplicates or only
adjacent ones, I think both would be useful as template filters, so I’d
like to implement them. Even if I end up implementing only one, it’s
good to keep the other in mind.
The Unix tool uniq removes only adjacent duplicates, which I found
surprising at first. I wouldn’t find "uniq" a good name for any variant
of the filter, since removing only adjacent duplicates might surprise
users not knowing the Unix tool, and removing all duplicates might
surprise users knowing the Unix tool.
The name "removeduplicates" is descriptive but quite long. It could take
an argument to choose whether all or only adjacent duplicates should be
removed. Examples:
"{'a\na\nb\na'|splitlines|removeduplicates}\n"
-> "a b"
"{removeduplicates('a\na\nb\na'|splitlines, onlyadjacent=False)}\n"
-> "a b"
"{removeduplicates('a\na\nb\na'|splitlines, onlyadjacent=True)}\n"
-> "a b a"
Any other ideas?
More information about the Mercurial-devel
mailing list