From 86dc10028f4f2a045797c9d3b072c7a034c257f7 Mon Sep 17 00:00:00 2001 From: William Manley Date: Tue, 8 Jan 2019 14:49:05 +0000 Subject: [PATCH 1/2] 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/ --- deb/format.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/deb/format.go b/deb/format.go index 3d02ab46c..b2d3bb466 100644 --- a/deb/format.go +++ b/deb/format.go @@ -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 } From f9557072010d1fb14d982b608427a96fab54b0cb Mon Sep 17 00:00:00 2001 From: William Manley Date: Tue, 8 Jan 2019 15:14:39 +0000 Subject: [PATCH 2/2] Add William Manley (@wmanley) to `AUTHORS` My measly contribution hardly merits it but it's a requirement in `CONTRIBUTING.md`. --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 00d6a403c..f376e783a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,3 +34,4 @@ List of contributors, in chronological order: * Maximilian Stein (https://github.com/steinymity) * Strajan Sebastian (https://github.com/strajansebastian) * Artem Smirnov (https://github.com/urpylka) +* William Manley (https://github.com/wmanley)