mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
[THOG-315] Replace bytes.buffer with strings.builder. (#533)
* Replace bytes.buffer with string.builder. * Remove profiling. * Remove detector changes. * ignore .test files. * fix detectors removed.
This commit is contained in:
parent
80ed2df88f
commit
e12432cef8
3 changed files with 31 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
.idea
|
||||
dist
|
||||
.env
|
||||
.env
|
||||
*.test
|
|
@ -76,3 +76,28 @@ func TestGitEngine(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGitEngine(b *testing.B) {
|
||||
repoUrl := "https://github.com/dustin-decker/secretsandstuff.git"
|
||||
path, _, err := git.PrepareRepo(repoUrl)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
defer cancel()
|
||||
|
||||
e := Start(ctx,
|
||||
WithConcurrency(1),
|
||||
WithDecoders(decoders.DefaultDecoders()...),
|
||||
WithDetectors(false, DefaultDetectors()...),
|
||||
)
|
||||
for i := 0; i < b.N; i++ {
|
||||
e.ScanGit(ctx, path, "", "", 0, common.FilterEmpty())
|
||||
resultCount := 0
|
||||
for _ = range e.ResultsChan() {
|
||||
resultCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -332,21 +332,21 @@ func (s *Git) ScanCommits(repo *git.Repository, path string, scanOptions *ScanOp
|
|||
}
|
||||
|
||||
for _, frag := range file.TextFragments {
|
||||
newLines := bytes.Buffer{}
|
||||
var sb strings.Builder
|
||||
newLineNumber := frag.NewPosition
|
||||
for _, line := range frag.Lines {
|
||||
if line.Op == gitdiff.OpAdd {
|
||||
newLines.WriteString(line.Line)
|
||||
sb.WriteString(line.Line)
|
||||
}
|
||||
}
|
||||
log.WithField("fragment", newLines.String()).Trace("detecting fragment")
|
||||
log.WithField("fragment", sb.String()).Trace("detecting fragment")
|
||||
metadata := s.sourceMetadataFunc(fileName, email, hash, when, urlMetadata, newLineNumber)
|
||||
chunksChan <- &sources.Chunk{
|
||||
SourceName: s.sourceName,
|
||||
SourceID: s.sourceID,
|
||||
SourceType: s.sourceType,
|
||||
SourceMetadata: metadata,
|
||||
Data: newLines.Bytes(),
|
||||
Data: []byte(sb.String()),
|
||||
Verify: s.verify,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue