Skip to content

Commit

Permalink
Optimize order of default rules
Browse files Browse the repository at this point in the history
By moving the .git/ exclusion rule to the end of the default list,
it's possible to skip the entire .git/ directory walk because no
exclusions appear after it. This should slightly speed up packing
performance when the default rules are used or when no additional
exclusion rules are set by .terraformignore.
  • Loading branch information
brandonc committed Jan 30, 2024
1 parent 1aeab8a commit c37bb9b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/ignorefiles/terraformignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,20 @@ func (r *rule) compile() error {

var defaultExclusions = []rule{
{
val: strings.Join([]string{"**", ".git", "**"}, string(os.PathSeparator)),
val: strings.Join([]string{"**", ".terraform", "**"}, string(os.PathSeparator)),
negated: false,
negationsAfter: true,
},
// Place negation rules as high as possible in the list
{
val: strings.Join([]string{"**", ".terraform", "**"}, string(os.PathSeparator)),
negated: false,
negationsAfter: true,
val: strings.Join([]string{"**", ".terraform", "modules", "**"}, string(os.PathSeparator)),
negated: true,
negationsAfter: false,
},
{
val: strings.Join([]string{"**", ".terraform", "modules", "**"}, string(os.PathSeparator)),
negated: true,
val: strings.Join([]string{"**", ".git", "**"}, string(os.PathSeparator)),
negated: false,
negationsAfter: false,
},
}

Expand Down

0 comments on commit c37bb9b

Please sign in to comment.