Avoid shelling out once per object, things go much faster

This commit is contained in:
rubyist 2014-10-03 09:29:29 -04:00
parent fa922d7e98
commit 494a547831
2 changed files with 3 additions and 17 deletions

@ -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 {

@ -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) {