(parent string, t *object.Tree)
| 266 | func (se sortableEntries) Swap(i int, j int) { se[i], se[j] = se[j], se[i] } |
| 267 | |
| 268 | func (h *buildTreeHelper) copyTreeToStorageRecursive(parent string, t *object.Tree) (plumbing.Hash, error) { |
| 269 | sort.Sort(sortableEntries(t.Entries)) |
| 270 | for i, e := range t.Entries { |
| 271 | if e.Mode != filemode.Dir && !e.Hash.IsZero() { |
| 272 | continue |
| 273 | } |
| 274 | |
| 275 | path := path.Join(parent, e.Name) |
| 276 | |
| 277 | var err error |
| 278 | e.Hash, err = h.copyTreeToStorageRecursive(path, h.trees[path]) |
| 279 | if err != nil { |
| 280 | return plumbing.ZeroHash, err |
| 281 | } |
| 282 | |
| 283 | t.Entries[i] = e |
| 284 | } |
| 285 | |
| 286 | o := h.s.NewEncodedObject() |
| 287 | if err := t.Encode(o); err != nil { |
| 288 | return plumbing.ZeroHash, err |
| 289 | } |
| 290 | |
| 291 | hash := o.Hash() |
| 292 | if h.s.HasEncodedObject(hash) == nil { |
| 293 | return hash, nil |
| 294 | } |
| 295 | return h.s.SetEncodedObject(o) |
| 296 | } |
no test coverage detected