From c37bb9b4effc317d2c52863ec7ed4a549a492245 Mon Sep 17 00:00:00 2001 From: Brandon Croft Date: Mon, 29 Jan 2024 17:10:22 -0700 Subject: [PATCH] Optimize order of default rules 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. --- internal/ignorefiles/terraformignore.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/ignorefiles/terraformignore.go b/internal/ignorefiles/terraformignore.go index 978d6de..df7d569 100644 --- a/internal/ignorefiles/terraformignore.go +++ b/internal/ignorefiles/terraformignore.go @@ -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, }, }