Skip to content

Commit 620ae59

Browse files
committed
git-backport-diff: Kill git-log after match found
d0c8cbd has indeed made finding a match faster, but the downside is that the git-log process continues to run in the background even when we no longer consume its output. This is a problem particularly for large patch series, where git-backport-diff may thus spawn hundreds of subprocesses. We don't need the git-log process after we found a match, so make it a real job instead of an anonymous subprocess, which allows us to terminate it after we have found a match. Reported-by: Thomas Huth <[email protected]> Fixes: d0c8cbd
1 parent e02cf70 commit 620ae59

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

git-backport-diff

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,34 @@ compare_git()
226226
do
227227
let cnt=$cnt+1;
228228
subj=${hashsubj:40}
229+
230+
# We need to direct the git-log output through a FIFO so we
231+
# get a git-log job that we can kill once we have found our
232+
# match
233+
git_fifo=$(mktemp -u --tmpdir 'backport-diff.XXXXXX')
234+
mkfifo "$git_fifo"
235+
229236
downhash=${hashsubj:0:40}
230237
# A little bit hackish, but find the match by looking at upstream
231238
# subject lines, and using the newest one. Not all backports contain
232239
# the phrase "cherry-pick", so we can't really try and find the
233240
# upstream hash from that...
234241
uphash=""
242+
git log $upstream --pretty=tformat:"%H%s" --fixed-strings --grep="${subj}" >"$git_fifo" &
243+
job_id=$(jobs -l | grep "\<$!\>" | sed -e 's/[^\[]*\[\([^\]]*\)\].*/\1/')
235244
while read uphashsubj
236245
do
237246
if [[ "${uphashsubj:40}" == "$subj" ]]
238247
then
239248
uphash=${uphashsubj:0:40}
240249
break
241250
fi
242-
done < <(git log $upstream --pretty=tformat:"%H%s" --fixed-strings --grep="${subj}")
251+
done <"$git_fifo"
252+
253+
# Ignore errors
254+
kill %$job_id &>/dev/null || true
255+
wait &> /dev/null
256+
rm -f "$git_fifo"
243257

244258
if [[ -n "$uphash" ]]
245259
then

0 commit comments

Comments
 (0)