Applied returns a slice of attributes applied to the given path, relative to the receiving tree. It traverse through sub-trees in a topological ordering, if there are relevant .gitattributes matching that path.
(to string)
| 90 | // the receiving tree. It traverse through sub-trees in a topological ordering, |
| 91 | // if there are relevant .gitattributes matching that path. |
| 92 | func (t *Tree) Applied(to string) []*Attr { |
| 93 | var attrs []*Attr |
| 94 | for _, line := range t.Lines { |
| 95 | if l, ok := line.(PatternLine); ok { |
| 96 | if l.Pattern().Match(to) { |
| 97 | attrs = append(attrs, line.Attrs()...) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | splits := strings.SplitN(to, "/", 2) |
| 103 | if len(splits) == 2 { |
| 104 | car, cdr := splits[0], splits[1] |
| 105 | if child, ok := t.Children[car]; ok { |
| 106 | attrs = append(attrs, child.Applied(cdr)...) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return attrs |
| 111 | } |