Skip to content

Commit

Permalink
Update logic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz committed Jul 12, 2023
1 parent 06ef49e commit cd8ed15
Show file tree
Hide file tree
Showing 2 changed files with 473 additions and 164 deletions.
9 changes: 5 additions & 4 deletions pkg/gitparse/gitparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,12 @@ func isCommitLine(isStaged bool, latestState ParseState, line []byte) bool {
latestState == ModeLine ||
latestState == IndexLine ||
latestState == BinaryFileLine ||
latestState == ToFileLine ||
latestState == HunkContentLine) {
return false
}

if len(line) > 7 && bytes.Equal(line[:6], []byte("commit")) {
if len(line) > 7 && bytes.Equal(line[:7], []byte("commit ")) {
return true
}
return false
Expand Down Expand Up @@ -513,7 +514,7 @@ func isDiffLine(isStaged bool, latestState ParseState, line []byte) bool {
// rename to new.txt
// deleted file mode 100644
func isModeLine(isStaged bool, latestState ParseState, line []byte) bool {
if isStaged || !(latestState == DiffLine || latestState == ModeLine) {
if !(latestState == DiffLine || latestState == ModeLine) {
return false
}
// This could probably be better written.
Expand Down Expand Up @@ -658,7 +659,7 @@ func isHunkEmptyLine(isStaged bool, latestState ParseState, line []byte) bool {
}

func isCommitSeparatorLine(isStaged bool, latestState ParseState, line []byte) bool {
if (latestState == ModeLine || latestState == IndexLine || latestState == BinaryFileLine) &&
if (latestState == ModeLine || latestState == IndexLine || latestState == BinaryFileLine || latestState == ToFileLine) &&
len(line) == 1 && bytes.Equal(line[:1], []byte("\n")) {
return true
}
Expand All @@ -667,7 +668,7 @@ func isCommitSeparatorLine(isStaged bool, latestState ParseState, line []byte) b

func cleanupParse(currentCommit *Commit, currentDiff *Diff, commitChan chan Commit, totalLogSize *int) {
// Ignore empty or binary diffs (this condition may be redundant).
if currentDiff != nil && (currentDiff.Content.Len() > 0 || !currentDiff.IsBinary) {
if currentDiff != nil && currentDiff.Content.Len() > 0 {
currentCommit.Diffs = append(currentCommit.Diffs, *currentDiff)
}
if currentCommit != nil {
Expand Down
Loading

0 comments on commit cd8ed15

Please sign in to comment.