forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacro.go
More file actions
66 lines (60 loc) · 1.58 KB
/
macro.go
File metadata and controls
66 lines (60 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gitattr
type MacroProcessor struct {
macros map[string][]*Attr
}
// 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{
&Attr{K: "diff", V: "false"},
&Attr{K: "merge", V: "false"},
&Attr{K: "text", V: "false"},
}
return &MacroProcessor{
macros: macros,
}
}
// 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) []*Line {
result := make([]*Line, 0, len(lines))
for _, line := range lines {
if line.Pattern != nil {
resultLine := Line{
Pattern: line.Pattern,
Attrs: make([]*Attr, 0, len(line.Attrs)),
}
for _, attr := range line.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)
} else if readMacros {
mp.macros[line.Macro] = line.Attrs
}
}
return result
}