From dbb1314f1ba4ac3ac987a31cea727c868f44c4c8 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Tue, 21 Nov 2017 00:38:39 +0000 Subject: [PATCH] history: Improve timestamps by changing them less often Currently we change the version timestamp on every single bump of the package, which causes a lot of unnecessary noise. Further, this impacts the usefuless of delta packages by skewing their timestamps from simple bump-rebuilds. We now set the timestamp to the time the version last changed, as opposed to when the release number changed, to signify major differences. This is extracted from the tag data and analysing the spec at that point in time. Combined with the latest ypkg change to emit `SOURCE_DATE_EPOCH`, this should remove much of the jitter in between package rebuilds and restore sane deltas in no time at all. Signed-off-by: Ikey Doherty --- src/builder/build.go | 2 +- src/builder/history.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/builder/build.go b/src/builder/build.go index 9f0e93a..917173f 100644 --- a/src/builder/build.go +++ b/src/builder/build.go @@ -383,7 +383,7 @@ func (p *Package) BuildYpkg(notif PidNotifier, usr *UserInfo, pman *EopkgManager } // Pass unix timestamp of last git update if h != nil && len(h.Updates) > 0 { - cmd += fmt.Sprintf(" -t %v", h.Updates[0].Time.UTC().Unix()) + cmd += fmt.Sprintf(" -t %v", h.GetLastVersionTimestamp()) } log.WithFields(log.Fields{ diff --git a/src/builder/history.go b/src/builder/history.go index e6f1bec..5ac264c 100644 --- a/src/builder/history.go +++ b/src/builder/history.go @@ -335,3 +335,33 @@ func (p *PackageHistory) WriteXML(path string) error { _, err = fi.WriteString(string(bytes)) return err } + +// GetLastVersionTimestamp will return a timestamp appropriate for us within +// reproducible builds. +// +// This is calculated by using the timestamp from the last explicit version +// change, and not from simple bumps. The idea here is to only increment the +// timestamp if we've actually upgraded to a major version, and in general +// attempt to reduce the noise, and thus, produce better delta packages +// between minor package alterations +func (p *PackageHistory) GetLastVersionTimestamp() int64 { + lastVersion := p.Updates[0].Package.Version + lastTime := p.Updates[0].Time + + if len(p.Updates) < 2 { + return lastTime.UTC().Unix() + } + + // Walk history and find the last version change, assigning timestamp + // as appropriate. + for i := 1; i < len(p.Updates); i++ { + newVersion := p.Updates[i].Package.Version + if newVersion != lastVersion { + break + } + lastVersion = p.Updates[i].Package.Version + lastTime = p.Updates[i].Time + } + + return lastTime.UTC().Unix() +}