(parent string, t *object.Tree)
| 241 | func (se sortableEntries) Swap(i int, j int) { se[i], se[j] = se[j], se[i] } |
| 242 | |
| 243 | func (h *buildTreeHelper) copyTreeToStorageRecursive(parent string, t *object.Tree) (plumbing.Hash, error) { |
| 244 | sort.Sort(sortableEntries(t.Entries)) |
| 245 | for i, e := range t.Entries { |
| 246 | if e.Mode != filemode.Dir && !e.Hash.IsZero() { |
| 247 | continue |
| 248 | } |
| 249 | |
| 250 | path := path.Join(parent, e.Name) |
| 251 | |
| 252 | var err error |
| 253 | e.Hash, err = h.copyTreeToStorageRecursive(path, h.trees[path]) |
| 254 | if err != nil { |
| 255 | return plumbing.ZeroHash, err |
| 256 | } |
| 257 | |
| 258 | t.Entries[i] = e |
| 259 | } |
| 260 | |
| 261 | o := h.s.NewEncodedObject() |
| 262 | if err := t.Encode(o); err != nil { |
| 263 | return plumbing.ZeroHash, err |
| 264 | } |
| 265 | |
| 266 | hash := o.Hash() |
| 267 | if h.s.HasEncodedObject(hash) == nil { |
| 268 | return hash, nil |
| 269 | } |
| 270 | return h.s.SetEncodedObject(o) |
| 271 | } |
no test coverage detected