From 7cfe929c3692e74f4e6073960eaf0e08a9989811 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 22 Oct 2018 12:42:18 +0200 Subject: [PATCH] db/Count: print empty group if song without grouped tag exists Be consistent with "list" responses. --- NEWS | 1 + doc/protocol.xml | 5 +++++ src/db/Count.cxx | 8 ++++---- src/tag/VisitFallback.hxx | 8 ++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 9507057e7..5b8a3b48c 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/doc/protocol.xml b/doc/protocol.xml index 4b9a4c95a..75cdb5478 100644 --- a/doc/protocol.xml +++ b/doc/protocol.xml @@ -1599,6 +1599,11 @@ OK per-artist counts: count group artist + + 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. + diff --git a/src/db/Count.cxx b/src/db/Count.cxx index ba0d443e7..dccb3e8c7 100644 --- a/src/db/Count.cxx +++ b/src/db/Count.cxx @@ -90,10 +90,10 @@ GroupCountVisitor(TagCountMap &map, TagType group, const LightSong &song) assert(song.tag != nullptr); const Tag &tag = *song.tag; - VisitTagWithFallback(tag, group, - std::bind(CollectGroupCounts, std::ref(map), - std::cref(tag), - std::placeholders::_1)); + VisitTagWithFallbackOrEmpty(tag, group, + std::bind(CollectGroupCounts, std::ref(map), + std::cref(tag), + std::placeholders::_1)); } void diff --git a/src/tag/VisitFallback.hxx b/src/tag/VisitFallback.hxx index 3ad486f5f..23992d44b 100644 --- a/src/tag/VisitFallback.hxx +++ b/src/tag/VisitFallback.hxx @@ -49,4 +49,12 @@ VisitTagWithFallback(const Tag &tag, TagType type, F &&f) noexcept }); } +template +void +VisitTagWithFallbackOrEmpty(const Tag &tag, TagType type, F &&f) noexcept +{ + if (!VisitTagWithFallback(tag, type, f)) + f(""); +} + #endif