File minchangescount.patch of Package rpm

commit 17cc2a1ead4384c7d453aa7ddd9ebabcfb9b6266
Author: Bernhard M. Wiedemann <bwiedemann@suse.de>
Date:   Fri Nov 8 11:58:39 2019 +0100

    Allow to keep a minimum number of changelog entries
    
    because some tools and workflows break when _changelog_trimtime
    dropped all entries.

diff --git a/build/parseChangelog.c b/build/parseChangelog.c
index ad6d834a1..8380778fe 100644
--- a/build/parseChangelog.c
+++ b/build/parseChangelog.c
@@ -203,6 +203,8 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
     time_t time;
     time_t lastTime = 0;
     time_t trimtime = rpmExpandNumeric("%{?_changelog_trimtime}");
+    int minchangescount = rpmExpandNumeric("%{?_changelog_mincount}");
+    int changescount = 0;
     char *date, *name, *text, *next;
     int date_words;      /* number of words in date string */
 
@@ -284,7 +286,7 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
 	    *s-- = '\0';
 	}
 	
-	if ( !trimtime || time >= trimtime ) {
+	if ( !trimtime || time >= trimtime || changescount++ < minchangescount ) {
 	    addChangelogEntry(h, time, name, text);
 	} else break;
 	
diff --git a/macros.in b/macros.in
index 4f7efb2ae..f3c8c12c4 100644
--- a/macros.in
+++ b/macros.in
@@ -234,6 +234,10 @@ package or when debugging this package.\
 #	Any older entry is not packaged in binary packages.
 %_changelog_trimtime	0
 
+#	When using %_changelog_trimtime, ensure to keep at least
+#	this many entries to reduce confusion of users and tools
+%_changelog_mincount	1
+
 #	If true, set the SOURCE_DATE_EPOCH environment variable
 #	to the timestamp of the topmost changelog entry
 %source_date_epoch_from_changelog 0