aboutsummaryrefslogtreecommitdiffstats
path: root/tree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-29 22:49:00 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-29 22:49:00 +0200
commitdd4af03ad368cc50dd08912010f5b667bd7569cd (patch)
treedb8a4dbe49e534b2215a74866de5e229a06fc3b0 /tree.go
parent5cf20a4edf7803458a1c2ec94e902369bed76f28 (diff)
downloadgo-git-dd4af03ad368cc50dd08912010f5b667bd7569cd.tar.gz
core: MemoryObject.Write, remove SetSize side effect
Diffstat (limited to 'tree.go')
-rw-r--r--tree.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/tree.go b/tree.go
index 86f1aaa..3058231 100644
--- a/tree.go
+++ b/tree.go
@@ -218,18 +218,30 @@ func (t *Tree) Encode(o core.Object) error {
if err != nil {
return err
}
+
+ var size int
defer checkClose(w, &err)
for _, entry := range t.Entries {
- if _, err = fmt.Fprintf(w, "%o %s", entry.Mode, entry.Name); err != nil {
+ n, err := fmt.Fprintf(w, "%o %s", entry.Mode, entry.Name)
+ if err != nil {
return err
}
- if _, err = w.Write([]byte{0x00}); err != nil {
+
+ size += n
+ n, err = w.Write([]byte{0x00})
+ if err != nil {
return err
}
- if _, err = w.Write([]byte(entry.Hash[:])); err != nil {
+
+ size += n
+ n, err = w.Write([]byte(entry.Hash[:]))
+ if err != nil {
return err
}
+ size += n
}
+
+ o.SetSize(int64(size))
return err
}