From 494a547831a1823828e4a9d39c7a795be3eda8a0 Mon Sep 17 00:00:00 2001 From: rubyist Date: Fri, 3 Oct 2014 09:29:29 -0400 Subject: [PATCH] Avoid shelling out once per object, things go much faster --- commands/command_scan.go | 12 +++--------- git/git.go | 8 -------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/commands/command_scan.go b/commands/command_scan.go index e526eafe..aab0e0a9 100644 --- a/commands/command_scan.go +++ b/commands/command_scan.go @@ -34,11 +34,7 @@ func scanCommand(cmd *cobra.Command, args []string) { var mediaObjects bytes.Buffer for _, o := range objects { if o.Type == "blob" && o.Size < 200 { - // Grep these objects for a git-media pointer indicator. This one is crude, do better. - isMedia, _ := git.GrepBlob(o.Sha1, "git-media") // Need a better pattern (must match all pointer versions) - if isMedia { - mediaObjects.WriteString(o.Sha1 + "\n") - } + mediaObjects.WriteString(o.Sha1 + "\n") } } @@ -68,11 +64,9 @@ func scanCommand(cmd *cobra.Command, args []string) { } p, err := pointer.Decode(bytes.NewBuffer(nbuf)) - if err != nil { - fmt.Println("Cannot decode file :(") - break + if err == nil { + pointers = append(pointers, p) } - pointers = append(pointers, p) _, err = r.ReadBytes('\n') // Extra \n inserted by cat-file if err != nil { diff --git a/git/git.go b/git/git.go index 2596af8a..bf0071dc 100644 --- a/git/git.go +++ b/git/git.go @@ -47,14 +47,6 @@ func Grep(pattern string) (string, error) { return simpleExec(nil, "git", "grep", "--full-name", "--name-only", "--cached", pattern) } -func GrepBlob(blob, pattern string) (bool, error) { - output, err := simpleExec(nil, "git", "grep", pattern, blob) - if err != nil { - return false, err - } - return output != "", nil -} - // HashObject is equivalent to `git hash-object --stdin` where data is passed // to stdin. func HashObject(data []byte) (string, error) {