/
niceSOFT
/
git-lfs
Обзор
Документация
Войти
/
niceSOFT
/
git-lfs
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
git/gitattr/macro.go
85 строк
2 KB
Julien Marzal
feat[macro]: processing macro lines
28 окт 2025, 11:00
28 окт 2025, 11:00
951b156
Код
Авторство
О чём код?
package gitattr type MacroProcessor struct { macros map[string][]*Attr didReadMacros bool } // NewMacroProcessor returns a new MacroProcessor object for parsing macros. func NewMacroProcessor() *MacroProcessor { macros := make(map[string][]*Attr) // This is built into Git. macros["binary"] = []*Attr{ {K: "diff", V: "false"}, {K: "merge", V: "false"}, {K: "text", V: "false"}, } return &MacroProcessor{ macros: macros, didReadMacros: false, } } // ProcessLines reads the specified lines, returning a new set of lines which // all have a valid pattern. If readMacros is true, it additionally loads any // macro lines as it reads them. func (mp *MacroProcessor) ProcessLines(lines []Line, readMacros bool) []PatternLine { result := make([]PatternLine, 0, len(lines)) for _, line := range lines { switch l := line.(type) { case PatternLine: var lineAttrs lineAttrs lineAttrs.attrs = make([]*Attr, 0, len(l.Attrs())) resultLine := &patternLine{l.Pattern(), lineAttrs} for _, attr := range l.Attrs() { macros := mp.macros[attr.K] if attr.V == "true" && macros != nil { resultLine.attrs = append( resultLine.attrs, macros..., ) } else if attr.Unspecified && macros != nil { for _, m := range macros { resultLine.attrs = append( resultLine.attrs, &Attr{ K: m.K, Unspecified: true, }, ) } } // Git copies through aliases as well as // expanding them. resultLine.attrs = append( resultLine.attrs, attr, ) } result = append(result, resultLine) case MacroLine: if readMacros { mp.macros[l.Macro()] = l.Attrs() } } } mp.didReadMacros = mp.didReadMacros || readMacros return result } // ProcessMacros reads all the lines but only processes macro lines. func (mp *MacroProcessor) ProcessMacros(lines []Line) { for _, line := range lines { switch l := line.(type) { case MacroLine: mp.macros[l.Macro()] = l.Attrs() default: continue } } mp.didReadMacros = true }