mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Stanza.WriteTo: Sort extra fields alphabetically
This makes the output deterministic. This is important to me as I am using `Packages` index files as a kind of lockfile and committing it to my git repository. Without this we get a lot of noise in the diff whenever the file is regenerated because [go randomises map iteration order][1]. [1]: https://nathanleclaire.com/blog/2014/04/27/a-surprising-feature-of-golang-that-colored-me-impressed/
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
@@ -182,8 +183,16 @@ func (s Stanza) WriteTo(w *bufio.Writer, isSource, isRelease, isInstaller bool)
|
||||
|
||||
// no extra fields in installer
|
||||
if !isInstaller {
|
||||
for field, value := range s {
|
||||
err := writeField(w, field, value, isRelease)
|
||||
// Print extra fields in deterministic order (alphabetical)
|
||||
keys := make([]string, len(s))
|
||||
i := 0
|
||||
for field := range s {
|
||||
keys[i] = field
|
||||
i++
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, field := range keys {
|
||||
err := writeField(w, field, s[field], isRelease)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user