aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/index/encoder.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-02-13 19:18:05 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-02-13 19:18:05 +0100
commit940a16ca68457beded1eff551f23febeffb32f3e (patch)
treeb914bf2ba817d9d6b614adc3ebb07ea04f41f906 /plumbing/format/index/encoder.go
parentc551c29a93882658d4b34860b5300de0f3456059 (diff)
downloadgo-git-940a16ca68457beded1eff551f23febeffb32f3e.tar.gz
format/index: sort the Entries before encode
Diffstat (limited to 'plumbing/format/index/encoder.go')
-rw-r--r--plumbing/format/index/encoder.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/plumbing/format/index/encoder.go b/plumbing/format/index/encoder.go
index e5de135..4699d43 100644
--- a/plumbing/format/index/encoder.go
+++ b/plumbing/format/index/encoder.go
@@ -6,6 +6,7 @@ import (
"errors"
"hash"
"io"
+ "sort"
"time"
"srcd.works/go-git.v4/utils/binary"
@@ -61,6 +62,8 @@ func (e *Encoder) encodeHeader(idx *Index) error {
}
func (e *Encoder) encodeEntries(idx *Index) error {
+ sort.Sort(ByName(idx.Entries))
+
for _, entry := range idx.Entries {
if err := e.encodeEntry(&entry); err != nil {
return err
@@ -139,3 +142,9 @@ func (e *Encoder) padEntry(wrote int) error {
func (e *Encoder) encodeFooter() error {
return binary.Write(e.w, e.hash.Sum(nil))
}
+
+type ByName []Entry
+
+func (l ByName) Len() int { return len(l) }
+func (l ByName) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
+func (l ByName) Less(i, j int) bool { return l[i].Name < l[j].Name }