From 620ae595def8ab61d90e3d8fb814ba1e2ec015e6 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Tue, 15 Oct 2019 17:54:10 +0200 Subject: [PATCH] git-backport-diff: Kill git-log after match found d0c8cbd7ac5bb 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 Fixes: d0c8cbd7ac5bb78c46d17e4fc04e77b6d3962baf --- git-backport-diff | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/git-backport-diff b/git-backport-diff index 2ae090f..d9a2aea 100755 --- a/git-backport-diff +++ b/git-backport-diff @@ -226,12 +226,21 @@ compare_git() do let cnt=$cnt+1; subj=${hashsubj:40} + + # We need to direct the git-log output through a FIFO so we + # get a git-log job that we can kill once we have found our + # match + git_fifo=$(mktemp -u --tmpdir 'backport-diff.XXXXXX') + mkfifo "$git_fifo" + downhash=${hashsubj:0:40} # A little bit hackish, but find the match by looking at upstream # subject lines, and using the newest one. Not all backports contain # the phrase "cherry-pick", so we can't really try and find the # upstream hash from that... uphash="" + git log $upstream --pretty=tformat:"%H%s" --fixed-strings --grep="${subj}" >"$git_fifo" & + job_id=$(jobs -l | grep "\<$!\>" | sed -e 's/[^\[]*\[\([^\]]*\)\].*/\1/') while read uphashsubj do if [[ "${uphashsubj:40}" == "$subj" ]] @@ -239,7 +248,12 @@ compare_git() uphash=${uphashsubj:0:40} break fi - done < <(git log $upstream --pretty=tformat:"%H%s" --fixed-strings --grep="${subj}") + done <"$git_fifo" + + # Ignore errors + kill %$job_id &>/dev/null || true + wait &> /dev/null + rm -f "$git_fifo" if [[ -n "$uphash" ]] then