Skip to content

Commit

Permalink
history: Improve timestamps by changing them less often
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ikeydoherty committed Nov 21, 2017
1 parent 139b3e9 commit dbb1314
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
30 changes: 30 additions & 0 deletions src/builder/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit dbb1314

Please sign in to comment.