db/Count: print empty group if song without grouped tag exists

Be consistent with "list" responses.
This commit is contained in:
Max Kellermann 2018-10-22 12:42:18 +02:00
parent 6c06244e83
commit 7cfe929c36
4 changed files with 18 additions and 4 deletions

1
NEWS
View File

@ -1,6 +1,7 @@
ver 0.20.22 (not yet released)
* protocol
- add tag fallbacks for AlbumArtistSort, ArtistSort
- "count group ..." can print an empty group
* storage
- curl: URL-encode paths
* Android

View File

@ -1599,6 +1599,11 @@ OK
per-artist counts:
</para>
<programlisting>count group artist</programlisting>
<para>
A group with an empty value contains counts of matching
song which don't this group tag. It exists only if at
least one such song is found.
</para>
</listitem>
</varlistentry>

View File

@ -90,7 +90,7 @@ GroupCountVisitor(TagCountMap &map, TagType group, const LightSong &song)
assert(song.tag != nullptr);
const Tag &tag = *song.tag;
VisitTagWithFallback(tag, group,
VisitTagWithFallbackOrEmpty(tag, group,
std::bind(CollectGroupCounts, std::ref(map),
std::cref(tag),
std::placeholders::_1));

View File

@ -49,4 +49,12 @@ VisitTagWithFallback(const Tag &tag, TagType type, F &&f) noexcept
});
}
template<typename F>
void
VisitTagWithFallbackOrEmpty(const Tag &tag, TagType type, F &&f) noexcept
{
if (!VisitTagWithFallback(tag, type, f))
f("");
}
#endif