77 "io/ioutil"
88 "regexp"
99 "strings"
10-
11- "gopkg.in/src-d/enry.v1/data"
1210)
1311
1412type attrType int
@@ -28,6 +26,7 @@ func (i attrType) String() string {
2826 if i < 0 || i >= attrType (len (attrTypeIndex )- 1 ) {
2927 return fmt .Sprintf ("attrType(%d)" , i )
3028 }
29+
3130 return attrTypeName [attrTypeIndex [i ]:attrTypeIndex [i + 1 ]]
3231}
3332
@@ -42,7 +41,8 @@ type regExpAttribute struct {
4241 attributes map [* regexp.Regexp ]string
4342}
4443
45- // GitAttributes is a struct that contains two maps, boolAttributes contains all the attributes that works like a boolean condition,
44+ // GitAttributes is a struct that contains two maps:
45+ // boolAttributes contains all the attributes that works like a boolean condition,
4646// regExpAttributes contains all the attributes that match a regExp to choose if an attribute is applied or not
4747type GitAttributes struct {
4848 boolAttributes map [attrType ]boolAttribute
@@ -64,7 +64,7 @@ func (gitAttrs *GitAttributes) IsVendor(path string) bool {
6464 return val
6565 }
6666
67- return data . VendorMatchers . Match (path )
67+ return IsVendor (path )
6868}
6969
7070// Returns whether or not path is a documentation path.
@@ -73,7 +73,7 @@ func (gitAttrs *GitAttributes) IsDocumentation(path string) bool {
7373 return val
7474 }
7575
76- return data . DocumentationMatchers . Match (path )
76+ return IsDocumentation (path )
7777}
7878
7979// Returns whether or not path is a generated path.
@@ -113,8 +113,8 @@ func NewGitAttributes() *GitAttributes {
113113 return & gitAttrs
114114}
115115
116- // LoadGitattributes reads and parses the file .gitattributes which overrides the standard strategies
117- // Returns slice of errors that have may ocurred in the load
116+ // LoadGitattributes reads and parses the file .gitattributes which overrides the standard strategies.
117+ // Returns slice of errors that have may ocurred in the load.
118118func (gitAttrs * GitAttributes ) LoadGitAttributes (path string , reader io.Reader ) []error {
119119 rawAttributes , errArr := loadRawGitAttributes (reader )
120120 if len (rawAttributes ) == 0 {
@@ -124,19 +124,6 @@ func (gitAttrs *GitAttributes) LoadGitAttributes(path string, reader io.Reader)
124124 return append (gitAttrs .parseAttributes (path , rawAttributes ), errArr ... )
125125}
126126
127- func (gitAttrs * GitAttributes ) String () string {
128- out := ""
129- for key , val := range gitAttrs .boolAttributes {
130- out += fmt .Sprintf ("Type: %s Attributes: %v\n " , key , val .attributes )
131- }
132-
133- for key , val := range gitAttrs .regExpAttributes {
134- out += fmt .Sprintf ("Type: %s Attributes: %v\n " , key , val .attributes )
135- }
136-
137- return out
138- }
139-
140127func loadRawGitAttributes (reader io.Reader ) (map [string ][]string , []error ) {
141128 rawAttributes := map [string ][]string {}
142129 var errArr []error
@@ -216,6 +203,7 @@ func (gitAttrs *GitAttributes) processBoolAttr(kind attrType, key string, attrib
216203 if _ , ok := gitAttrs .boolAttributes [kind ].attributes [key ]; ok {
217204 err = & overrideError {attribute : kind , path : key }
218205 }
206+
219207 switch {
220208 case attribute == gitAttrs .boolAttributes [kind ].matchers [0 ]:
221209 gitAttrs .boolAttributes [kind ].attributes [key ] = true
0 commit comments