aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/index/encoder.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-02-21 16:07:25 +0100
committerGitHub <noreply@github.com>2017-02-21 16:07:25 +0100
commit867b10692e5f8a34a82cc0a783bdb63e2b5ff398 (patch)
tree3ddb2f430ee3c958f0650cb7db6a9df44b1e1361 /plumbing/format/index/encoder.go
parent0b8b8da617d5a077f282e57d0300dc106a604236 (diff)
parent790fbdaddc3c9a434f2ad97d9eb56db9b6c99495 (diff)
downloadgo-git-867b10692e5f8a34a82cc0a783bdb63e2b5ff398.tar.gz
Merge pull request #270 from mcuadros/submodules-init
Submodules init and update
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..bdb10c1 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 }