Skip to content

Commit

Permalink
Fix changelog trimming to work relative to newest existing entry (#1301)
Browse files Browse the repository at this point in the history
%_changelog_trimtime is an absolute timestamp which needs to be constantly
pushed forward to preserve the same relative age, and will start trimming
entries from unchanged packages until none are left, leading to unexpected
and confusing behavior (RhBug:1722806, ...)

It's better to trim by age relative to newest changelog entry. This way the
number of trimmed entries will not change unless the spec changes, and at
least one entry is always preserved. Introduce a new %_changelog_trimage
macro for this and mark the broken by design %_changelog_trimtime as
deprecated, but autoconvert an existing trimtime into relative for now.

As a seemingly unrelated change, move the "time" variable declaration
to a narrower scope to unmask the time() function for use on entry.

Fixes: #1301
  • Loading branch information
pmatilai authored and ffesti committed Aug 11, 2020
1 parent 28b3704 commit a587258
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion build/parseChangelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,26 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
rpmRC rc = RPMRC_FAIL; /* assume failure */
char *s, *sp;
int i;
time_t time;
time_t firstTime = 0;
time_t lastTime = 0;
time_t trimtime = rpmExpandNumeric("%{?_changelog_trimtime}");
time_t trimage = rpmExpandNumeric("%{?_changelog_trimage}");
char *date, *name, *text, *next;
int date_words; /* number of words in date string */

/* Convert _changelog_trimtime to age for backwards compatibility */
if (trimtime && !trimage) {
trimage = time(NULL) - trimtime;
trimtime = 0;
}

s = sp = argvJoin(sb, "");

/* skip space */
SKIPSPACE(s);

while (*s != '\0') {
time_t time;
if (*s != '*') {
rpmlog(RPMLOG_ERR, _("%%changelog entries must start with *\n"));
goto exit;
Expand All @@ -235,6 +243,12 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
rpmlog(RPMLOG_ERR, _("bad date in %%changelog: %s\n"), date);
goto exit;
}
/* Changelog trimming is always relative to first entry */
if (!firstTime) {
firstTime = time;
if (trimage)
trimtime = firstTime - trimage;
}
if (lastTime && lastTime < time) {
rpmlog(RPMLOG_ERR,
_("%%changelog not in descending chronological order\n"));
Expand Down
6 changes: 5 additions & 1 deletion macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@ package or when debugging this package.\
%__global_requires_exclude_from %{?_docdir:%{_docdir}}
%__global_provides_exclude_from %{?_docdir:%{_docdir}}

# Maximum age of preserved changelog entries in binary packages,
# relative to newest existing entry. Unix timestamp format.
%_changelog_trimage 0

# The Unix time of the latest kept changelog entry in binary packages.
# Any older entry is not packaged in binary packages.
# DEPRACATED, use %_changelog_trimage instead.
%_changelog_trimtime 0

# If true, set the SOURCE_DATE_EPOCH environment variable
Expand Down

0 comments on commit a587258

Please sign in to comment.