Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
gitparse: Use an object for currentDiff (#1573)
Miccahb54683acb91a
diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.goindex 8e8925111..2f5262cf3 100644--- a/pkg/gitparse/gitparse.go+++ b/pkg/gitparse/gitparse.go@@ -237,7 +237,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan choutReader := bufio.NewReader(stdOut)var (currentCommit *Commit- currentDiff *Diff+ currentDiff DifftotalLogSize int)@@ -260,8 +260,8 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chlatestState = CommitLine// If there is a currentDiff, add it to currentCommit.- if currentDiff != nil && currentDiff.Content.Len() > 0 {- currentCommit.Diffs = append(currentCommit.Diffs, *currentDiff)+ if currentDiff.Content.Len() > 0 {+ currentCommit.Diffs = append(currentCommit.Diffs, currentDiff)currentCommit.Size += currentDiff.Content.Len()}// If there is a currentCommit, send it to the channel.@@ -270,7 +270,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chtotalLogSize += currentCommit.Size}// Create a new currentDiff and currentCommit- currentDiff = &Diff{}+ currentDiff = Diff{}currentCommit = &Commit{Message: strings.Builder{},}@@ -309,8 +309,8 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chif currentCommit == nil {currentCommit = &Commit{}}- if currentDiff != nil && currentDiff.Content.Len() > 0 {- currentCommit.Diffs = append(currentCommit.Diffs, *currentDiff)+ if currentDiff.Content.Len() > 0 {+ currentCommit.Diffs = append(currentCommit.Diffs, currentDiff)// If the currentDiff is over 1GB, drop it into the channel so it isn't held in memory waiting for more commits.totalSize := 0for _, diff := range currentCommit.Diffs {@@ -331,7 +331,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chcurrentCommit.Message.WriteString(oldCommit.Message.String())}}- currentDiff = &Diff{}+ currentDiff = Diff{}case isModeLine(isStaged, latestState, line):latestState = ModeLine// NoOp@@ -354,16 +354,13 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chcase isHunkLineNumberLine(isStaged, latestState, line):latestState = HunkLineNumberLine- // TODO: Is it still necessary to check whether the currentDiff is nil?- if currentDiff != nil && currentDiff.Content.Len() > 0 {- currentCommit.Diffs = append(currentCommit.Diffs, *currentDiff)+ if currentDiff.Content.Len() > 0 {+ currentCommit.Diffs = append(currentCommit.Diffs, currentDiff)}- newDiff := &Diff{+ currentDiff = Diff{PathB: currentDiff.PathB,}- currentDiff = newDiff-words := bytes.Split(line, []byte(" "))if len(words) >= 3 {startSlice := bytes.Split(words[2], []byte(","))@@ -420,14 +417,14 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chlatestState = ParseFailure}- if currentDiff != nil && currentDiff.Content.Len() > c.maxDiffSize {+ if currentDiff.Content.Len() > c.maxDiffSize {ctx.Logger().V(2).Info(fmt.Sprintf("Diff for %s exceeded MaxDiffSize(%d)", currentDiff.PathB, c.maxDiffSize,))break}}- cleanupParse(currentCommit, currentDiff, commitChan, &totalLogSize)+ cleanupParse(currentCommit, ¤tDiff, commitChan, &totalLogSize)ctx.Logger().V(2).Info("finished parsing git log.", "total_log_size", totalLogSize)}