MCPcopy Index your code
hub / github.com/sinclairtarget/git-who / ParseCommits

Function ParseCommits

internal/git/parse.go:58–211  ·  view source on GitHub ↗

Turns an iterator over lines from git log into an iterator of commits

(lines iter.Seq[string])

Source from the content-addressed store, hash-verified

56
57// Turns an iterator over lines from git log into an iterator of commits
58func ParseCommits(lines iter.Seq[string]) (iter.Seq[Commit], func() error) {
59 var iterErr error
60
61 seq := func(yield func(Commit) bool) {
62 var commit Commit
63 var diff *FileDiff
64 now := time.Now()
65 linesThisCommit := 0
66
67 for line := range lines {
68 done := linesThisCommit >= 6 && (len(line) == 0 || rev.IsFullHash(line))
69 if done {
70 if allowCommit(commit, now) {
71 if !yield(commit) {
72 return
73 }
74 }
75
76 commit = Commit{}
77 diff = nil
78 linesThisCommit = 0
79
80 if len(line) == 0 {
81 continue
82 }
83 }
84
85 switch {
86 case linesThisCommit == 0:
87 commit.Hash = line
88 case linesThisCommit == 1:
89 commit.ShortHash = line
90 case linesThisCommit == 2:
91 parts := strings.Split(line, " ")
92 commit.IsMerge = len(parts) > 1
93 case linesThisCommit == 3:
94 commit.AuthorName = line
95 case linesThisCommit == 4:
96 commit.AuthorEmail = line
97 case linesThisCommit == 5:
98 i, err := strconv.Atoi(line)
99 if err != nil {
100 iterErr = fmt.Errorf(
101 "error parsing date from commit %s: %w",
102 commit.Name(),
103 err,
104 )
105 return
106 }
107
108 commit.Date = time.Unix(int64(i), 0)
109 default:
110 var err error
111
112 // Handle file diffs
113 if diff == nil {
114 diff = &FileDiff{}
115

Callers 5

TestParseFileRenameFunction · 0.92
TestCommitsRenameDeepDirFunction · 0.92
runWorkerFunction · 0.92
CommitsWithOptsFunction · 0.85

Calls 3

NameMethod · 0.95
allowCommitFunction · 0.85
parseLinesChangedFunction · 0.85

Tested by 3

TestParseFileRenameFunction · 0.74
TestCommitsRenameDeepDirFunction · 0.74