Skip to content

Commit

Permalink
git-backport-diff: Kill git-log after match found
Browse files Browse the repository at this point in the history
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
  • Loading branch information
XanClic committed Oct 17, 2019
1 parent e02cf70 commit 620ae59
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion git-backport-diff
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,34 @@ 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" ]]
then
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
Expand Down

0 comments on commit 620ae59

Please sign in to comment.