summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2019-02-10 23:07:59 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2019-02-13 22:40:22 -0500
commitb5146f831076ac0bcdc23c4a515c6a47837237b4 (patch)
tree476a146ff920f9abdc8d16554077468d28500cf1
parent4749df22d3415e961f550d4af6d660c8b77c4dd4 (diff)
fi-filefilter: use a regex
-rw-r--r--fi-filefilter/main.go21
1 files changed, 9 insertions, 12 deletions
diff --git a/fi-filefilter/main.go b/fi-filefilter/main.go
index 407f3f6..645b8c4 100644
--- a/fi-filefilter/main.go
+++ b/fi-filefilter/main.go
@@ -19,6 +19,7 @@ import (
"fmt"
"io"
"os"
+ "regexp"
"strings"
"time"
@@ -30,15 +31,6 @@ func abort(err error) {
os.Exit(1)
}
-func accept(path string) bool {
- for _, arg := range os.Args[1:] {
- if strings.Contains(path, arg) {
- return true
- }
- }
- return false
-}
-
var commit *libfastimport.CmdCommit
var (
@@ -55,6 +47,11 @@ func ensureCommit() {
}
func main() {
+ re, err := regexp.Compile(os.Args[1])
+ if err != nil {
+ abort(err)
+ }
+
commits := 0
beg := time.Now()
status := func() {
@@ -92,17 +89,17 @@ func main() {
}
case libfastimport.FileModify:
- if accept(string(cmdt.Path)) {
+ if re.MatchString(string(cmdt.Path)) {
ensureCommit()
backend.Do(cmd)
}
case libfastimport.FileModifyInline:
- if accept(string(cmdt.Path)) {
+ if re.MatchString(string(cmdt.Path)) {
ensureCommit()
backend.Do(cmd)
}
case libfastimport.FileDelete:
- if accept(string(cmdt.Path)) {
+ if re.MatchString(string(cmdt.Path)) {
ensureCommit()
backend.Do(cmd)
}