@@ -114,78 +114,30 @@ jobs:
114114 printf -v PR_COMMENT_BODY_ACCUMULATOR "%s Searching for upstream commits on 'master' branch in range \`%s..%s\` that fix \`%s\` using \`git log\`...\n" \
115115 "$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH" "$HEAD_COMMIT_SHA" "$UPSTREAM_LINUX_HASH"
116116
117- FOUND_FIXING_COMMITS=()
118- # Construct the grep pattern using the full SHA as it's the most precise match.
119- # `git log` grep is powerful enough for full SHA.
117+ # Construct the grep pattern using the full SHA for precise matching.
120118 GREP_PATTERN="Fixes: ${UPSTREAM_LINUX_HASH}"
121119
122120 # Use git log to find commits that mention the full SHA in their "Fixes:" line,
123121 # in the range from the specific commit up to HEAD.
124- # --pretty=format:"%H%n%B" ensures SHA on one line, followed by the full message.
125- # --invert-grep ensures we exclude the UPSTREAM_LINUX_HASH if it somehow
126- # matches its own Fixes: tag (shouldn't happen, but defensive).
127- # --regexp-ignore-case for case-insensitive grep (Fixes: vs fixes:).
128- # We explicitly include --invert-grep "${UPSTREAM_LINUX_HASH}" to ensure
129- # the original commit itself is not included in the results for "Fixes:"
130- # that points to itself, as we are looking for *subsequent* fixes.
131- GIT_LOG_OUTPUT=$(git -C linux log master \
122+ # --pretty=format:"%h %s" to get short SHA and subject.
123+ # --regexp-ignore-case for case-insensitive grep.
124+ # We explicitly exclude the UPSTREAM_LINUX_HASH itself from the result,
125+ # as we are looking for *subsequent* fixes.
126+ GIT_LOG_FIXES_OUTPUT=$(git -C linux log master \
132127 "${UPSTREAM_LINUX_HASH}..${HEAD_COMMIT_SHA}" \
133128 --grep="${GREP_PATTERN}" \
134- --pretty=format:"%H%n%B " \
129+ --pretty=format:"%h %s " \
135130 --regexp-ignore-case)
136131
137- if [ -z "$GIT_LOG_OUTPUT " ]; then
132+ if [ -z "$GIT_LOG_FIXES_OUTPUT " ]; then
138133 printf -v PR_COMMENT_BODY_ACCUMULATOR "%s No upstream fixes found for \`%s\` in the specified range.\n" \
139134 "$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
140135 else
141- # Process the git log output line by line to parse SHAs and full messages.
142- current_commit_sha=""
143- commit_message_lines=()
144- # Read the git log output, handling multi-line messages
145- while IFS= read -r line; do
146- if [[ "$line" =~ ^[0-9a-f]{40}$ ]]; then
147- # This line is a SHA, indicating a new commit.
148- # Process the previous commit's message (if any) before starting a new one.
149- if [ -n "$current_commit_sha" ]; then
150- FULL_MESSAGE=$(printf "%s\n" "${commit_message_lines[@]}")
151- # Final check on the full message (though grep already filtered)
152- # to extract the specific Fixes: line for display.
153- if echo "$FULL_MESSAGE" | grep -Eq "^Fixes: [0-9a-fA-F]*${UPSTREAM_LINUX_HASH}.*"; then
154- FIX_MESSAGE_SNIPPET=$(echo "$FULL_MESSAGE" | grep -Ei "^Fixes:.*${UPSTREAM_LINUX_HASH}.*")
155- FOUND_FIXING_COMMITS+=("${current_commit_sha}:${FIX_MESSAGE_SNIPPET}")
156- fi
157- fi
158- current_commit_sha="$line"
159- commit_message_lines=() # Reset message lines for the new commit
160- else
161- # This line is part of the current commit's message
162- commit_message_lines+=("$line")
163- fi
164- done <<< "$GIT_LOG_OUTPUT"
165-
166- # Process the last commit in the output (after the loop finishes)
167- if [ -n "$current_commit_sha" ]; then
168- FULL_MESSAGE=$(printf "%s\n" "${commit_message_lines[@]}")
169- if echo "$FULL_MESSAGE" | grep -Eq "^Fixes: [0-9a-fA-F]*${UPSTREAM_LINUX_HASH}.*"; then
170- FIX_MESSAGE_SNIPPET=$(echo "$FULL_MESSAGE" | grep -Ei "^Fixes:.*${UPSTREAM_LINUX_HASH}.*")
171- FOUND_FIXING_COMMITS+=("${current_commit_sha}:${FIX_MESSAGE_SNIPPET}")
172- fi
173- fi
174-
175- if [ ${#FOUND_FIXING_COMMITS[@]} -gt 0 ]; then
176- printf -v PR_COMMENT_BODY_ACCUMULATOR "%s SUCCESS: Found %d upstream Linux commit(s) that fix \`%s\`:\n" \
177- "$PR_COMMENT_BODY_ACCUMULATOR" ${#FOUND_FIXING_COMMITS[@]} "$UPSTREAM_LINUX_HASH"
178- for FIX_COMMIT_ENTRY in "${FOUND_FIXING_COMMITS[@]}"; do
179- # Split SHA and message part for display
180- FIX_COMMIT_SHA=$(echo "$FIX_COMMIT_ENTRY" | cut -d ':' -f 1)
181- FIX_MESSAGE_SNIPPET=$(echo "$FIX_COMMIT_ENTRY" | cut -d ':' -f 2-) # Get everything after the first colon
182- printf -v PR_COMMENT_BODY_ACCUMULATOR "%s - \`%s\` (Fixes tag: \`%s\`)\n" \
183- "$PR_COMMENT_BODY_ACCUMULATOR" "$FIX_COMMIT_SHA" "$FIX_MESSAGE_SNIPPET"
184- done
185- else
186- printf -v PR_COMMENT_BODY_ACCUMULATOR "%s No upstream fixes found for \`%s\` in the specified range.\n" \
187- "$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
188- fi
136+ printf -v PR_COMMENT_BODY_ACCUMULATOR "%s SUCCESS: Found upstream Linux commit(s) that fix \`%s\`:\n" \
137+ "$PR_COMMENT_BODY_ACCUMULATOR" "$UPSTREAM_LINUX_HASH"
138+ # Add a markdown code block for the git log output
139+ printf -v PR_COMMENT_BODY_ACCUMULATOR "%s\`\`\`\n%s\n\`\`\`\n" \
140+ "$PR_COMMENT_BODY_ACCUMULATOR" "$GIT_LOG_FIXES_OUTPUT"
189141 fi
190142 printf -v PR_COMMENT_BODY_ACCUMULATOR "%s\n" "$PR_COMMENT_BODY_ACCUMULATOR"
191143 done # End of for PR_COMMIT_SHA loop
0 commit comments