MCPcopy Create free account
hub / github.com/google/git-appraise / buildCommentThreads

Function buildCommentThreads

review/review.go:227–260  ·  view source on GitHub ↗

This function builds the comment thread tree from the log-based list of comments. Since the comments can be processed in any order, this uses an internal mutable data structure, and then converts it to the proper CommentThread structure at the end.

(commentsByHash map[string]comment.Comment)

Source from the content-addressed store, hash-verified

225// Since the comments can be processed in any order, this uses an internal mutable
226// data structure, and then converts it to the proper CommentThread structure at the end.
227func buildCommentThreads(commentsByHash map[string]comment.Comment) []CommentThread {
228 threadsByHash := make(map[string]*mutableThread)
229 for hash, comment := range commentsByHash {
230 thread, ok := threadsByHash[hash]
231 if !ok {
232 thread = &mutableThread{
233 Hash: hash,
234 Comment: comment,
235 }
236 threadsByHash[hash] = thread
237 }
238 }
239 var rootHashes []string
240 for hash, thread := range threadsByHash {
241 if thread.Comment.Original != "" {
242 original, ok := threadsByHash[thread.Comment.Original]
243 if ok {
244 original.Edits = append(original.Edits, &thread.Comment)
245 }
246 } else if thread.Comment.Parent == "" {
247 rootHashes = append(rootHashes, hash)
248 } else {
249 parent, ok := threadsByHash[thread.Comment.Parent]
250 if ok {
251 parent.Children = append(parent.Children, thread)
252 }
253 }
254 }
255 var threads []CommentThread
256 for _, hash := range rootHashes {
257 threads = append(threads, fixMutableThread(threadsByHash[hash]))
258 }
259 return threads
260}
261
262// getCommentsFromNotes parses the log-structured sequence of comments for a commit,
263// and then builds the corresponding tree-structured comment threads.

Callers 2

TestBuildCommentThreadsFunction · 0.85
getCommentsFromNotesFunction · 0.85

Calls 1

fixMutableThreadFunction · 0.85

Tested by 1

TestBuildCommentThreadsFunction · 0.68