diff --git a/build/parseChangelog.c b/build/parseChangelog.c index 65c0952a69..d8159a25a6 100644 --- a/build/parseChangelog.c +++ b/build/parseChangelog.c @@ -189,6 +189,39 @@ static int dateToTimet(const char * datestr, time_t * secs, int * date_words) return rc; } +/* + * Ensure each changelog entry has a different, reproducable timestamp. + * We could ensure different at parse-time, but as the changelog is + * parsed newest first, creating reproducable stamps requires processing + * in the opposite order. + */ +static void monotonize(Header h) +{ + struct rpmtd_s td; + + if (headerGet(h, RPMTAG_CHANGELOGTIME, &td, HEADERGET_ALLOC)) { + uint32_t *times = td.data; + uint32_t prevtime = 0; + int serial = 0; + + for (int i = td.count; i >= 0; i--) { + uint32_t t = times[i]; + if (prevtime) { + if (t == prevtime) { + serial++; + t += serial; + } else { + serial = 0; + } + } + prevtime = times[i]; + times[i] = t; + } + headerMod(h, &td); + rpmtdFreeData(&td); + } +} + /** * Add %changelog section to header. * @param h header @@ -304,6 +337,8 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb) s = next; } + monotonize(h); + rc = RPMRC_OK; exit: diff --git a/tests/Makefile.am b/tests/Makefile.am index af10bb06fb..e5daa097ce 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -54,6 +54,7 @@ EXTRA_DIST += data/SPECS/hello-g3.spec EXTRA_DIST += data/SPECS/foo.spec EXTRA_DIST += data/SPECS/globtest.spec EXTRA_DIST += data/SPECS/versiontest.spec +EXTRA_DIST += data/SPECS/chlog.spec EXTRA_DIST += data/SPECS/conflicttest.spec EXTRA_DIST += data/SPECS/configtest.spec EXTRA_DIST += data/SPECS/filedep.spec diff --git a/tests/data/SPECS/chlog.spec b/tests/data/SPECS/chlog.spec new file mode 100644 index 0000000000..a038b35c9f --- /dev/null +++ b/tests/data/SPECS/chlog.spec @@ -0,0 +1,25 @@ +Name: chlog +Summary: Testing changelog behavior +Version: 1.2 +Release: 5 +License: GPL + +%description +%{summary} + +%files + +%changelog +* Tue Jan 19 2021 Tester - 1.2-5 +- Oh no not again +* Mon Jan 18 2021 Tester - 1.2-4 +- This really isn't my day... +* Mon Jan 18 2021 Tester - 1.2-3 +- Oh, it's Monday +* Mon Jan 18 2021 - 1.2-2 +- Fixup one +* Mon Jan 18 2021 Tester - 1.2-1 +- Rebase to 1.2 +* Sun Feb 02 2020 Tester - 1.0-1 +- Initial version + diff --git a/tests/rpmspec.at b/tests/rpmspec.at index 2b11201dbf..025653c676 100644 --- a/tests/rpmspec.at +++ b/tests/rpmspec.at @@ -285,3 +285,31 @@ foo-bus = 1.0-1 ], []) AT_CLEANUP + +AT_SETUP([rpmspec changelog]) +AT_KEYWORDS([rpmspec changelog]) +AT_CHECK([[ +runroot rpmspec -q --qf '[* %{CHANGELOGTIME:date} %{CHANGELOGNAME}\n%{CHANGELOGTEXT}\n\n]' /data/SPECS/chlog.spec +]], +[0], +[* Tue Jan 19 12:00:00 2021 Tester - 1.2-5 +- Oh no not again + +* Mon Jan 18 12:00:03 2021 Tester - 1.2-4 +- This really isn't my day... + +* Mon Jan 18 12:00:02 2021 Tester - 1.2-3 +- Oh, it's Monday + +* Mon Jan 18 12:00:01 2021 - 1.2-2 +- Fixup one + +* Mon Jan 18 12:00:00 2021 Tester - 1.2-1 +- Rebase to 1.2 + +* Sun Feb 2 12:00:00 2020 Tester - 1.0-1 +- Initial version + +], +[]) +AT_CLEANUP